Removing background

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
Jim

Removing background

Post by Jim »

I'm sorry if this is more of an image processing question than Imagemagick, per se, but, I have a series of microscope images that have blue spots with a random off-white background. I like the blue spots and want to remove the background so that it's transparent.

The difficulty is that the blue spots are irregular and have a number of different hues. They are diffuse blue at the edges and dark blue in the middle. I haven't found any solutions online for any package. Is there some keyword I should look under?

I'm currently trying convert -fx to see if I can isolate a range of blues, but, so far, I'm not good enough with -fx or maybe I'm trying the wrong tool. Any suggestions?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Removing background

Post by fmw42 »

Jim wrote:I'm sorry if this is more of an image processing question than Imagemagick, per se, but, I have a series of microscope images that have blue spots with a random off-white background. I like the blue spots and want to remove the background so that it's transparent.

The difficulty is that the blue spots are irregular and have a number of different hues. They are diffuse blue at the edges and dark blue in the middle. I haven't found any solutions online for any package. Is there some keyword I should look under?

I'm currently trying convert -fx to see if I can isolate a range of blues, but, so far, I'm not good enough with -fx or maybe I'm trying the wrong tool. Any suggestions?
convert image.png -fuzz XX% -transparent white result.png

Change XX to some percent tolerance for determining a range of values near white to make transparent. XX=0 will make pure white transparent. XX=100 will make the whole image transparent. If you have a better estimate of the background color, substitute that value as "rgb(rr,gg,bb)" with the quotes. You can use rr,gg,bb in range 0-255 or 0-100%. If percent, then include the % symbol with each value for rr,gg,bb. Be sure your result image is png or gif or some other format that supports transparency. Input image can be any type.

see
http://www.imagemagick.org/script/comma ... s.php#fuzz
http://www.imagemagick.org/script/comma ... ransparent
http://imagemagick.org/script/color.php

P.S. You might also want to check out the ImageJ application (http://rsb.info.nih.gov/ij/), which has many plug-ins especially designed for medical applications (such as microscopy)
Last edited by fmw42 on 2008-10-06T22:14:27-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Removing background

Post by anthony »

As you describe images containing only blue and white colors (variable) I would say the easiest is to extract the blue channel, then normalize. After that you can threshold at say 50% (or some other value) to divide the image into a map of blue and white areas.

Experiment.

If you submit a small sample image we could also do some experiments for you too.

This whole process by the way is known as 'segmentation' but is an area IM lacks some direct and specific operators. That doesn't mean it can't do it, just not simply.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply