Given a BW image with several white color regions, it seems connected-components can label regions separately.
How can I create individual region in different mask files for each connected-component regions ?
Thanks for your help.
Creating Mask files from connected-compoents
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Creating Mask files from connected-compoents
Use both -define connected-components:mean-color=true and -define connected-components:keep=list-of-ids. That will export one file for each region that you list. You have to run it once to find the regions you want and then run it again with these commands.
See https://imagemagick.org/script/connected-components.php
Please always provide your IM version and platform when asking questions, since syntax may differ.
See https://imagemagick.org/script/connected-components.php
Please always provide your IM version and platform when asking questions, since syntax may differ.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Creating Mask files from connected-compoents
If you want one image per component, you will need a shell loop after first listing the components. Within that loop, you could re-run the connected components for a single id-number. Alternatively, use the first run to create unique colours, one per component. Then loop through those colours, isolating the colour to make the mask.
The code for this will depend on your shell language, of course.
The code for this will depend on your shell language, of course.
snibgo's IM pages: im.snibgo.com