Using connected components tool

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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using connected components tool

Post by fmw42 »

The use your area threshold. Then get the list of ids left behind that are gray(255) (using my negated mask). Then use the keep on all those ids and save to png. You will get multiple mask images for each id. Then use the mask images as I did above on the original image and you will get each leaf separately. Or just do edge processing of each mask to get the outlines.

I do not understand why you why you want id 0! I did not suggest that.

Perhaps you should explain a bit more or show me a manually created example of what you want as the end product.

As long as you have removed the stripe on the right, some maximum threshold area should remove all smaller objects as I did above. If your leaves are all about the same size, then one area threshold should work for all images. If not then you will have to stop an analyze the listing once to find the area threshold for each image and then use that in a second command to do the filtering.
tmelorc
Posts: 30
Joined: 2016-12-01T06:07:55-07:00
Authentication code: 1151

Re: Using connected components tool

Post by tmelorc »

I was thinking (probably wrong) that working with id0: only could be easier to collect only the components with leaves. But I am learning a lot now.

The final result I'd like to get is, for each image foo.jpg a sequence of images foo_{1,2,3...}.jpg one for each leaf, in white background and the leaf with solid black. Later I'll apply something to extract its contour.
The problem is that the leaves area is not so uniform. So I have to filter using some tool, maybe id or rectangle. I'm working on this.

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

Re: Using connected components tool

Post by fmw42 »

Create the filtered binary mask as before and then crop it once for each bounding box other than for id=0.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Using connected components tool

Post by anthony »

To distinguish between the leaves and other parts I would look at using morphology on the mask image.
This is actually what morphology was designed originally to do.. find objects of particular characteristics.

First I would look at closing any small 'holes' that might be in the leaves, then do something like a erode to find the larger 'leaf' objects.

See the find large circles' example (do may not need to use the conditional dilation part)
http://www.imagemagick.org/Usage/morpho ... onditional
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply