Cutting out a part of an Image using Magick++

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
billabonk

Cutting out a part of an Image using Magick++

Post by billabonk »

Hi guys. I'm pretty new to Magick++.
I have this Image: http://img517.imageshack.us/img517/3784/yoyoyo.jpg
I want to create a mask out of the colorful part in the middle.
So basically what I need to do is:
Make the colorful thingy in the middle white and make the black and grey areas on the outside complete black.
But how? I have no idea. Please help me!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cutting out a part of an Image using Magick++

Post by fmw42 »

Unfortunately, your background black is not pure black. So my attempts to use -threshold failed to isolate the center region without "eating away" some of it. I tried to use the red channel and hue channel as well with no good results.

convert yoyoyo.jpg -channel red -separate +channel -threshold XX% yoyoyo_0_c2.gif

where you can vary XX% around 1-10%

see -threshold http://www.imagemagick.org/script/comma ... #threshold

This also eats away at the center

convert yoyoyo.jpg -channel red -separate +channel +dither -colors 2 -threshold 10% yoyoyo_0_c2.gif


Perhaps others might have some better ideas.

The only thing to do is use some thing like GIMP or Photoshop to manually draw a mask around the center area and create a b/w binary mask
Last edited by fmw42 on 2009-10-16T09:54:41-07:00, edited 1 time in total.
billabonk

Re: Cutting out a part of an Image using Magick++

Post by billabonk »

Alright. So the starting image wasn't good in the first place.
Well thing is I actually created it myself.
I had these 2 Images:
http://img260.imageshack.us/img260/9058/50033144.jpg
http://img378.imageshack.us/img378/8666/smalljg.jpg

As you can see the HQ Version has some kind of error in it. I want to create a mask of it using the small version.
I resized the small Image to the size of the HQ Version using Image.zoom() and then used Image.composite() with MinusCompositeOp. Is there a better way to create a mask? Im still enw to this stuff :/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cutting out a part of an Image using Magick++

Post by fmw42 »

the problem is your first (larger image) is not totally black inside the center area. to be honest, I am still not sure what you are trying to do. If you created the first image with the darker inside, then how did you get the smooth outline for the shape? Did you draw that in some GUI image processing tool such as GIMP or Photoshop? If so, then you should be able to create a binary mask at the same time in that tool. What is your final objective and what are the functional steps you think you need to get there?

You either need to find some segmentation or thresholding technique that will separate the shape from the background or trace it manually in some GUI application and fill the inside with white and the outside with black.
Post Reply