IM really needs this feature

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM really needs this feature

Post by snibgo »

See http://www.imagemagick.org/script/color.php . But you can just use "rgb(58.194%%,30.5%%,31%%)".
snibgo's IM pages: im.snibgo.com
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: IM really needs this feature

Post by VanGog »

Thanks now it works. So the only thing what could be improved in the -fuzz is to
have possibility to specify more colors
e.g

Code: Select all

convert test.png -colorspace HSL -fuzz 15%% -fill Black +opaque "rgb(%avgH1%%%,%avgS1%%%,%avgL1%%%),rgb(%avgH2%%%,%avgS2%%%,%avgL2%%%)" -colorspace sRGB result_mask.png
It would also solve the missing of wrapping in HSL model.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM really needs this feature

Post by fmw42 »

Code: Select all

convert test.png -colorspace HSL -fuzz 15%% -fill Black +opaque "rgb(%avgH1%%%,%avgS1%%%,%avgL1%%%),rgb(%avgH2%%%,%avgS2%%%,%avgL2%%%)" -colorspace sRGB result_mask.png
Is it really valid it specify two values for +opaque? I never heard of that feature! If so, is it really finding a fuzz amount around each value and replacing everything not in those two ranges with black?
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: IM really needs this feature

Post by VanGog »

Maybe it could be better written like so:

Code: Select all

convert test.png -colorspace HSL -fuzz 15%% -fill Black +opaque "rgb(%avgH1%%%,%avgS1%%%,%avgL1%%%)||rgb(%avgH2%%%,%avgS2%%%,%avgL2%%%)" -colorspace sRGB result_mask.png
I think this would either need new function
instead of IsColorSimilar to use AreColorsSimilar which could recieve more colors in argument. Or just edit the IsColorSimilar function. The algorithm should find out if the color is in range of one of the colors. If both colors are out of range so it would be like they are not in the fuzz tolerance. The idea is simple, but harder to explain because colorspaces are my weakness - I am not good on mathematics. But I know it must work. It's basicly that you process every pixel and test it for multiple conditions.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IM really needs this feature

Post by fmw42 »

VanGog wrote:Maybe it could be better written like so:

Code: Select all

convert test.png -colorspace HSL -fuzz 15%% -fill Black +opaque "rgb(%avgH1%%%,%avgS1%%%,%avgL1%%%)||rgb(%avgH2%%%,%avgS2%%%,%avgL2%%%)" -colorspace sRGB result_mask.png
I think this would either need new function
instead of IsColorSimilar to use AreColorsSimilar which could recieve more colors in argument. Or just edit the IsColorSimilar function. The algorithm should find out if the color is in range of one of the colors. If both colors are out of range so it would be like they are not in the fuzz tolerance. The idea is simple, but harder to explain because colorspaces are my weakness - I am not good on mathematics. But I know it must work. It's basicly that you process every pixel and test it for multiple conditions.

That is why I keep suggesting my 1D color lut using -fx to create the lut. You can build any combination of colors and comparisons.
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: IM really needs this feature

Post by VanGog »

I'd like to create my own little program, which could do similar thing as I described here. Based on specialized HSB definitions I could generate masks.

I would like to ask ImageMagick programmers where can I find the blur and level function in IM source? Possibly also function which joins images e.g. you have a grid of 3x3 image same size and want to join them. Because I would like to include these features in my program.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM really needs this feature

Post by snibgo »

I'm not a programmer, but:

effect.c has BlurImage(...).
enhance.c has LevelImage(...).
snibgo's IM pages: im.snibgo.com
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: IM really needs this feature

Post by VanGog »

The blur functions look very hard for me to understand (* but I found interesting explanation at least for gausian filter here http://stackoverflow.com/questions/1696 ... -functions ). The LevelImage seems more simple. I am checking it to understand how it works.

For the case that somebody with the knowledge would read this - my question to the function is what are meanings of these entities: rho, sigma - I see that black_point is rho but why? Does it mean black is expressed in angle? Which colorspace model/diagram should I check?

As far as I understand it so the main job is done by the method LevelPixel image. So IM first calculates scale (every time for every pixel?)

Code: Select all

scale=(white_point != black_point) ? 1.0/(white_point-black_point) : 1.0;
And then you change the color value saved in the pixel variable.

Code: Select all

level_pixel=QuantumRange*gamma_pow(scale*((double) pixel-black_point),1.0/
    gamma);
Post Reply