Detecting multiple images in one image file

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: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detecting multiple images in one image file

Post by fmw42 »

The listing from connected components when you use verbose=true in the define will show all the bounding boxes. So you just need to parse the output to get them. Once you have them, you can use -crop with those bounding boxes to extract each image one at a time. You will have to script these parts.

dcotto
Posts: 15
Joined: 2019-09-24T15:24:28-07:00
Authentication code: 1152

Re: Detecting multiple images in one image file

Post by dcotto »

Hey it works great!
the only issue im having is that the images arent cropping to exactly the same in the master sheet. For instance ill have 2 or more images in the one master sheet ...200x300, 425 x 500 .. .

im using the command below:
convert niceoutput-chopped.png -define connected-components:area-threshold=410 -define connected-components:verbose=true -connected-components 4 objects.png

With the command you gave me it works great but theres only small pixel differences after i use the command above. ill get 201x302, 426x502.
I guess the settings in -define connected-components:area-threshold=410 and -connected-components 4 may need to be configured. but not sure if the issue could be in the other command... mind you that i have about 2px black border around all images in my master sheet..not sure if that 2px black border is interfereing with the black background with the command you gave me last

Is there anyway to force it to be 100% of the exact everytime
i need to make sure the size is exactly the same size

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detecting multiple images in one image file

Post by fmw42 »

If there is noise in your image or other data, then the regions may touch and include other things than your exact images and so be larger. Did you threshold or flood fill first? Did you try changing the area-threshold? Use as large a value as you can such that it is smaller than the area of your smallest image. You can try removing noise before flood filling also.

dcotto
Posts: 15
Joined: 2019-09-24T15:24:28-07:00
Authentication code: 1152

Re: Detecting multiple images in one image file

Post by dcotto »

Yes one great thing that helped was increasing the fuzz to 10%. that seems to work well.
Thank you again for all your help.

its hard to understand imagemagick. I really wish there was a more thorough book out there thats up to date. ill have to go through documenation for now.

Do you know of any good books or tutorials out there that explain the process of a image file.. for instance i know photoshop and i know channels, Alpha, Green, Blue, Red. I want to know the autonomy of an image and its data and what it contains pertaining to how imagemagick works with those image files would you be able to know where i can begin my journey?


Locked