New script: ColorMask

troypiggo said:
I wonder what's going to come first - PI 1.8.5 or ColorMask 1.0? :p

The only things left on my to-do list are the difficult items and I'm about to go on a business trip, so I'd be putting my money on PI 1.8.5  :p
 
I'm a brand new newbie to PI and the forum. I would like to download the New script: ColorMask, but for the life of me, can't figure out where the link is, although it is in front of my face.
Thanks for help
Bruce
 
Bruce

First page of this posting. At the bottom of the first section by Rick there is a paperclip. That is the script.



Mike
 

Attachments

  • color.jpg
    color.jpg
    25.7 KB · Views: 96
Hi Rick,

I am trying to use the ColorMask script, but I get strange results. It seems that the masks don't select the desired colors.

I have generated a pair of synthetic images trying to understand the behavior of the script. The test images are generated using ChannelCombination from monochrome images. The first has the values L=0.5, c=0.5, h=[0..1] and the second L=0.5, c=1.0, h=[0..1]. I have generated masks for the six predefined colors and the masks don't seem to fit the colors. It seems that the ranges of the predefined colors are not right.

I don't know if I am doing something wrong or if there is an error in the scripts.

Andr?s.
 

Attachments

  • c0.5.png
    c0.5.png
    28.7 KB · Views: 82
  • c1.0.png
    c1.0.png
    29.7 KB · Views: 77
I'll have a look tonight, Andr?s.  Have you tried using readout mode to check the hue values in the synthetic images?  Color is a very slippery thing!

Cheers,
Rick.
 
Hi Andr?s,

I had a play with synthetic images as you did.  Everything is behaving much as expected, IMO.  I have done the same exercise before and got the same confusing results as last time.  I think that colours can be very subjective.  My wife and I certainly don't have the same sense of colour  :D

The way the script works is by assuming that each of the predefined colour ranges is 120 degrees wide and centred on a multiple of 60 degrees (0 = red, 60 = yellow, 120 = green, etc.)  This is only approximately correct, but I find it close enough most of the time.  For careful work I use the cursor readout to check actual hue values in my images.

The big complication is that in reality hue isn't a simple linear thing.  If you look at one of your synthesised colour images with the readout cursor you will see some weird stuff.  What is the hue value at the endpoint where it should be 360 degrees? On the 0.5 chrominance image it is 359.28 degrees which is pretty close, but on the 1.0 chrominance image it is 3.2846 degrees.  You may get different results depending on what colour space you are using but I don't expect them to be any less weird.  Here's another weird thing: the hue values through most of the green area in the 1.0 chrominance image are all the same at 134.3887 degrees.  I presume what is happening here is that the colours are being clipped to the gamut of the colour space.  Take a look at the L values.  They aren't all 0.5 as you would expect.  Similarly, the chrominance values aren't all 1 - they vary between roughly 0.4 and 0.8.

So, to build a ColorMask script that works "perfectly" you need to take into account the intricacies of colour spaces and the varying human perception of colour.  That's something I couldn't do without a lot of research and perhaps not even then.  Despite being simplistic I think the script is still useful but I'd be happy to jump ship if someone builds a better one!

Hope that explains your results & concerns.  If not, let me know the details including what colour space you are using.

Cheers,
Rick.
 
Hello Rick,

Thanks a lot for developing this script. It's a great tool.

I'm having the same problem that Andres reported some time ago. When I use the "h" value everything is fine, I'm able to pick the colors I intend to. But when I use the preset buttons it's a different story. For example, when I press the Red button, the script selects magenta and blue....when I press the Blue button, it selects red, yellow and green colors on the attached color wheel image.

h value readouts are as follows:

Red - 77
Yellow - 106
Green - 138
Cyan - 237
Blue - 307
Magenta - 330

whereas H values are 0, 60, 120 etc respectively, distributed evenly at 60 degrees separation.

I'm no expert in color spaces and I will do some more reading tonight. Maybe, there is something wrong with my PI settings which is causing this issue.

 

Attachments

  • Color Wheel.png
    Color Wheel.png
    3.1 KB · Views: 188
Hi Sedat,

Thanks for the kind comment.  I have just retired and will hopefully have a bit more time for writing scripts now :)

I don't think it is likely that your PI settings are causing this issue.  It's just that our perception of colour is complex and varies from person to person and the simple rules that are currently used for the colour buttons are only a rough approximation of reality.  I did experiment with more complex ranges to match better in the past but it wasn't an unqualified success and I came to the conclusion that custom ranges were almost always required in practice anyway.

Cheers,
Rick.
 
Thank you for your kind answer. Congrats on your retirement! Hope this proves to be a good thing :) I have not been able to retire myself yet....

The thing is the color buttons are taking H values as their reference whereas the script only cares for the  h color space values.

When the "Red" button is pressed it spits out a range between 300 and 60 degrees which is wrong by h color space standards. These values should be something like 40 to 90 for Red. The color buttons are producing the color ranges in H color space which, apparently, doesn't mean anything to the script. Below is a chart I just put together showing H and h values of some colors. There should be nothing subjective about these figures as far as I understand.





 

Attachments

  • Screen Shot 2020-01-14 at 3.49.29 PM.png
    Screen Shot 2020-01-14 at 3.49.29 PM.png
    13.7 KB · Views: 75
for me, it seems that the script produces proper masks for a given color when i press the buttons, but any time i tried to measure my image the way Sedat has and then input ranges into the UI i always got something unexpected. i decided it was user error/ignorance of the h color space and stopped trying to fine tune it.

rob
 
As I suspected, there was something wrong with my PI settings so I did reset them and obtained the following new "h" values:



I hope they are in line with others this time...

The buttons are not an essential part of this script but in their current state they are misleading. As long as you remember to use the "h" values for your targeted color range, the script works perfectly.
 
As I suspected, there was something wrong with my PI settings so I did reset them and obtained the following new "h" values:



I hope they are in line with others this time...

The buttons are not an essential part of this script but in their current state they are misleading. As long as you remember to use the "h" values for your targeted color range, the script works perfectly.
Can you repost the info from this post?
 
If Rick wouldn't object, I would like to post a slight modification of his marvelous ColorMask script.

The modifications include:
- added Luminance and Chrominance numeric filters (useful if you want for example make a mask for a reds but only for bright part of image, i.e. skipping background color noise)
- you can set hue range which is used when you press color preset buttons; buttons themselves are now colored and rearranged according to their hue value;
- all parameters are now stored between script calls.
- hue calculation changed from CIEh() function to H(), so hue numerical values are more familiar and evenly spaced (Adam Block post some videos about this)
1677511899187.png

UPD. 2023/02/27 some bugfixes/improvements upon users’ reports were made
 

Attachments

  • ColorMask_mod.zip
    8.9 KB · Views: 99
Last edited:
If Rick wouldn't object, I would like to post a slight modification of his marvelous ColorMask script.

The modifications include:
- added Luminance and Chrominance numeric filters (useful if you want for example make a mask for a reds but only for bright part of image, i.e. skipping background color noise)
- you can set hue range which is used when you press color preset buttons; buttons themselves are now colored and rearranged according to their hue value;
- all parameters are now stored between script calls.
- hue calculation changed from CIEh() function to H(), so hue numerical values are more familiar and evenly spaced (Adam Block post some videos about this)
View attachment 17850
UPD. 2023/02/27 some bugfixes/improvements upon users’ reports were made
Nice. If I might suggest- would it be possible to insert a small circular graphic of the color wheel with the Hue angles shown? I think this will make concrete how it works. The preset buttons would not need to be very large if more space is needed.

-adam
 
Nice. If I might suggest- would it be possible to insert a small circular graphic of the color wheel with the Hue angles shown? I think this will make concrete how it works. The preset buttons would not need to be very large if more space is needed.

-adam
Thank you Adam for your advices!
I've updated user interface with color wheel with displaying currently selected hue range on it. Hope this would be helplful

1678098159528.png
 

Attachments

  • ColorMask mod3.zip
    149.8 KB · Views: 141
Thank you Adam for your advices!
I've updated user interface with color wheel with displaying currently selected hue range on it. Hope this would be helplful

View attachment 17937
Yes..now THAT is more like it! I hope you receive positive feedback with this version.
May I make this available through my website (since you do not have a repository?).

-adam
 
Last edited:
Back
Top