It is currently Thu Mar 28, 2024 10:02 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 7:07 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14796
Location: roma, italy
For the nice programmers walking through this chat.
From time to time I use the Gimp function MaxRGB; I would like to have also a MaxCMY, to play with.
So my challenge is: would somebody be willing to "open" the source code of MaxRGB and replace the statements where maximum Red or maximum Green or maximum Blue is found (and replaces the pixel) and do a similar algorithm to find the maximum Cyan, maximum Magenta and maximum Yellow and replace the pixel?
I tried to do a python script for that, scanning each pixel, it succeeded, but it took an enormous amount of time, while MaxRGB is extremely fast; so my script is useless, while a compiled function would be similar to MaxRGB in terms of performances.
Thanks....

_________________
"Where am I ?"


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 9:41 am  (#2) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
You can fake it (I think) by playing channel games.

Decompose an image to CMY, then recompose this to RGB, so C->R, M->G, Y->B. Then use the maxRGB filter, decompose back to RGB, and compose back to CMY.

Here is an example:
Attachment:
cmymax.jpg
cmymax.jpg [ 558.79 KiB | Viewed 1638 times ]


And attached is a script to do that. I have not verified manually that this produces the "right" answer, but technically, it should....except for losses in the double colourspace conversions...


Attachments:
maxCMY.scm [2.48 KiB]
Downloaded 88 times

_________________
Image
Fantasy Cartography and Mapping by RobA
Top
 Post subject: Re: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 10:07 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14796
Location: roma, italy
Thanks RobA!!! Quick and excellent work!
I downloaded and tried it; but now, I have a doubt on understanding how to detect C, M, Y values; let me explain:
my idea was that I had to sum up G+B to get the Cyan value, R+B to get the Magenta value, G+R to get the Yellow value; so I did in my (very slow...) python, then by comparing the so calculated C, M, Y values I selected the biggest value, then applied the corresponding full C (0,255,255), M(255,0,255), Y(255,255,0) value to that pixel.
The results are significantly divergent.
Am I totally wrong?

_________________
"Where am I ?"


Top
 Post subject: Re: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 10:56 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14796
Location: roma, italy
Sorry!..
There was something wrong in my script, but because it's very slow I will take a bit of time to come back with a new compare result

_________________
"Where am I ?"


Top
 Post subject: Re: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 11:12 am  (#5) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
dinasset wrote:
Thanks RobA!!! Quick and excellent work!
I downloaded and tried it; but now, I have a doubt on understanding how to detect C, M, Y values; let me explain:
my idea was that I had to sum up G+B to get the Cyan value, R+B to get the Magenta value, G+R to get the Yellow value; so I did in my (very slow...) python, then by comparing the so calculated C, M, Y values I selected the biggest value, then applied the corresponding full C (0,255,255), M(255,0,255), Y(255,255,0) value to that pixel.
The results are significantly divergent.
Am I totally wrong?



Yes. You are totally wrong ;)

C <> G+B
M <> R+B
Y <> G+R

The two colour spaces are not at all related that way.

Really, they C = 1-1/R, M = 1-1/G, and Y = 1-1/B working in the 0..1 range for all values.

Also, reading the maxRGB documentation,
Quote:
For every pixel, the filter keeps intensity of the RGB color channel which has the maximal intensity and reduces other both to zero. For example: 220, 158, 175 max--> 220, 0, 0. If two channels have same intensity, both are held: 210, 54, 210 max--> 210, 0, 210.


So it doesn't set it to the full R,G, or B value (255), instead it just zeros out the not highest channel values at that pixel.



And thinking about this points out that my script was actually a waste of time, as the same results can be done by inverting the image, (Colours->Invert) followed by he maxRGB plugin, then invert the colours again....

Though I could extend the script to work across any of the colourspaces via a selector... HSL, HSV, YUL, LAB, etc...

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Last edited by RobA on Sun Mar 24, 2013 11:20 am, edited 1 time in total.

Top
 Post subject: Re: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 11:12 am  (#6) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
RobA wrote:
Decompose an image to CMY, then recompose this to RGB, so C->R, M->G, Y->B. Then use the maxRGB filter, decompose back to RGB, and compose back to CMY.

Is not this mathematically equivalent to Invert, MaxRGB, Invert?

EDIT: :ninja

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 11:17 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14796
Location: roma, italy
OK.
I corrected my script, the colours are now the same as those resulting from your script, the only difference is in the fact that while in my script I apply the pure C M Y color, in your script the results show a component of the third primary in the tint (which is nicer, under certain aspects).
So, again THANKS A LOT, your script is EXTREMELY quick and useful, I will archive my python as an..exercise to learn something!

_________________
"Where am I ?"


Top
 Post subject: Re: Challenge : MaxCMY
PostPosted: Sun Mar 24, 2013 11:32 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14796
Location: roma, italy
PS: just for my fun, I checked the MaxRGB results and ALSO in this case it is not true that "Reduce image to pure red, green, and blue" as the description of the function says, because the 3 resulting colours are not at all "pure", they are only close to their maximum value (for instance, in the classical Gimp example image the blue is x"0000cd")....
(this is also explained in your post, only "the other two are reduced to zero"; OK, I didn't read enough....sigh)

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Challenge

14

No new posts Attachment(s) Free Challenge

102

No new posts Attachment(s) Directed Challenge

111

No new posts Attachment(s) GMIC Challenge

24



* Login  



Powered by phpBB3 © phpBB Group