I am starting to think that your point picker colors are HSB and not HSL (single hexcone rather than double hexcone)
otherwise the brightness mask is not getting the dark values properly. To validate, I used the values in your colorpicker image
You have rgb=51,67,82 and hsb=209,38,32
Code: Select all
convert -size 1x1 xc:"rgb(51,67,82)" -colorspace HSB txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsb
0,0: (58.0652%,37.8042%,32.1569%) #94A560C75252 hsb(58.0652%,37.8042%,32.1569%)
These are all in percent. Converting hue from percent to deg I get rounded values of
hsb=209,38,32
Thus, this confirms that you are not using HSL in the colorpicker but HSB!
So I have changed my code as follows:
Code: Select all
Hmin=104
Hmax=216
Smin=8
Smax=33
Bmin=31
Bmax=46
convert -size 360x1 xc: -fx "(i>$Hmin && i<$Hmax)?white:black" h_lut2.png
convert -size 360x1 xc: -fx "(i>$Smin*360/100 && i<$Smax*360/100)?white:black" s_lut2.png
convert -size 360x1 xc: -fx "(i>$Bmin*360/100 && i<$Bmax*360/100)?white:black" b_lut2.png
convert test2.png -colorspace hsb -separate test2_hsb_%d.png
convert test2_hsb_0.png h_lut2.png -clut test2_hsb_mask2_0.png
convert test2_hsb_1.png s_lut2.png -clut test2_hsb_mask2_1.png
convert test2_hsb_2.png b_lut2.png -clut test2_hsb_mask2_2.png
convert test2_hsb_mask2_0.png test2_hsb_mask2_1.png test2_hsb_mask2_2.png -evaluate-sequence multiply test2_hsb_mask2.png
First I convert all min and max values (in the fx) to the range 0 to 360 and use the i (x) image coordinate as the measure from 0 to 360. Since the hue values are already in the range 0 to 360, nothing needs to be done. The sat and brightness values need to be scaled from the range 0 to 100 to the range 0 to 360 to correspond with the size of the lookup table.
Next I separate the HSB channels to ensure that the are converted from RGB to HSB.
Then I apply the fx luts separately to each appropriate channel.
Then I combine them using -evaluate-sequence multiply to make the mask binary (via logical &&).
Here are the 3 mask images for each channel and the final mask.
hue:
saturation:
brightness:
final binary mask:
Note your saturation range may be shifted too high, since it does not get much of the shadow to the right side of the building on the left side of the image.
The above is all predicated upon the assumption that you are really using HSB not HSL and that values you have presented are in the ranges of hue 0 to 360, sat 0 to 100, and brightness 0 to 100. If any of these are wrong, then that invalidates the above. Please see if you can validate these assumptions. You can also pick points on each of the separated HSB channels and then we would modify the code because the range of HSB is either 0-360,0-255,0-255 or 0-100 for all three if in percent.
I am not that much an expert on PS. How are you validating that the color ranges you used correspond to the regions you want? The color picker in my version does not highlight any pixels in the image with those values. Also if you are using a color picker, why not just pick rgb colors?
Why don't you just use the PS color picker to get an rgb triplet (say it is rgb=51,67,82), then use the Color Range window to set the fuzz value (say it is 40%) to where you can select the regions you want. Then come back to IM and use the same thing.
Code: Select all
convert image -fuzz 40% -fill black +opaque "rgb(51,67,82)" -fill white -opaque "rgb(51,67,82)" maskimage
Just because you create the mask in RGB space, does not restrict you from further processing in HSL colorspace. For example you could use -modulate to change the H,S,L value for pixels only within the mask region.
[/b]