Page 1 of 1

Divide image into 4 quadrants

Posted: 2013-01-14T08:52:31-07:00
by cambob
I have a 640x480 picture that I would like to store as 4 160x120 pictures, for upper left, upper right, lower left, lower right

|---------|--------|
| | |
|------------------|
| | |
| --------|--------|

Re: Divide image into 4 quadrants

Posted: 2013-01-14T09:40:47-07:00
by Bonzo

Re: Divide image into 4 quadrants

Posted: 2013-01-14T10:38:01-07:00
by fmw42
I believe Bonzo meant (half the image size in the crop)

convert image -crop 320x240 +repage +adjoin result_%d.suffix

The +adjoin would be needed for images such as gif that would normally put them as frames/layers in the same gif rather than separate images. The +repage removes the virtual canvas.

See
http://www.imagemagick.org/Usage/crop/#crop_tile
http://www.imagemagick.org/Usage/crop/#crop_repage
http://www.fmwconcepts.com/imagemagick/ ... .php#crop2

Re: Divide image into 4 quadrants

Posted: 2013-01-14T10:47:16-07:00
by Bonzo
I believe Bonzo meant (half the image size in the crop)
You are right fmw42 :?

But looking at the original post again the OP wants the four corners not the image devided into four - 4 160x120 pictures

Re: Divide image into 4 quadrants

Posted: 2013-01-14T11:00:38-07:00
by snibgo
I'm probably totally wrong, but maybe the OP wants to chop his 640x480 image into four images, each 160x120. This would need a resize followed by crop, eg:

convert infile -resize 50% -crop 2x2@ out_%02d.jpg

Or perhaps he wants to replicate his image, like four passport photos.

Any more guesses? Does the winner get a prize?

Re: Divide image into 4 quadrants

Posted: 2013-01-14T17:59:35-07:00
by fmw42
Bonzo wrote:
I believe Bonzo meant (half the image size in the crop)
You are right fmw42 :?

But looking at the original post again the OP wants the four corners not the image devided into four - 4 160x120 pictures
Sorry, I could not make out what he wanted and just took a guess at the easiest thing.

Re: Divide image into 4 quadrants

Posted: 2013-01-14T23:56:20-07:00
by anthony
It could mean the 4 quadrants around some point...
http://www.imagemagick.org/Usage/crop/#crop_quad

Basically there are a number of ways the request could be answered, and achieved.
There are lots of ways to skin a cat, and what method you use depends
on what you want that skin for, and how messy you like the results!

Re: Divide image into 4 quadrants

Posted: 2013-01-15T08:32:52-07:00
by cambob
Ok, I'll take the prize 4 images 320,240. just a little mixup on my part

Re: Divide image into 4 quadrants

Posted: 2013-01-15T18:04:59-07:00
by anthony
If you just want the images in the corners (and ignore the rest) you will need to crop them individually.
For example.

convert image.png \
\( -clone 0 -crop 160x120+0+0 +repage \)
\( -clone 0 -gravity NorthEast -crop 160x120+0+0 +repage \)
\( -clone 0 -gravity SouthEast -crop 160x120+0+0 +repage \)
\( -clone 0 -gravity SouthWest -crop 160x120+0+0 +repage \)
-delete 0 image_save_%d.png

That will save four images extracted from just the corners (deleting the original only at the end). In actual fact this is rather like what tile or equal area cropping does internally.

As usual are at other ways to do this too, for example using: -chop, tile cropping, and even equal area cropping with ignored overlap, or quadrent crop, with sub-cropping. Really it depends on what you want and what other things you may need from the source image.