Page 1 of 1

Histogramm from clipping path

Posted: 2011-01-20T04:07:22-07:00
by straight
Hi guys,

currently I am trying to find dominant colors in a picture. I've already seen a lot of solutions and commands here in different threads.
But before I want to generate the histogramm I choose the first clipping path in the picture (tiff image) and only want a histogramm of this area.
Unfortunatelly it wont work.
Here is the command line:

Code: Select all

convert -colors 4 -depth 8 [b]+clip-path '#1'[/b] picture.tif -format "%c" histogram:info: | sort -n -r -k 1 > "histo.txt"
The color reduction works as it should. A generated gif with:

Code: Select all

convert -colors 4 -depth 8 +clip-path '#1' picture.tif picture.gif
only has the 4 colors.

But the histogram shows >100000 lines instead of only 4.


Without clip-path '#1' I'll get a histogram with 4 line.


Workaround is to save a tmp. gif picture and then genereate the histogram.
But maybe there is a way to do that in one command. (Maybe this is a bug?)

Any suggestions?

Re: Histogramm from clipping path

Posted: 2011-01-20T11:51:26-07:00
by fmw42
perhaps you should put the input image first after convert. don't know if that will help, though.

see http://www.imagemagick.org/Usage/basics/#cmdline

what is your IM version and platform. if old perhaps upgrade

Re: Histogramm from clipping path

Posted: 2011-01-21T06:17:04-07:00
by straight
IM version is up to date. Unix OS

First here is a Tiff file with a clipping path http://www.mediafire.com/?sx6kxvbq86717gv
Image
The clipping path is around the circle. So clipped along the path should exclude the yellow color.

Now I want a histogram only of the inner of the circle:

Code: Select all

convert -clip-path '#1' picture.tif -format "%c" histogram:info: | sort -n -r -k 1 > histo.txt
convert picture.tif  -clip-path '#1' -format "%c" histogram:info: | sort -n -r -k 1 > histo.txt
lines: 850
dominant color: yellow (#FFF000)

--> obviously clipping has no effect
I don't get it :?

How can I generate a histogram over the selected path?


cheers

Re: Histogramm from clipping path

Posted: 2011-01-21T06:47:07-07:00
by magick
To see the clipping path in action, try these commands:
  • convert picture.tif -negate 1.png
    convert picture.tif -clip-path '#1' -negate 2.png
    identify -verbose 1.png 2.png
Notice the expected color differences in the results. Clipping prevents pixel updates to any pixel within the clipping path.

Re: Histogramm from clipping path

Posted: 2011-01-23T16:54:51-07:00
by anthony
In other words it only prevents updated, it does not prevent reading.

Perhaps you can negate the clipping path and use it to replace the 'unknown and unwanted area' with a known color like transparency. You can then ignore transparency in the results.

Re: Histogramm from clipping path

Posted: 2011-01-24T01:56:08-07:00
by straight
Hello magick and anthony,

thanks for your input. "it does not prevent reading"
I filled the the inverted selection of clipping path with transparent color (none) and excluded them while reading the histogram.

Code: Select all

convert -layers merge picture.tif -transparent none -colors 16 -depth 8 +clip-path '#1' -fill none -background none -draw "color 0,0 reset" -format "%c" histogram:info: | sort -n -r -k 1 | grep -v none | head -n 10 > histo.txt
Cheers :)