http://www.viewdocsonline.com/document/to8qqp
Code: Select all
SET minH=0.547222222
SET minS=0.21
SET minL=0.29
SET maxH=0.616666667
SET maxS=0.4
SET maxL=0.33
Code: Select all
SET minH=0.547222222
SET minS=0.21
SET minL=0.29
SET maxH=0.616666667
SET maxS=0.4
SET maxL=0.33
Code: Select all
REM avgH=0.581944444
REM avgS=0.305
REM avgL=0.31
SET avgH1=58.1944444
SET avgS1=30.5
SET avgL1=31
SET avgH2=44.44444444
SET avgS2=20.5
SET avgL2=38.5
convert test.png -colorspace HSL -fuzz 15%% -fill Black +opaque "rgb(%avgH1%%%,%avgS1%%%,%avgL2%%%)" -colorspace sRGB result_mask.png
pause
So my rgb() function looks for incorrect colors?fmw42 wrote:I believe in IM HSL values are either all percent or 0-360,0-255,0-255 except in -modulate where 100,100,100 means no change.
see http://www.imagemagick.org/script/color.php
rgb values are all percent or all in range 0-255. It is only hue that has range 0-360 if not specified as percent.So my rgb() function looks for incorrect colors?
Code: Select all
° , % , %
max: 222, 40, 33
avg: 209.5, 30.5, 31
diff: 12.5 , 9,5 , 2
Then how should I calculate diffR , diffG , diffB when I have colors in HSL?fmw42 wrote:fuzz=sqrt((diffR^2+diffG^+diffB^2)/3)
Code: Select all
min: 197 21 29
max: 222 40 33
avg: 209,5 30,5 31
diff=3,472222222 // °
diff=(1/360)*100*diff // %
diff=10.3%
Code: Select all
avg: 160 20,5 38,5
diff=15,55555556 // °
diff=(1/360)*100*diff // %
diff=21,3184265%
I don't know what is lut.fmw42 wrote:The solution is easy. Just use -fx to create a 1D binary lookup table from your ranges of allowed H,S,L. Then apply the lut using -clut to the HSL version of the image to make a binary mask. Then apply the mask using -mask with your image (HSL or RGB) to do what further processing you want to do.
OK, I am going to try it but must to retype it to valid Windows syntaxfmw42 wrote:Here is what I have in mind.
It takes little time with -fx to create a 1D lut of size say 360x1 or even 3600x1. Then use -clut to apply the lut to the HSL image, which makes it a mask. This takes little time also since it is a lookup table. The mask is then used to limit the processing only to those pixels that were selected by the -fx expression.
The fx expression is made for each channel H, S, L so you get 3 1D grayscale luts that are combined to make one color lut. This is applied to the HSL image to make a mask.
The fx expressions are just ranges of values (r>X && r<Y)?white:black, for the hue channel
You will have to scale the S and L channels by 360x255, if you are working with HSL color values as 0-360, 0-256, 0-255
So something like the following:
You can make the expressions as complicated as you want.Code: Select all
fact=`convert xc: -format "%[fx:360/255]" info:` convert -size 360x1 xc: -colorspace HSL -fx "(r>Xr && r<Yr)?white:black" redlut.png convert -size 360x1 xc: -colorspace HSL -fx "(g>Xg*$fact && g<Yg*$fact)?white:black" greenlut.png convert -size 360x1 xc: -colorspace HSL -fx "(b>Xb*$fact && b<Yb*$fact)?white:black" bluelut.png convert redlut.png greenlut.png bluelut.png -combine lut.png convert \( image -colorspace HSL \) lut.png -clut mask.png convert image -mask mask.png <processing> result
Code: Select all
SET fact=`convert xc: -format "%%[fx:360/255]" info:`
convert -size 360x1 xc: -colorspace HSL -fx "(r>Xr && r<Yr)?white:black" redlut.png
convert -size 360x1 xc: -colorspace HSL -fx "(g>Xg*%fact% && g<Yg*%fact%)?white:black" greenlut.png
convert -size 360x1 xc: -colorspace HSL -fx "(b>Xb*%fact% && b<Yb*%fact%)?white:black" bluelut.png
convert redlut.png greenlut.png bluelut.png -combine lut.png
convert \( image -colorspace HSL \) lut.png -clut mask.png
convert image -mask mask.png <processing> result
Code: Select all
convert \( image -colorspace HSL \) lut.png -clut mask.png
Unix syntax requires it. In Windows, remove the \Why is there the question mark after and backslash before parenthesis? Why parenthesis are there: