It is currently Tue Oct 17, 2017 8:17 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 69 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject: Re: Palettes
PostPosted: Thu Dec 25, 2014 10:09 pm 
Offline

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
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Fri Dec 26, 2014 12:54 am 
Offline
User avatar

Joined: Mon Feb 07, 2011 12:46 pm
Posts: 919
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
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Fri Dec 26, 2014 1:21 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6273
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
sqrt.png [ 4.42 KiB | Viewed 1300 times ]
gray.png
gray.png [ 4.3 KiB | Viewed 1300 times ]
Top
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Fri Dec 26, 2014 4:28 am 
Offline

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
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Fri Dec 26, 2014 10:26 pm 
Offline

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
grayscale.png [ 9.75 KiB | Viewed 1259 times ]
Top
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Sat Dec 27, 2014 4:27 am 
Offline

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...).

Image


Top
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Sat Dec 27, 2014 10:20 am 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19086
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
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Sat Dec 27, 2014 1:38 pm 
Offline

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
 Profile  
 
 Post subject: Re: Palettes
PostPosted: Sat Dec 27, 2014 1:40 pm 
Offline

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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 2 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group