Page 1 of 1

Change background by applying clipping path

Posted: 2008-02-05T10:12:27-07:00
by sven
Hi magick,

I would like to change the background of an image by applying its clipping path. That is to say that the current image has a white background and a clipping path which describes a part of this image.
The resulting image should be the same image containing the image part with the clipping part on a blue background.

I've tried many combinations of "-clip", "-clip-path id" etc., but nothing seems to work.

Any help is appreciated!

Thanks a lot!
Sven

Re: Change background by applying clipping path

Posted: 2008-02-06T02:39:59-07:00
by masterbp
Hi Sven

I has a similar problem and solved it using something like:

Code: Select all

+clip-path #1 -fill blue -draw "color 0,0 reset"
I am no expert in ImageMagick, so this is only a qualified guess:)

Re: Change background by applying clipping path

Posted: 2008-02-06T02:46:52-07:00
by masterbp
Hi

I also have a related question which I hope anyone can help me with:

I want to give a picture a white background by using the clipping path.

Code: Select all

"c:\Program Files\ImageMagick-6.3.8-Q16\convert.exe" +clip-path #1 -fill white -draw "color 0,0 reset" 18.tif 18.jpg
This works great if i'm using a RGB image or converting from CMYK to RGB using color profiles, but in this case i only want to make the background white on a CMYK image - nothing else. Using the above command on a CMYK image gives me a black background instead of white

Any help is appreciated.

Re: Change background by applying clipping path

Posted: 2008-02-06T17:55:16-07:00
by anthony
The -draw operation and most colors handling is done in RGB space.

However I have found that many other operations also do handle things properly, but not with enough certainty to give a bug report.

For example I have found that using -opaque to replace a particular color with the current -fill color on a CMYK image often results in the color being applied as if, both color specifications were being mis-read as a CMYK color, when the color was given as a RGB color.

For example using the IM examples "colorwheel.png" image, works fine for RGB images.

Code: Select all

 convert colorwheel.png -fuzz 50% -fill red -opaque red replace_red.png
But goes bad when the image is converted to either CMY or CMYK in memory.

Code: Select all

convert colorwheel.png -colorspace CMY -fuzz 50% -fill red -opaque red -colorspace RGB replace_red_2.png
The result looks to be as if the given RGB 'red' color was being looked at as a CMYK cyan (which has the same memory bit pattern). Clearly a bug.

Actually viewing a CMY colorspace image on screen using the special "x:" output format is displays incorrectly!

However back you your problem...

I would first try to switch to using -opaque with a -fuzz factor of more than 100% (all colors, masked by clipping path) to -draw. But as you saw that will also fail, which should be reported as BUG for CMYK images.

Sorry.

Alternative...

The only other solution I can see is to use the clipping path to create a transparency mask. This could then be colorized to white, converted to CMYK and overlaid on the original image, using alpha composition.

There is always more than one way to do anything in image processing.

Re: Change background by applying clipping path

Posted: 2008-02-07T00:18:51-07:00
by masterbp
Hello anthony

Thank you for your feedback. Could you please give me an example of your alternative solution. I'm not sure i understand how this is done.

Thanks again!

Re: Change background by applying clipping path

Posted: 2008-02-07T18:14:59-07:00
by anthony
I do not have a image with a clipping path!! Making it difficult to test and debug the solution.

Re: Change background by applying clipping path

Posted: 2008-06-12T06:28:04-07:00
by Brian P
For some reason, the suggested solution:

Code: Select all

convert +clip-path #1 -fill blue -draw "color 0,0 reset" in.jpg out.jpg
only works for me on a windows machine - when I try the same command on Linux (have tried with several different versions of ImageMagick) I get all sorts of errors. Earlier versions won't accept it as a valid command, while later versions create a file named +clip-path.

What am I doing wrong?

Re: Change background by applying clipping path

Posted: 2008-06-12T16:58:50-07:00
by anthony
Start a new topic