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
bakground debris
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: bakground debris
Pure white or near white? A connected area that includes the center? Like a fuzzy select wand tool? Seeing the image may help.Nik wrote: I would like to select the white area of the image, based upon the centre of the image.
Re: bakground debris
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
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
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: bakground debris
Thanks, seeing helps. Your image is not pure black and white, so I included a fuzz factor. One solution:
If you are using a Windows batch file, don't forget to escape the %s (otherwise it will fail without error).
Code: Select all
convert mask.png +level 0,98% -fill white -fuzz 50% -floodfill +640+960 white -threshold 99% mask_new.png
Re: bakground debris
Hi GreenKoopa,
That works perfectly!!!
Could you please explain the process?
Many, Many thanks,
Nik
That works perfectly!!!
Could you please explain the process?
Many, Many thanks,
Nik
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: bakground debris
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.
+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
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
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