Croping pictures in picture

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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

You are asking for a couple of VERY complex taskes, whcih is beyond the scope of a single question. basically people do not want to do ALL the work for you.

You first need to ask yourself. Do you plan to do this for hundereds of images?
or just one or two sets? In that later... do it by hand with a GUI photo processing problem. In the former (hundreded of images), then you need IM and figure out how to automate the process.

You however can split your problem in three seperate, but still very difficult problems, and these are what you need to work out, one step at a time.

First you have multiple images! You need to first find a way to cut out and seperate the verious parts you are interested it.

The simplist method is to 'cut' the images into parts. That is start by looking for a vertical line of the background color along whcih you can 'cut' the image into two smaller parts, then repeat with those parts.

You can then repeate this process with slanted, though straight lines.

not that this can fail if you need a crooked lines or curves to seperate the images, but that does not appear to be the can with your example.

A alturnative an more general solution can be solved by masking the image using just the background color, then using -segment (with a -verbose setting) to find the various parts, so you can seperateally mask these out from the original image.

Play with -verbose and -segment. I have not looked at this process in much detail in IM Examples, so if you do this please report your successes and failures back to me, so the results can be sared with others.

if you are unwilling, ask a seperate question on the forums for this step, either as a
'cut' solution or as a 'segment' solution.


Second. After you have the sub-images seperated the next difficult step is aligning (rotating) the images back into right allignment. That brings up the question. of finding what the 'corners' of each image is, and figuring out which way is UP!

Third. Once you have the locations of the 'corners' you can then figure out the
rotataion you need to re-align the images, assuming the images are rectangles!

This can be solved with some 'affine transformations' the solution of which is still being worked out in IM examples. That is a 3 point transformation.

However as you are dealing with a 4 point rectangle you may want to use a 4 point perspective transformation. Recent discussions may make 4 point transformations posible in IM very soon.

Basically you need to think about things and experiment with -segment to solve the first problem.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

The problem with -segment is I don't know how it is suposed to work, so have been unable to properly bug test it. But from what i read you chould be able to extract a greyscale mask of the background color, and run with through "-verbose -segment ??", then parse the verbose output to find the pictures.

The problem is I have seen no example, and my ultra quick tests have proved inconclusive.

It is a shame as it sounds like a perfect operator to split up images like this, or find other aspects of images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Hmmm... I am sorry. I made a bit of a mistake. I had assumed that segment was a spatial (space) for finding clusters of pixels. After some more careful study, I found I was wrong.

It is a color segmentation algorithim, that is used as part of IM color quantization routines.
That is it is used to reduce the number of colors in an image, NOT find spots of colors.

Arrggghhh... Sorry for misleading people.

I'll shut up now.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

The -segment option performs histogram analysis using the fuzzy C-means algorithm. We suspect Anthony is talking about a labeling algorithm. Its on our list of things to do if we ever find the time.
Post Reply