Divide image into 4 quadrants

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
cambob
Posts: 11
Joined: 2013-01-12T11:32:05-07:00
Authentication code: 6789

Divide image into 4 quadrants

Post 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

|---------|--------|
| | |
|------------------|
| | |
| --------|--------|
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Divide image into 4 quadrants

Post by Bonzo »

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

Re: Divide image into 4 quadrants

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Divide image into 4 quadrants

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Divide image into 4 quadrants

Post 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?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Divide image into 4 quadrants

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

Re: Divide image into 4 quadrants

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cambob
Posts: 11
Joined: 2013-01-12T11:32:05-07:00
Authentication code: 6789

Re: Divide image into 4 quadrants

Post by cambob »

Ok, I'll take the prize 4 images 320,240. just a little mixup on my part
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Divide image into 4 quadrants

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply