The r, g, b are not really red, green and blue, but simply the first, second and third channel.
The color picker from PS is computing HSB not HSL. So you must ensure that you convert HSB to HSL properly and consistently with what the code expects if you want to use HSL. But note that HSL is hard to work with, since pure r,g,b,c,m,y colors are at 50% lightness. I would shy away from using HSL. However, if you want to use those color values, be sure that you compute the values consistent with H 0-360, S 0-100 and L 0-100. Then use the following code. This is unix and so you will need to convert it to window syntax.
The easiest way to do the conversion is
Code: Select all
convert -size 1x1 xc:"hsb(hval,sval,bval)" -colorspace HSL -format "%[pixel:u.p{0,0}]" info:
Code: Select all
Hmin=your computed value
Hmax=your computed value
Smin=your computed value
Smax=your computed value
Lmin=your computed value
Lmax=your computed value
convert -size 360x1 xc: -fx "(i>$Hmin && i<$Hmax)?white:black" h_lut.png
convert -size 360x1 xc: -fx "(i>$Smin*3.6 && i<$Smax*3.6)?white:black" s_lut.png
convert -size 360x1 xc: -fx "(i>$Lmin*3.6 && i<$Lmax*3.6)?white:black" l_lut.png
convert h_lut.png s_lut.png l_lut2.png -combine lut.png
convert \( test2.png -colorspace hsl \) lut.png -clut -separate -evaluate-sequence multiply test2_hsl_mask.png
So this should be very fast
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" \) \
\( -size 360x1 xc: -fx "(i>$Smin && i<$Smax)?white:black" \) \
\( -size 360x1 xc: -fx "(i>$Bmin && i<$Bmax)?white:black" \) \
\( -clone 0-2 -combine \) -delete 0-2 \
\( test2.png -colorspace hsb \) \
+swap -clut -separate -evaluate-sequence multiply test2_mask.png
You can process two images at the same time, but you need to duplicate code and use -write to save the earlier results. However, if you have multiply images to process, the best way would be to put the command in a loop over each image.