color analyzer and correction tool

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

color analyzer and correction tool

Post by VanGog »

First of all sorry, this post is so long, but it is not simple to describe the functions I would like to see in IM, if they are not yet here...

Does IM has any analyzer for precise and intelligent detection of colors?
If not, just took this post like something I look for, and you could develop.

I have uploaded 5MB image but with 1:30 waiting time http://www.crocko.com/4DB350D539C04468B ... st_del.jpg to illustrate what I would like to analyzer from the image.

There is few sets of aerial photos on my computer, they have different colors and I would like to join all photos together but would like to correct the colors. I don't know if you have any color analyzer. My main idea is to get work with areas, not whole images.

I use comparison for illustration. Photoshop can use color selection, but not much intelligent. You can set color and tolerance when you try to find some color. But I would like to set tolerance (not right word) for every color. I would like to find characteristics for every color (first step, manual). On the image above I would like to analyze areas with forests. I know that PS has some graphical functions for example with Levels, where you see characteristics of the colors for some area. So my idea is to select some colors first.

Left strip on the image, forest values are:
#3e4b31 (C:68%, M:49%, Y:81%, K:46%)
#434e3e (C:68%, M:50%, Y:71%, K:42%)
#404d33 (C:68%, M:48%, Y:80%, K:44%)
#2d3b2a (C:72%, M:53%, Y:77%, K:58%)
#384635 (C:70%, M:51%, Y:74%, K:48%)
So it would be good to have a way to find some color(s) and to define minimum and maximum values that are acceptable for the certain color in the resulting selection. I mean something like this:

Code: Select all

-selectcolor #384635 (C1:69%, C2:71%, M1:50% M2:52%, Y1:72%, Y2:76%, K1:47%, K2:49%)
Next step should be to name the selection, "forest1".

Till now you maybe have some function to this if you work with a smaller image. But now you have bigger image like I don' know, e.g. 16000x16000px and there are blocks by 4000x4000px. One block has darkers colors and second block has lighter colors. So to analyze next block I need to define next colors, but problem is, that I don't want this selection should be from the block which was already analyzed. Probably there would be some function to detect that in certain area, are pixels already selected and this area should not be proccessed into next selection.

So I define next forest colors for the second strip:
#041205 (C:75%, M:60%, Y:72%, K:83%)
#18251e (C:77%, M:59%, Y:71%, K:73%)
#222f26 (C:75%, M:57%, Y:72%, K:66%)
#283629 (C:74%, M:54%, Y:74%, K:61%)
#47544b (C:69%, M:51%, Y:63%, K:36%)
and similar colors. Lets call this for example "forest2"

Last strip, forest colors:
light greens:
#475d39 (C:69%, M:43%, Y:84%, K:34%)
#31461d (C:73%, M:47%, Y:98%, K:51%)
#334821 (C:73%, M:47%, Y:96%, K:49%)
#355224 (C:75%, M:43%, Y:100%, K:42%)
#24361e (C:75%, M:52%, Y:85%, K:63%)
dark greens:
#0a0e00 (C:71%, M:62%, Y:72%, K:84%)
#1b1c17 (C:71%, M:64%, Y:70%, K:78%)
#454638 (C:63%, M:55%, Y:71%, K:47%)
#222b1a (C:71%, M:56%, Y:79%, K:70%)

So the analyze should sensitively find similar colors. But the main goal is to search by little block, so I think there would be necessary to used some grid system, because you need to know what square has been searched and had a result. For this it would be good to search bigger blocks like 25x25 to detect if there was some positive result. Next if there was positive result, then evaluate, bigger area for example in square 277x277 to ensure no positive result was found here. For next search and next strips this area should be avoided. So you know (you remember) what you found and do not next search in that area. I could for example search
1) strip one 1.1) forest 1.2) grass and fields 1.3) rivers 1.4) other water surface
2) strip two 2.1) forest 2.2) grass and fields 2.3) rivers 2.4) other water surface
2) strip two 3.1) forest 3.2) grass and fields 3.3) rivers 3.4) other water surface

There is one more problem:
For correction of colors I will need to select all pixels by named selections. But all pixels of the image must by adjusted, so what I need is to select adjacent pixels (pixels adjacent to the named selection, if there is nor selection yet). This way all pixels would be selected and named.

Next step is "What to do with the selections?"
I would need to define what selection I want to use, and apply color corrections (probably level or any other function to correct this problem).

Edit
One more idea how to make the selection more precise and correct. In Photoshop, there is function levels. If you select little area of forest, you can PS levels will auto analyze the contrast of the area and gives this curve:
http://www.noeticart.com/photos/blog/le ... log_01.jpg
Contrast is one of the most important issues when comparing two photos or two segments. So if you could analyze a square in grid you will see that strip one forest has high values between 2,56 and 1,57 (I don't know what the number means but it is the horizontal position on the axis). The darker green on strip two has values from 0 to 1. This would be also good information to define if it is correct area! It could be first step, before color analyzer. If we could define, contrast on R,G,B and C,Y,M,K channels separately, that would be precise enough.
Maybe whole this post could be shortened on this basic idea. If we could select area by defining contrast level in square of the grid, I could simply select the areas that need the correction!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color analyzer and correction tool

Post by fmw42 »

IM has a function -segment , but it does not work very "intelligently". see http://www.imagemagick.org/script/comma ... v7#segment

You can do the same things in IM that you mention in photoshop. You can isolate a region based upon fuzzy thresholding or fuzzy color selection. You can process regions to adjust the brightness and contrast, see -brightness-contrast or -sigmoidal-contrast.

http://www.imagemagick.org/script/comma ... s-contrast
http://www.imagemagick.org/script/comma ... l-contrast

But there is no one single function that does exactly what you want, to my knowledge.
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: color analyzer and correction tool

Post by VanGog »

fmw42 wrote:You can isolate a region based upon fuzzy thresholding or fuzzy color selection.
What does it mean? Fuzzy color? What does it mean and what function is it? What do you mean by words "isolate a region", do you mean to select pixels?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color analyzer and correction tool

Post by fmw42 »

There are several techniques involving -fuzz to search for a range of colors near a color +- some color distance. see

http://www.imagemagick.org/script/comma ... msu83#fuzz
http://www.imagemagick.org/Usage/color_basics/#replace
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: color analyzer and correction tool

Post by VanGog »

OK, I understand. I thought you speak about some non-sharpen colors of the image. Is there way how to better specify the color in "amount of its 'components'" - If I say that color #3e4b31 has C:68%, M:49%, Y:81%, K:46% components, so is there a way how can I specify that I look for range of colors where Cyan can have -fuzz 1%, Magenta - fuzz 2%, Yellow -fuzz 5% Key -fuzz 2% ? Or more colors (R,G,B)... So maybe if this could be possible so I could use such common with -segment ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color analyzer and correction tool

Post by fmw42 »

-fuzz does not work in connection to -segment.

the only way to use -fuzz with individual r,g,b or c,m,y,k is to separate the channels into individual images and apply -fuzz ... to each channel, then recombine the channels.

see
http://www.imagemagick.org/Usage/color_basics/#channels

or use -channel to specify which channel to use and then use -fuzz, then +channel to get back to all the channels, the -channel again for a different channel. That way, you can do it all in one command.

convert image -channel r -fuzz ... +channel -channel g -fuzz .... +channel -channel b -fuzz ... +channel resultimage
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: color analyzer and correction tool

Post by VanGog »

After reading your answer in this thread viewtopic.php?f=1&t=20701&p=83086#p83086 about histogram, I think here could be solution how to test the areas. If I will learn how to work with the histograms.

My idea is to do batch, that will select some type of green with fuzz and generate histogram for this selection. I don't know if it is possible in IM. is it the same as in PS? I tried in PS to select dark green and then compared to green of different photo. This way I would compare more colors from the image. So I would generate histogram for the selection and than analyzed histogram areas in batch to get to know which type of level scheme I will use for it.

But is it possible to select e.g. just one quarter of the image, then in this area select only the green I want, then generate the histogram. Do it for all 4 quarters and probably save to file?

And second question is if it would be possible to analyze the histogram image in the way, that I select a part of the image (I would specify the coordinates manually) and than to generate the txt information as you mentioned in the thread "How to get color information".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color analyzer and correction tool

Post by fmw42 »

VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: color analyzer and correction tool

Post by VanGog »

I have found the link
"Cropping into roughly Equally Sized Divisions"
http://www.imagemagick.org/Usage/crop/#crop_equal

Code: Select all

 convert rose: -crop 23x15  +repage  +adjoin  rose_23x15_%02d.gif
That's awesome! But how to pass these images to generate histogram? Is it possible to do it from one convert command? And how to name the histogram, or the cuts/crops, is it possible to use temp name instead of original name? Or is it possible to pass the files to temp folder? How to do it in a clear way.

And still the question is here: is it not possible to generate histogram from fuzzy green selection? So the most sure way how to make the analysis is to get the median green and darker and dark green and this analyze. I cannot do analysis for area which contains light greens, because these are field usually. And I can analyze colors of forests to find what level setting to use for the image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color analyzer and correction tool

Post by fmw42 »

You are going to have to use several lines to do the processing.

You can make a variable for the input image name (without suffix) and use that in your output name

inname=`convert image -format "%t" info:`

convert image ..... ${inname}_%d.png
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: color analyzer and correction tool

Post by VanGog »

Code: Select all

inname=`convert image -format "%t" info:`
convert image ..... ${inname}_%d.png
Sorry but I did not recognized syntax that you used. Is it syntax for batch file?
Because this looks more like batch ... And I use Windows.

But I would need more training this because I do not understand how you mean to do it. Esspecially the part " -format "%t"" . Any link to describe how to define output filenames? (I searched google and found only this link:
viewtopic.php?f=3&t=19174
where the percentage character is used again in "%[filename:base]-%"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color analyzer and correction tool

Post by fmw42 »

It is a string format. see http://www.imagemagick.org/script/escape.php

The syntax for the variable is unix. You will need to find a way to do that in Windows. I am not a windows user. But see http://www.imagemagick.org/Usage/windows/
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: color analyzer and correction tool

Post by VanGog »

fmw42 wrote:You are going to have to use several lines to do the processing.

You can make a variable for the input image name (without suffix) and use that in your output name

inname=`convert image -format "%t" info:`

convert image ..... ${inname}_%d.png
I did not find equivalent solution for batch, but I realized, that the solution is pretty simple.

Code: Select all

set="path=temp/"
convert image .... .%path%%d.png
or

Code: Select all

set="path=temp/"
convert image .... .!path!%d.png
Now, when I watch it. I ask myself why this commands %d, %t etc works in batch files. Why not double the percentage sign?

I will do the analyzer. My plan is this:

Crop the image on small pictures and process them similar like I would do with areas in a grid -> create hexagrams for this pictures. Here I want to apply the histogram only on selected greens (I would probably select all colors that are not my selection of green... fuzz 25% -fill white +opaque green ... (at this point I should probably make grayscale for brightness histogram) and then to use the histogram. I think that it could show the white color on right and the greens on left).

At the last stage I would repeat the similar process on the temp/images*.gif histograms. I would separate histograms to grid cuts ---> similar cut command like above. Then make histograms of brightness, and then output if the histogram contains 100% black or 100% white or some other values. This way I can analyze any area of histogram. It is a lit complicated, but should work. I hope, in future you could integrate similar grid function to IM, that would do similar analyzes.
Post Reply