Page 3 of 9

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-01T16:55:34-07:00
by VanGog
I will explain what I need to process later. Now, its not clear why you use r, g, b on the left side of expression. Why dont you use hue, saturation and lightness?

I still dont understand how to use it. Why should I use r g b when working with HSL? Not clear how to calculate the r g b and why.

Why not to write it as so:

Code: Select all

REM Calculate colors from HSL to RGB .. and create mask

REM avgH=0.581944444
REM avgS=0.305
REM avgL=0.31

REM IM uses range of 0-100% for rgb() so I have to multiply by 100

SET avgH1=58.1944444
SET avgS1=30.5
SET avgL1=31

SET avgH2=44.44444444
SET avgS2=20.5
SET avgL2=38.5

SET fact=`convert xc: -format "%%[fx:360/255]" info:`
convert -size 360x1 xc: -colorspace HSL -fx "(hue>avgH && hue<avgH)?white:black" h.png
convert -size 360x1 xc: -colorspace HSL -fx "(saturation>avgS*%fact% && saturation<avgS*%fact%)?white:black" s.png
convert -size 360x1 xc: -colorspace HSL -fx "(lightness>avgL*%fact% && avgL<Yb*%fact%)?white:black" l.png

convert h.png s.png l.png -combine lut.png

convert ( image -colorspace HSL ) lut.png -clut mask.png

convert image -mask mask.png <processing> result
Should I change -size 360x1 to 1024x1 according width of my image?

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-01T17:32:54-07:00
by fmw42
IM only recognized r,g,b,c,y,m,k channels. You convert to HSL, but IM does not know that. It only knows that you have 3 channels. It treats the Hue as R (first channel), Sat as G (second channel), Light as B (third channel). However, it is really processing H,S,L. That is also why you need to apply the 1D lut to the HSL version of the image. see -fx http://www.imagemagick.org/script/fx.php
and -channel http://www.imagemagick.org/script/comma ... hp#channel.

r is shortcut name for u.r, g is shortcut for u.g and b is shortcut for u.b. That is really what -fx understands. It does not understand hue, saturation or lightness as arguments. u means the pixels of the input image. Read the link for -fx.

-fx only understand values in the range of 0-1 for images. So my commands should really be as follows. (sorry for my earlier error).

if you use Hue in range 0-360, Sat in the range of 0-255 and Light in the range 0-255, then just do

Code: Select all

convert -size 1x360 gradient: -fx "(u>Hmin/360 && u<Hmax/360)?white:black" red_hue_lut.png
convert -size 1x360 gradient: -fx "(u>Smin/255 && u<Smax/255)?white:black" green_sat_lut.png
convert -size 1x360 gradient: -fx "(u>Lmin/255 && u<Lmax/255)?white:black" blue_light_lut.png

convert red_hue_lut.png green_sat_lut.png blue_light_lut.png -combine lut.png

convert ( image -colorspace HSL ) lut.png -clut mask.png

convert image -mask mask.png <processing> result
Note, the above has been revised since first posted.

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T04:16:01-07:00
by VanGog
I read your reference but I have no idea how you do your calculations or what they mean in the examples. I can understand the first part of CLUV article, where it is about gradients. But the part starting "Function to Color LUT Conversion" :
replace the 'u' in the function with the value '(i/w)' or '(j/h)' to calculate the replace value based on its position.
is subject for confusion for me. What does this crazy expression mean is not clear to me:

Code: Select all

SET fact=`convert xc: -format "%[fx:360/255]" info:`

convert -size 360x1 xc: -colorspace HSL -fx "(r>= && r<=)?white:black" h.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

conver
t -size 360x1 xc: -colorspace HSL -fx "(g>=*`convert xc: -format "%[fx:360/255]"
 info:` && g<=*`convert xc: -format "%[fx:360/255]" info:`)?white:black" s.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

convert -size 360x1 xc: -colorspace HSL -fx "(b>=*`convert xc: -format "%[fx:360/255]"
 info:` && b<=*`convert xc: -format "%[fx:360/255]" info:`)?white:black" l.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

convert h.png s.png l.png -combine lut.png

convert ( test.png -colorspace HSL ) lut.png -clut mask.png

convert test.png -mask mask.png  0<processing 1>result
file not found
The second code of you results:

Code: Select all

convert -size 1x360 gradient: -fx "(u>/360 && u</360)?white:black" red_hue_lut.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

conver
t -size 1x360 gradient: -fx "(u>/255 && u</255)?white:black" green_sat_lut.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

conver
t -size 1x360 gradient: -fx "(u>/255 && u</255)?white:black" blue_light_lut.png

convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

convert red_hue_lut.png green_sat_lut.png blue_light_lut.png -combine lut.png

convert ( image -colorspace HSL ) lut.png -clut mask.png
convert.exe: unable to open image `image': No such file or directory @ error/blob.c/OpenBlob/2614.
convert.exe: no decode delegate for this image format `image' @ error/constitute.c/ReadImage/532.
convert.exe: missing an image filename `mask.png' @ error/convert.c/ConvertImage
Command/3016.

convert test.jpg -mask mask.png  0<processing 1>result
file not found

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T06:33:41-07:00
by snibgo

Code: Select all

convert -size 1x360 gradient: -fx "(u>Hmin/360 && u<Hmax/360)?white:black" red_hue_lut.png

convert -size 1x360 gradient: -fx "(u>/360 && u</360)?white:black" red_hue_lut.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.
When using Windows environment variables, you need % at each start and end, thus:

Code: Select all

convert -size 1x360 gradient: -fx "(u>%Hmin%/360 && u<%Hmax%/360)?white:black" red_hue_lut.png

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T06:43:58-07:00
by VanGog
No, that is not the error.

Code: Select all

convert -size 1x360 gradient: -fx "(u>54.72222222/360 && u<61.66666667/360)?white:black" red_hue_lut.png

convert -size 1x360 gradient: -fx "(u>21/255 && u<40/255)?white:black" green_sat_lut.png

convert -size 1x360 gradient: -fx "(u>29/255 && u<33/255)?white:black" blue_light_lut.png

convert red_hue_lut.png green_sat_lut.png blue_light_lut.png -combine lut.png

convert ( test.jpg -colorspace HSL ) lut.png -clut mask.png

convert test.jpg -mask mask.png  0<processing 1>result
file not dound
Still file not found

And the first code has this error:

Code: Select all

convert -size 360x1 xc: -colorspace HSL -fx "(r>= && r<=)?white:black" h.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

convert -size 360x1 xc: -colorspace HSL -fx "(g>=*`convert xc: -format "%[fx:360/255]"
 info:` && g<=*`convert xc: -format "%[fx:360/255]" info:`)?white:black" s.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

convert -size 360x1 xc: -colorspace HSL -fx "(b>=*`convert xc: -format "%[fx:360/255]"
 info:` && b<=*`convert xc: -format "%[fx:360/255]" info:`)?white:black" l.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T06:57:56-07:00
by snibgo

Code: Select all

convert test.jpg -mask mask.png  0<processing 1>result
file not dound
The command is junk. What is "processing"?

Code: Select all

convert -size 360x1 xc: -colorspace HSL -fx "(r>= && r<=)?white:black" h.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.
The command is junk. What values is r being compared to?

Code: Select all

convert -size 360x1 xc: -colorspace HSL -fx "(g>=*`convert xc: -format "%[fx:360/255]"
 info:` && g<=*`convert xc: -format "%[fx:360/255]" info:`)?white:black" s.png
convert.exe: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2092.
The command is junk. The "-fx" contains two converts.

Please paste your Windows script.

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T07:09:02-07:00
by VanGog
test.jpg or test.png

Code 1

Code: Select all

REM Calculate colors from HSL to RGB .. and create mask

REM avgH=0.581944444
REM avgS=0.305
REM avgL=0.31

REM IM uses range of 0-100% for rgb() so I have to multiply by 100

SET minH1=54.72222222
SET minS1=21
SET minL1=29
SET maxH1=61.66666667
SET maxS1=40
SET maxL1=33

SET minH2=28.88888889
SET minS2=8
SET minL2=31
SET maxH2=60
SET maxS2=33
SET maxL2=46


SET fact=`convert xc: -format "%%[fx:360/255]" info:`
convert -size 360x1 xc: -colorspace HSL -fx "(r>=%minH% && r<=%maxH%)?white:black" h.png
convert -size 360x1 xc: -colorspace HSL -fx "(g>=%minS%*%fact% && g<=%maxS%*%fact%)?white:black" s.png
convert -size 360x1 xc: -colorspace HSL -fx "(b>=%minL%*%fact% && b<=%maxL%*%fact%)?white:black" l.png

convert h.png s.png l.png -combine lut.png

convert ( test.png -colorspace HSL ) lut.png -clut mask.png

convert test.png -mask mask.png <processing> result
code 2

Code: Select all

REM Calculate colors from HSL to RGB .. and create mask

REM avgH=0.581944444
REM avgS=0.305
REM avgL=0.31

REM IM uses range of 0-100% for rgb() so I have to multiply by 100

SET minH1=54.72222222
SET minS1=21
SET minL1=29
SET maxH1=61.66666667
SET maxS1=40
SET maxL1=33

SET minH2=28.88888889
SET minS2=8
SET minL2=31
SET maxH2=60
SET maxS2=33
SET maxL2=46

convert -size 1x360 gradient: -fx "(u>%minH1%/360 && u<%maxH1%/360)?white:black" red_hue_lut.png
convert -size 1x360 gradient: -fx "(u>%minS1%/255 && u<%maxS1%/255)?white:black" green_sat_lut.png
convert -size 1x360 gradient: -fx "(u>%minL1%/255 && u<%maxL1%/255)?white:black" blue_light_lut.png

convert red_hue_lut.png green_sat_lut.png blue_light_lut.png -combine lut.png

convert ( test.jpg -colorspace HSL ) lut.png -clut mask.png

convert test.jpg -mask mask.png <processing> result

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T07:28:44-07:00
by snibgo
Code 1:

Code: Select all

SET fact=`convert xc: -format "%%[fx:360/255]" info:`
This is junk in Windows. Use:

Code: Select all

SET fact=1.4117647

Code: Select all

convert -size 360x1 xc: -colorspace HSL -fx "(r>=%minH% && r<=%maxH%)?white:black" h.png
But what are the values of %minH% and %maxX%? You haven't set them. Same problems with S and L.

Code: Select all

convert test.png -mask mask.png <processing> result
What is this command for? It is junk. Replace "<processing>" with whatever processing you need, and "result" with a proper filename, such as "result.png".

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T09:12:00-07:00
by VanGog
Sorry for my slow responses today because I am sick & out of energy. That is also why my thinking is slowed :-/. I noted that the mask does not contain all the shadows that should be there. It should contain all shadows which are on routes and walls of buildings. The shadows on grass are not included. The dots of shadows are colored and not like I expected.

The mask I have created by my script using -HSL and -fuzz:
Image
Looked more correct than the mask bellow:
Image
But both should be in white black color of sure.

Proccess:

I need to suppress the shadows. I did this in Photoshop but it takes more steps. But I think I would like to try to use MPR first, and then to do the suppress of shadows:

Image

1) Select the pixels from the image (aerial photo of city / daylight) using mask
2) copy this to MPR and name it e.g. "original_routes" - I will use this at least 2x or 3x in the following steps

3) use new layer - lets call it "Routes shadows 71% visibility"
this is a group in fact which will apply 71% visibility for the steps bellow

4) grab the copy of "original_routes"
5) use levels: input values: 0 , 1 , 95 (default input values in Photoshop are 0, 1, 255 ; output is unchanged : 0 , 255)
6) apply effect: soft light blending ... I cannot to explain it but maybe here is some definition:
http://graphicssoft.about.com/od/glossa ... _Light.htm
You should get image of shadows like this:
http://oi59.tinypic.com/2yuletk.jpg
it gives light "blue light" color to the image area which is under it.

7) create new layer from the previous layer
8) Change hue to +160 ... The range in Photohop is -180* to 180* and the original value is 0. So when you add +160 and apply the
9) soft light and visibility of this layer is 43%
so you removed a lot of the blue from the shadows:
Image

10) additionally create new layer
11) again use new copy of "original_routes"
here I need to change color of cyan channel (I did this in separate window because my file is in RGB)
I used these values for curves: input: 57 output: 81
apply color blending (this will effect colors of the image bellow - we still work only with the pixels of shadows - the pixels copy the color)
This removes most of the blues in shadows and makes it a bit darker:
Image

Notice: all steps have effect. If you exclude one step I will notice the difference. I you example would skip effect of hue 160° applied at 43% visibility, you would have much darker shadows now.

12) now check the point 3) - now is time to apply visibility to all those layers: 71%

And we're done.

There is yet another layer but that is for green shadows not for on-route shadows.

Compare original and the result (detail from another area)
Image

My actual code:
http://paste.ofcode.org/32EQK58F6mtGm688fG5hkcU

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T09:50:02-07:00
by fmw42
Note that I changed my code in my earlier post. There is no fact=360/255. You need to convert the tests to use values between 0 and 1.

If you provide your input image your exact min and max values for HSL and what the ranges are for each, I will try to process your image. I need to know what ranges you are using for H, S and L, because if you are trying to use PS values, they may have different ranges than IM needs. If I recall, Sat in PS is 0-100, but in IM it is 0-255. So I need to understand what your H, S, L values mean in terms of their ranges. Or provide them to me in percent by dividing by the proper range max value for the system from which you obtained them.

fx starts with an input grayscale gradient. For each pixel it does the test. u will range from 0 to 1. So it tests the gradient for all possible pixels between 0 and 1 that then are converted to the size of the input gradient, in this case 360. Where u is within the range you specify for H, S, L (scaled to the range 0 to 1), it will output white, otherwise it outputs black. The output 1D image will be white where your tests pass and black where they fail for each channel H, S, L. The 1D image can then be used by -clut to transform you HSL image to a black/white mask, which can then be used to process your original image using -mask.

Once I provide the mask, you will have to convert your PS commands into IM processing equivalents. That is a separate issue.

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T10:05:08-07:00
by fmw42
From your code

Code: Select all

REM Calculate colors from HSL to RGB .. and create mask

REM avgH=0.581944444
REM avgS=0.305
REM avgL=0.31

REM IM uses range of 0-100% for rgb() so I have to multiply by 100

SET minH1=54.72222222
SET minS1=21
SET minL1=29
SET maxH1=61.66666667
SET maxS1=40
SET maxL1=33

SET minH2=28.88888889
SET minS2=8
SET minL2=31
SET maxH2=60
SET maxS2=33
SET maxL2=46

convert -size 1x360 gradient: -fx "( (u>%minH1%/360 && u<%maxH1%/360)||(u>%minH2%/360 && u<%maxH2%/360)  )?white:black" red_hue_lut.png
convert -size 1x360 gradient: -fx "( (u>%minS1%/255 && u<%maxS1%/255)||(u>%minS2%/360 && u<%maxS2%/360) )?white:black" green_sat_lut.png
convert -size 1x360 gradient: -fx "( (u>%minL1%/255 && u<%maxL1%/255)||(u>%minL2%/360 && u<%maxL2%/360) )?white:black" blue_light_lut.png
This code seem inconsistent with your data.


These avg values seem to be already in fractions. You then seem to convert them to percent to get min and max.

Code: Select all

REM avgH=0.581944444
REM avgS=0.305
REM avgL=0.31

REM IM uses range of 0-100% for rgb() so I have to multiply by 100

SET minH1=54.72222222
SET minS1=21
SET minL1=29
SET maxH1=61.66666667
SET maxS1=40
SET maxL1=33
But you are then normalizing by 360 and 255 in -fx, which is wrong. You would properly need to normalize by 100 to get them back to fractions between 0 and 1.

So you should be using

Code: Select all

convert -size 1x360 gradient: -fx "( (u>%minH1%/100 && u<%maxH1%/100)||(u>%minH2%/100 && u<%maxH2%/100)  )?white:black" red_hue_lut.png
convert -size 1x360 gradient: -fx "( (u>%minS1%/100 && u<%maxS1%/100)||(u>%minS2%/100 && u<%maxS2%/100) )?white:black" green_sat_lut.png
convert -size 1x360 gradient: -fx "( (u>%minL1%/100 && u<%maxL1%/100)||(u>%minL2%/100 && u<%maxL2%/100) )?white:black" blue_light_lut.png
Or just convert the ave as fractions to min and max as fractions and leave off the /100.


Furthermore, you have compounded the conditions to find two regions. But if you expect to process the two regions differently, you need to make two masks, one for each set of processing. You said you have dark shadows and light shadows. If the are processed differently, then you need to create a mask for each and not combine the two into one mask.

You also need to fill in <processing> with your exact processing commands. <processing> was just a placeholder for what you really want to do in IM to change the regions.

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T10:10:09-07:00
by VanGog
Here I uploaded testing image and xls table containing two sets of shadow values which I used in the last code.
http://www.fileconvoy.com/dfl.php?id=g6 ... eddbbf7d7c

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T10:15:29-07:00
by fmw42
Sorry I do not understand your table. Lets take one set of shadows. What tool extracted these values?

H S Brightness
min: 104 8 31
max: 216 33 46
avg: 160 20.5 38.5

What are the ranges for your H, S, B? Is this colorspace HSB or HSL? IM distinguishes them as different?

Why do your images have two separate parts joined together?

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T10:33:05-07:00
by fmw42
One other possible modification is that if your conditions for each channel must be satisfied jointly rather than independently, then the combining of the 3 1D luts will need to become

Code: Select all

convert red_hue_lut.png green_sat_lut.png blue_light_lut.png -evaluate-sequence multiply lut.png
so that you get only white where all three images are white and black elsewhere rather than color lut.

Re: Sophisticated fuzz with HSL definition?

Posted: 2014-06-02T10:45:10-07:00
by VanGog
Does your program really work to generate B/W mask? My mask is in RGB having colored pixels there.

I used Eyedropper tool to manually select color and view it with ColorPicker in Photoshop. There are these values displayed: H [°],S [%],B [%]
B is Brightness which is the same as Lightness. I have being looking for various colors of the shadows on routes and I have been writing them to the table on left. Then I found the minim and maximum and written them to the table on left.
What tool extracted these values?
H S Brightness
min: 104 8 31
max: 216 33 46
avg: 160 20.5 38.5
The first two rows are those values which I have written from left table.
The third line is average calculated from these values. I used these values with fuzz.

I do conversion bellow

Code: Select all

min:	0,547222222	0,21	0,29
max:	0,616666667	0,4	0,33
avg:	0,581944444	0,305	0,31
And then I do one more converiton to Image Magick:

Code: Select all

min IM:	54,72222222	21	29
max IM:	61,66666667	40	33
avg IM:	58,19444444	30,5	31
So now we need to work with
min IM and max IM

Do you see the formulas in the cells?