Page 1 of 9
Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T05:30:15-07:00
by VanGog
(I am using Windows XP)
Is it possible to use HSV or HSL model to define colors which you want to work with? I mean I have RGB image, but would like to use HSL definition for fuzz.
For example I have image like this:
And want to suppress shadows located on routes. To do it with RGB definition model I would need to select cca 20-30 colors depending on fuzz (the more precise fuzz the more colors I have to specify). But with HSV/HSL definition this would be much more simple to do. I would like to define minimal values in the similar way
Code: Select all
HSL_min1 = { 197, 21, 29}; // ( color is in range of H>=197 && S>=21 && L >=29
HSL_max1 = { 222, 40, 33}; // and H<=222 && S<=40 && L <=33 ) // dark shadows
// or
HSL_min2 = { 104, 8, 31}; // ( color is in range of H>=104 && S>=8 && L >=31
HSL_max2 = { 216, 33, 46}; // and H<=216 && S<=33 && L <=46 ) // light shadows
// and so on ...
So the final algorithm would look for two sets of colors, if the color is in one of the group, then the following action will be performed...
It is exact definition which includes many of colors without need to define all the colors. Is there any way to do it? I would really welcome it.
So in the result, I would effect the defined colors and have something like this...
(shadows suppressed)
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T07:38:04-07:00
by snibgo
You could do it with "-fx". Where did you get the numbers from? I don't think they identify shadows.
Here, I crop an area and find the min and max values of H, S and L. Then I make a mask that is white where pixels are in that range; otherwise black. You could then use the mask to lighten the image, or whatever. Windows BAT syntax.
Code: Select all
for /F "usebackq" %%L in (`%IM%convert ^
20r45mo.jpg ^
-crop 30x30+10+50 ^
-colorspace HSL ^
-format "minH=%%[fx:minima.r]\nmaxH=%%[fx:maxima.r]\nminS=%%[fx:minima.g]\nmaxS=%%[fx:maxima.g]\nminL=%%[fx:minima.b]\nmaxL=%%[fx:maxima.b]" ^
info:`) do set %%L
%IM%convert ^
20r45mo.jpg ^
-colorspace HSL ^
-fx "r>=%minH%&&r<%maxH% && g>=%minS%&&g<%maxS% && b>=%minL%&&b<%maxL% ?1:0" ^
mask.png
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T10:29:49-07:00
by VanGog
OK, thanks. I tried it without crop on image of size 1024x768 looks it takes very long time or is it looped forever?
Code: Select all
SET minH=197
SET minS=21
SET minL=29
SET maxH=222
SET maxS=40
SET maxL=33
for /F "usebackq" %%L in (`%IM%convert ^
test.jpg ^
-colorspace HSL ^
-format "minH=%%[fx:minima.r]\nmaxH=%%[fx:maxima.r]\nminS=%%[fx:minima.g]\nmaxS=%%[fx:maxima.g]\nminL=%%[fx:minima.b]\nmaxL=%%[fx:maxima.b]" ^
info:`) do set %%L
%IM%convert ^
test.jpg ^
-colorspace HSL ^
-fx "r>=%minH%&&r<%maxH% && g>=%minS%&&g<%maxS% && b>=%minL%&&b<%maxL% ?1:0" ^
mask.png
pause
Unfortunately it seems unusable because it consumes too much of time :-/
I also do not understand how your script works but it seems to me that the last part RGB model which is wrong.
Is there any change to skip using for command to run IM?
Note: I am reading about fx and I found function hsl() there. Maybe this one could be used?
Edit: Now I am reading:
Making IM Faster (in general) ... maybe should I use Q8 instead Q16 to make the command faster? But still I would like avoid sending multiple calls,
Also:
Avoid using FX, The Special Effects Image Operator, if you can use Alpha Composition, or the simpler Evaluate, Simple Math Operations, or other techniques instead.
If you do need to use these, try restricting its use to the smallest image possible, or to a single channel of the image (when handling grayscale).
But I will need to work with huge images at least 2000x2000 px. So it seems that using fx is not the best way.
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T11:48:02-07:00
by snibgo
For fx, min and max must be in the range zero to one.
"-fx" is too slow for multi-megapixel images.
You could make a mask of the difference between the image and the average shadow colour.
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T11:59:30-07:00
by VanGog
Also I am reading:
Building ImageMagick as a shared library (the default) can greatly reduce load time. Libraries and coder modules are only loaded as they are needed so a dynamic version of IM will not load anything that it doesn't need to use during image processing. Also shared libraries tend to remain available so may not need to be reloaded for a second run.
I installed static version due to my inexperience. Maybe this static version loads unnecessary libraries on every run?
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T13:21:40-07:00
by snibgo
DLL will makes almost difference. To speed it up, you could make a mask of the difference between the image and the average shadow colour.
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T13:45:45-07:00
by VanGog
But it takes really huge time. I think this method is bad. If I would list all the colors using fuzz with low value - it should be much more faster. But it will be very tedious to get all the colors needed. I wanted to simplify my job.
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T15:36:25-07:00
by fmw42
I do not think -fuzz will automatically wrap around both sides of red in HSL or similar colorspaces where hue is at 0 = 360.
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-05-31T15:51:08-07:00
by snibgo
Fuzz doesn't wrap. That is one reason why Lab is often a better colorspace for this type of problem.
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-06-01T01:52:10-07:00
by VanGog
snibgo wrote:For fx, min and max must be in the range zero to one.
"-fx" is too slow for multi-megapixel images.
You could make a mask of the difference between the image and the average shadow colour.
I cannot find out why this does not make floats but rounds the numbers:
SET /A minH=(1/360)*197
SET /A minS=21/100
SET /A minL=29/100
SET /A maxH=(1/360)*222
SET /A maxS=40/100
SET /A maxL=33/100
Still it* takes very long even in Q8. * - the first code
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-06-01T01:56:10-07:00
by VanGog
snibgo wrote:Fuzz doesn't wrap. That is one reason why Lab is often a better colorspace for this type of problem.
What do you mean by wrap?
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-06-01T02:02:45-07:00
by VanGog
Edit:
VanGog wrote:If I would list all the colors <in RGB> using fuzz with low value - it should be much more faster. But it will be very tedious to get all the colors needed. I wanted to simplify my job.
I meant RGB. But I would leave this idea in the case that it would be possible to use fuzz for HSL. But its not clear to me how to get the HSL value into -fuzz. Should I convert to HSL and then to use fuzz with RGB value or how?
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-06-01T07:59:08-07:00
by snibgo
VanGog wrote:I cannot find out why this does not make floats but rounds the numbers:
SET /A minH=(1/360)*197
Because "set" calculates with integers only. 1/360 is zero, to the nearest integer.
VanGog wrote:What do you mean by wrap?
A hue of 359 degrees is very close to a hue of 1 degree. But "-fuzz" doesn't know this.
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-06-01T08:35:07-07:00
by VanGog
snibgo wrote:
VanGog wrote:What do you mean by wrap?
A hue of 359 degrees is very close to a hue of 1 degree. But "-fuzz" doesn't know this.
Fortunately I don't need to select red hues in this case. I work with colors in the range of yellow - green - cyan - blue. That's all.
snibgo wrote:VanGog wrote:I cannot find out why this does not make floats but rounds the numbers:
SET /A minH=(1/360)*197
Because "set" calculates with integers only.
Contra
snibgo wrote:For fx, min and max must be in the range zero to one.
How could the script work then when you suggest using floats but batch does not work with floats?
Re: Sophisticated fuzz with HSL definition?
Posted: 2014-06-01T09:05:46-07:00
by snibgo
This works ...
... because there is no calculation (no "/A").