Histogramm from clipping path

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
straight
Posts: 6
Joined: 2011-01-20T03:58:42-07:00
Authentication code: 8675308

Histogramm from clipping path

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Histogramm from clipping path

Post 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
straight
Posts: 6
Joined: 2011-01-20T03:58:42-07:00
Authentication code: 8675308

Re: Histogramm from clipping path

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Histogramm from clipping path

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Histogramm from clipping path

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
straight
Posts: 6
Joined: 2011-01-20T03:58:42-07:00
Authentication code: 8675308

Re: Histogramm from clipping path

Post 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 :)
Post Reply