nesdev.com
http://forums.nesdev.com/

Palettes
http://forums.nesdev.com/viewtopic.php?f=21&t=12143
Page 5 of 5

Author:  Sik [ Thu Dec 25, 2014 10:09 pm ]
Post subject:  Re: Palettes

I think I know what is going on: use squares to make the values non-linear, then use a square root to counter the bias towards black caused by that (to make it a bias towards white instead). Not sure how well that works though.

So basically the full calculation would be:
Y = sqrt(R * R * 0.299 + G * G * 0.587 + B * B * 0.114)

EDIT: did a quick check and it does seem that grays are preserved at least.

EDIT 2: OK, here we go again with the comparisons
Original image
Standard grayscale algorithm
Square-based grayscale algorithm

EDIT 3: and now I'm seeing shortcomings to both approaches =/ Lame (but of course it's possible that with this other algorithm different values are needed as well, remember the original algorithm was just a way to get reasonable results with the technology available at the time)

Author:  zzo38 [ Fri Dec 26, 2014 12:54 am ]
Post subject:  Re: Palettes

Sik wrote:
So basically the full calculation would be:
Y = sqrt(R * R * 0.299 + G * G * 0.587 + B * B * 0.114)

EDIT: did a quick check and it does seem that grays are preserved at least.
It is easy to prove: x=r=g=b implies y=sqrt(.299x^2+.587x^2+.114x^2)=sqrt((.299+.587+.114)x^2)=sqrt(x^2)=x. This is not a proof of how good it is; only that it has one good quality which is that it is idempotent so that grayscale pictures are preserved.

Quote:
One slight problem is that the pictures do not all represent the same frame. It would be easy to fix by capturing one frame and then applying the algorithm and making outputs based on it (this should be easy to do using ImageMagick, for example).

Author:  lidnariq [ Fri Dec 26, 2014 1:21 am ]
Post subject:  Re: Palettes

In fact, it's really easy to do with ImageMagick:
convert YZG20dL.png -fx 'sqrt(0.299*R*R+0.587*G*G+0.114*B*B)' sqrt.png
convert YZG20dL.png -type Grayscale gray.png

I actually think the sqrt version seems to do a respectable job at compensating for the H-K effect... at least for pure reds, greens, and blues.

Attachments:
sqrt.png
sqrt.png [ 4.42 KiB | Viewed 1312 times ]
gray.png
gray.png [ 4.3 KiB | Viewed 1312 times ]

Author:  Sik [ Fri Dec 26, 2014 4:28 am ]
Post subject:  Re: Palettes

zzo38 wrote:
One slight problem is that the pictures do not all represent the same frame. It would be easy to fix by capturing one frame and then applying the algorithm and making outputs based on it (this should be easy to do using ImageMagick, for example).


Yeah, but the only true difference is the clouds having moved a little and maybe Sol's position being slightly different so it's not hard to do (by the way, in case you wonder those images were made by applying a color filter in-game).

As I said the factors with the square-based algorithm could be wrong, I was messing with these ones to see how well it works, does anybody else want to give them a try? I didn't check yet but at least I got the impression that it wasn't anywhere as off (this was mostly noticeable with red):

R = 0.25
G = 0.60
B = 0.15

Author:  Drag [ Fri Dec 26, 2014 10:26 pm ]
Post subject:  Re: Palettes

Wikipedia suggests removing the gamma, and then Y = 0.2126R + 0.7152G + 0.0722B, and then readding the gamma.

A simple approximation would be something like:
R = pow(R, 2.2);
G = pow(G, 2.2);
B = pow(B, 2.2);

Y = 0.2126R + 0.7152G + 0.0722B;

Y = pow(Y, 1/2.2);

Attachments:
grayscale.png
grayscale.png [ 9.75 KiB | Viewed 1271 times ]

Author:  Sik [ Sat Dec 27, 2014 4:27 am ]
Post subject:  Re: Palettes

Huh, I thought we were already dealing with linear RGB in the first place. Also that grass became way too bright.

Also this is what I got with the modified values I mentioned before. It still can be tweaked, but it certainly seems to look a lot closer than all the attempts I've seen so far (although my perception for the blue component may be off...).

Image

Author:  tepples [ Sat Dec 27, 2014 10:20 am ]
Post subject:  Re: Palettes

The formulas with sqrt in them implicitly assume 2.0 gamma. I know that 2.0 of the 2.2 gamma comes from the fact that signal levels represent potential (in volts), and power is proportional to the square of potential if impedance is constant. But where's the other 10%?

Author:  Drag [ Sat Dec 27, 2014 1:38 pm ]
Post subject:  Re: Palettes

Instead of a square root, take the 2.2-root? x^(1/2.2)

Author:  Sik [ Sat Dec 27, 2014 1:40 pm ]
Post subject:  Re: Palettes

Doesn't the gamma depend entirely on the display? (which is why images for Macs always had to deal with a different gamma value)

Page 5 of 5 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/