It is currently Sat Oct 21, 2017 12:39 pm

 All times are UTC - 7 hours

 Page 5 of 5 [ 69 posts ] Go to page Previous  1, 2, 3, 4, 5
 Print view Previous topic | Next topic
Author Message
 Post subject: Re: PalettesPosted: Thu Dec 25, 2014 10:09 pm

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
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)

Top

 Post subject: Re: PalettesPosted: Fri Dec 26, 2014 12:54 am

Joined: Mon Feb 07, 2011 12:46 pm
Posts: 929
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).

_________________
.

Top

 Post subject: Re: PalettesPosted: Fri Dec 26, 2014 1:21 am

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6291
Location: Seattle
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 [ 4.42 KiB | Viewed 1313 times ] gray.png [ 4.3 KiB | Viewed 1313 times ]
Top

 Post subject: Re: PalettesPosted: Fri Dec 26, 2014 4:28 am

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
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

Top

 Post subject: Re: PalettesPosted: Fri Dec 26, 2014 10:26 pm

Joined: Mon Sep 27, 2004 2:57 pm
Posts: 1248
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 [ 9.75 KiB | Viewed 1272 times ]
Top

 Post subject: Re: PalettesPosted: Sat Dec 27, 2014 4:27 am

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
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...).

Top

 Post subject: Re: PalettesPosted: Sat Dec 27, 2014 10:20 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19114
Location: NE Indiana, USA (NTSC)
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%?

Top

 Post subject: Re: PalettesPosted: Sat Dec 27, 2014 1:38 pm

Joined: Mon Sep 27, 2004 2:57 pm
Posts: 1248
Instead of a square root, take the 2.2-root? x^(1/2.2)

Top

 Post subject: Re: PalettesPosted: Sat Dec 27, 2014 1:40 pm

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
Doesn't the gamma depend entirely on the display? (which is why images for Macs always had to deal with a different gamma value)

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 5 of 5 [ 69 posts ] Go to page Previous  1, 2, 3, 4, 5

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki