Page 1 of 1

bakground debris

Posted: 2013-08-06T03:51:16-07:00
by Nik
Hi all,

I have managed to create a bitmap mask but it still has some areas of the background that have debris. The simplest way I can describe what I would like to do is in Photoshop terms. I would like to select the white area of the image, based upon the centre of the image. Then I inverse the selection and fill if with black.

If anybody can offer an suggestions of how I do this using imagmagick I would appreciate it.

Thanks,
Nik

Re: bakground debris

Posted: 2013-08-06T04:10:58-07:00
by GreenKoopa
Nik wrote: I would like to select the white area of the image, based upon the centre of the image.
Pure white or near white? A connected area that includes the center? Like a fuzzy select wand tool? Seeing the image may help.

Re: bakground debris

Posted: 2013-08-06T04:24:07-07:00
by Nik
The image has a pure white fill and pure black background. He's a link to the image:

http://s22.postimg.org/4lhf6h0wx/new_background_2.png

It's the debris in the black background I want to get rid of.

Hope this helps

Thanks for looking,
Nik

Re: bakground debris

Posted: 2013-08-06T04:46:18-07:00
by GreenKoopa
Thanks, seeing helps. Your image is not pure black and white, so I included a fuzz factor. One solution:

Code: Select all

convert mask.png +level 0,98% -fill white -fuzz 50% -floodfill +640+960 white -threshold 99% mask_new.png
If you are using a Windows batch file, don't forget to escape the %s (otherwise it will fail without error).

Re: bakground debris

Posted: 2013-08-06T04:58:22-07:00
by Nik
Hi GreenKoopa,

That works perfectly!!!

Could you please explain the process?

Many, Many thanks,
Nik

Re: bakground debris

Posted: 2013-08-06T05:24:15-07:00
by GreenKoopa
In IM selection is done by creating masks. So a fuzzy select / magic wand tool is really the same as a bucket / flood fill tool. IM has two fill tools: -floodfill and -draw floodfill.

+level 0,98%
Makes an image slightly darker. Now 98% gray is the closest color to white.

-fill white
This sets the color to fill with by -floodfill.

-fuzz 50%
Another setting for -floodfill. Play with this and watch the edges of the bottle. Photoshop must have a similar setting for it's selection tool.

-floodfill +640+960 white
Starts filling at +640+960 anything within -fuzz of white. I don't know of a way to specify "center" (unless you want to try the new IM 7.0 alpha).

Now the lightest part of the image is 98%, except where we filled with 100% pure white.

-threshold 99%
Colors below 99% turn black, above turn white. This leaves us with the fill area white and everything else black. This has destroyed your soft edges, which may or may not be what you wanted. They could be recovered if needed.

Re: bakground debris

Posted: 2013-08-06T12:32:56-07:00
by Nik
Great explanation, many thanks.

Just thought I would share how I find the centre and orientation of an image:

identifyResults=$(/opt/local/bin/identify -format "%w %h %[exif:orientation]" $image1)
width_centre=$(echo $identifyResults | cut -d ' ' -f1 | awk '{print $1/2}');
height_centre=$(echo $identifyResults | cut -d ' ' -f2 | awk '{print $1/2}');
orient=$(echo $identifyResults | cut -d ' ' -f3);

once I've got the centre then I pass it like this:

/opt/local/bin/convert $image1 +level 0,98% -fill white -fuzz 50% -floodfill +$width_centre+$height_centre white -threshold 99% new_mask.png

I really appreciate you taking the time to answer my question.

Thanks,
Nik