How to split image to 2 parts?

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
swistaczek

How to split image to 2 parts?

Post by swistaczek »

Heloo guys,
I have this picutre
Image
I want split it to 2 parts like this:
Image
oraz
Image
Anyone can give me any hints how should I do it?

Thanks in advantage,
Ernest
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to split image to 2 parts?

Post by Bonzo »

swistaczek

Re: How to split image to 2 parts?

Post by swistaczek »

The problem is that the image is diffrent size each time. I want split images by founding white space beetwen objects.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to split image to 2 parts?

Post by Bonzo »

Did you look at the second link?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to split image to 2 parts?

Post by anthony »

Okay if the images remain about the same size and you just want to divide them down the middel use

-crop 50%x100% +repage

A better method is being looked at.


If as you say you wnt to divide the image by looking for columns of a single color, I suggest you look at the script http://www.imagemagick.org/Usage/scripts/divide_vert

The script is writte to divide the image based on rows of constant color, but can be easilly modified to do it by columns instead (or rotate the image 90 degrees ;-) )

It will seperate the image into either 5 images end_white, first_part, middle_white, second_part, and end_white, BUT a flag can be given to ask it to just not output the areas of constant color, giving you just two images.

You could also modify the script (mail me your changes) to locate the middle section as well.


This is actually known as a segmentation issue. As such by converting your image into a mask of background and non-background areas you could also divide the image using the script
http://www.imagemagick.org/Usage/scripts/segment_image

When you have separated the mask areas, you can use them to mask the original image into separate parts.

This however should not be used directly as it will also separate the red 'spot' from the black area, unless the script is modified to only look for non-white pixels segments.

I would love to see both of these scripts converted into a various segmentation methods built into the IM library itself.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
swistaczek

Re: How to split image to 2 parts?

Post by swistaczek »

Hey,
I tried to use this script, but script returns me only 2 images of this:
Image
containing 1px white color, and rest.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to split image to 2 parts?

Post by anthony »

The script is an example which divides vertically!!!!

It will need to be modified to do horizontal division

Or rotate the images before and afterward.
As the script is pipeline compatible that is straightforward

convert input.png -rotate 90 miff:- | divide_vert -i - miff:- | convert - -rotate -90 +repage image_%d.png

The -i says to not output 'blank' image segments. In other words

However the image is JPEG. which means it does not have nice perfect colors, BUT it still worked producing two images!!!

For other JPEG images, we may need to improve the results by converting the image into a mask for separation, and then extracting the masked elements.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
swistaczek

Re: How to split image to 2 parts?

Post by swistaczek »

Thanks!

Code: Select all

convert input.jpeg -rotate 90 miff:- | ./divide_vert.sh -i - miff:- |convert - -rotate -90 +repage image_%d.jpeg
works great!
Geremia
Posts: 2
Joined: 2011-07-04T18:35:42-07:00
Authentication code: 8675308

Re: How to split image to 2 parts?

Post by Geremia »

Why not just do:

Code: Select all

convert -crop 50%x100% +repage input_image out%d_image
? It takes input_image and splits it vertically in half, forming out1_image and out2_image of the left and right halves. To split horizontally in half, just change 50%x100% to 100%x50%.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to split image to 2 parts?

Post by fmw42 »

If on Linux/Mac or Windows with cygwin, see my script multicrop at the link below. It is hard to know what you want since your links to your images are broken. Can you fix them, please.
Post Reply