Produce 'black' and 'other than black' images ?

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
rshea
Posts: 11
Joined: 2009-11-30T02:06:33-07:00
Authentication code: 8675309

Produce 'black' and 'other than black' images ?

Post by rshea »

Hi - I've got an TIF which contains a line graph. The axes/labels etc are all RGB(0,0,0) the line on the graph is rgb(143,174,214). Everything else is white.

I'd like to produce two images - one which contains only the line on the axes/labels and one which contains everything else.

I've done this :

Code: Select all

convert f1.tiff -fill white -opaque black f2.tiff
and that gives me a f2.tiff with just the line from the chart in it on a white background.

I now want to use that image to produce an image that contains only the axes/labels.
I've tried this :

Code: Select all

convert f1.tiff f2.tiff -compose minus f3.tiff 
but I get a copy of f1.tiff in f3.tiff (albeit one which occupies more space on disk).
And I've tried this :

Code: Select all

convert f2.tiff f1.tiff -compose minus f3.tiff 
but I get a copy of f2.tiff.

Sure I'm doing something simple wrong - anyone able to tell me what ?
rshea
Posts: 11
Joined: 2009-11-30T02:06:33-07:00
Authentication code: 8675309

Re: Produce 'black' and 'other than black' images ?

Post by rshea »

I just want to clarify something about this question. When I say
I'd like to produce two images - one which contains only the line on the axes/labels and one which contains everything else.
I really mean I want one image which contains everything in the original image that is rgb(0,0,0) and one image that contains everything else from the original image.

Thanks.

R.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Produce 'black' and 'other than black' images ?

Post by fmw42 »

try

convert f1.tiff \( -clone 0 -fill white +opaque black -write f3.tiff +delete \) -fill white -opaque black f2.tiff

or

convert f1.tiff \( -clone 0 -threshold 0 -write f3.tiff +delete \) -fill white -opaque black f2.tiff
rshea
Posts: 11
Joined: 2009-11-30T02:06:33-07:00
Authentication code: 8675309

Re: Produce 'black' and 'other than black' images ?

Post by rshea »

Hi fmw42 - Thanks very much for your reply, I appreciate it.

The second of your two options works beautifully. I just adjusted it slightly as I'm working on a 16bit version of IM (installed in rather a piecemeal way on Windows Vista) and I've found in the past that without -depth 8 the output of convert can be strange so this is what I used .

Code: Select all

convert.exe f1.tiff ( -depth 8 -clone 0 -threshold 0 -write f3.tiff +delete ) -fill white -opaque black f2.tiff
For some reason when I tried the first option I got an error message. Specfically I tried

Code: Select all

convert.exe f1.tiff ( -clone 0 -fill white +opaque black -write f3.tiff +delete ) -fill white -opaque black f2.tiff
I got an error message

Code: Select all

convert.exe: unable to open image `black': No such file or directory.
I couldn't really see what that was getting at (wondered if it was the slightly dodgy way I have IM installed on this machine) and so decided to try the second option you provided and as I say it worked fine.

While I'm here I'd like you to thank you for your collection of IM scripts at http://www.fmwconcepts.com/imagemagick/index.php - I've enjoyed browsing them.

Thanks again.

Richard.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Produce 'black' and 'other than black' images ?

Post by fmw42 »

I got an error message

CODE: SELECT ALL
convert.exe: unable to open image `black': No such file or directory.
This usually occurs when you are using a very old version of IM that does not support +opaque. What version are you on? IM is at 6.6.0-5. Perhaps you should consider upgrading to get all the enhancements and bug fixes that have taken place over time.
Post Reply