Page 1 of 3
How to get color information
Posted: 2012-04-07T13:08:28-07:00
by VanGog
Could you please help me with this? I need to do two simple batch scripts to test color information in image. So the output of the result should contain some information for the CMD.
1) (Solved) I want to test if file contains some pixels of white and to print some result. Possibly yes or no, or just print nothing if he has not the information. So I would ask for certain position in the image like: 0,0; 100,100; 500,500; 1000,1000 ... four points are enough to ensure that the image is not just white.
and second thing
2) (unsolved) I look for 4 groups of blue color: 1800ff. Every group has few of blue pixels, like if you made a stroke with a brush. So there will be at least 15px diameter of the pixel group. Is it possible to print coordinates for it? If not possible to find the group of pixels of given color, never mind, I would do it without it, just to print all the blue color pixels and I try to calculate with it. (Edit: Task has changed a bit. Now I need only to find pixel of the upper left corner from the blue brush stroke, and the lower right corner from the blue brush stroke. I think I could find the coordinates more simple in the output of the txt: command, if I could separate first line with blue pixels and last blue line of blue pixels. So to get image 256px x2 px.
Re: How to get color information
Posted: 2012-04-07T13:38:32-07:00
by fmw42
convert your image to txt: format and filter for a color by piping to grep.
convert yourimage: txt:- | grep "somecolor"
somecolor can be coloname, hex value such as #1800ff or rgb(r,g,b)
Example:
convert rose: txt:- | grep "white"
61,11: (255,255,255) #FFFFFF white
62,15: (255,255,255) #FFFFFF white
62,16: (255,255,255) #FFFFFF white
63,16: (255,255,255) #FFFFFF white
14,37: (255,255,255) #FFFFFF white
12,38: (255,255,255) #FFFFFF white
13,38: (255,255,255) #FFFFFF white
23,39: (255,255,255) #FFFFFF white
12,40: (255,255,255) #FFFFFF white
24,40: (255,255,255) #FFFFFF white
25,40: (255,255,255) #FFFFFF white
11,41: (255,255,255) #FFFFFF white
12,41: (255,255,255) #FFFFFF white
21,41: (255,255,255) #FFFFFF white
26,41: (255,255,255) #FFFFFF white
20,42: (255,255,255) #FFFFFF white
28,42: (255,255,255) #FFFFFF white
29,43: (255,255,255) #FFFFFF white
18,44: (255,255,255) #FFFFFF white
30,44: (255,255,255) #FFFFFF white
31,44: (255,255,255) #FFFFFF white
Re: How to get color information
Posted: 2012-04-07T14:31:57-07:00
by VanGog
One thing I did not realize. In the point 2) I forgot, that jpeg images have not exact color, but color in some range. So I need to find other way how to get the range of colors. When I click on the blue color from the saved image, so there is Y:0 and K:. Maybe this would be way how to filter it?
Re: How to get color information
Posted: 2012-04-07T14:32:31-07:00
by fmw42
Probably easier is just to list out the histogram. see
http://www.imagemagick.org/Usage/files/#histogram
Re: How to get color information
Posted: 2012-04-07T14:35:58-07:00
by fmw42
To get near colors use -fuzz xx% -fill black +opaque somecolor -fill somecolor -opaque somecolor . That will turn all the near colors into that color and the rest will become black.
convert image -fuzz xx% -fill black +opaque somecolor -fill somecolor -opaque somecolor txt:- | grep "somecolor"
see
http://www.imagemagick.org/Usage/color_basics/#replace
Re: How to get color information
Posted: 2012-04-07T14:56:41-07:00
by VanGog
The histogram is interesting function. It can generate "image" of the colors like PS levels. This could be solution to my previous question "color analyzer"
viewtopic.php?f=1&t=20695&p=83054#p83054...
Re: How to get color information
Posted: 2012-04-07T15:10:12-07:00
by VanGog
Is it possible to combine this two lines to one line?
Code: Select all
convert test.jpg -define histogram:unique-colors=false histogram:histogram.gif
convert histogram.gif -strip -resize 50% -separate histogram-%d.gif
Re: How to get color information
Posted: 2012-04-07T15:37:35-07:00
by fmw42
VanGog wrote:Is it possible to combine this two lines to one line?
Code: Select all
convert test.jpg -define histogram:unique-colors=false histogram:histogram.gif
convert histogram.gif -strip -resize 50% -separate histogram-%d.gif
Only way I know is via a pipe.
convert rose: -define histogram:unique-colors=false histogram:- | convert - -strip -resize 50% -separate histogram-%d.gif
I don't believe you need to add -strip.
Re: How to get color information
Posted: 2012-04-07T15:41:20-07:00
by fmw42
If you don't include the -resize, you can do this
convert rose: -separate -define histogram:unique-colors=false histogram:histogram-%d.gif
Re: How to get color information
Posted: 2012-04-07T16:10:53-07:00
by VanGog
Now I read about mpr but it does not work for me:
Code: Select all
convert test.jpg -define histogram:unique-colors=false +delete -write histogram:mpr:histogr mpr:histogr -strip -resize 50% -separate histogram_buffer-%d.gif
Error:
Code: Select all
convert test.jpg -define histogram:unique
-colors=false +delete -write histogram:mpr:histogram_buffer mpr:histogram_buffer
-strip -resize 50% -separate mpr:histogram_buffer-%d.gif
convert.exe: missing an image filename `mpr:histogram_buffer-%d.gif' @ error/con
vert.c/ConvertImageCommand/3016.
Re: How to get color information
Posted: 2012-04-07T17:17:43-07:00
by fmw42
Yes I had forgotten about mpr. You just have your +delete too early. You are deleting the input image before you create the mpr: image. try
convert test.jpg -define histogram:unique-colors=false -write histogram:mpr:histogr +delete mpr:histogr -strip -resize 50% -separate histogram_buffer-%d.gif
Re: How to get color information
Posted: 2012-04-07T23:40:23-07:00
by VanGog
The MPR function is awesome!
Code: Select all
convert test.jpg -fuzz 20% -fill black +opaque #1700ff -fill #1700ff -opaque #1700ff testik.jpg
I forgot I need only upper left corner and lower right corner of the blue areas. But could you get only first line of the blue and last line of the blue? The image could be two lines of pixels only. So it would be much more simple to get the information about minimum and maximum (by batch), to get and calculate four coordinates for points.
crop image borders based on color
Posted: 2012-04-08T02:15:16-07:00
by VanGog
Maybe it would be better to do it in this way:
"crop image borders based on color"
viewtopic.php?f=1&t=12066
convert <image> -trim +repage <result>
convert <image> -fuzz xx% -trim +repage <result>
I just don't understand where should I insert the color information (#1700ff):
Code: Select all
convert test.jpg -trim +repage result.jpg
convert test.jpg -fuzz 20% -trim +repage result2.jpg
To crop the image in the way that the blue will stay in image.
But the final goal is
either to print the coordinates for the corners, so is it really necessary to crop it? (Or is there any other function, that can simulate cropping around the blue border and just get the information about the corners position? I would like to crop the image, get information for corners and than I can delete this image and crop the original image.
Or to fill the image after it is cropped or generate empty image in this size and this use as mask to crop original? But still I need to print the coordinates for the batch because I need to write/save coordinates to .txt file.
What solution to choose?
Re: How to get color information
Posted: 2012-04-08T12:19:08-07:00
by fmw42
trim does not take a color value. it finds the colors from the four corners of the image.
Re: How to get color information
Posted: 2012-04-08T17:40:20-07:00
by anthony
Take the image and mask for white!
Code: Select all
convert image.jpg -fuzz 5% -fill white -opaque white -fill black +opaque white -format '%[mean]' info:
if you get a number that is not 0 (all black) you have some colors within 5% of white!
The value is the fraction of white times 2^16.
See IM Examples, Quantization, Extracting colors (in various ways)
http://www.imagemagick.org/Usage/quantize/#handling