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?".

How to split image to 2 parts?

Postby swistaczek » 2009-06-01T02:14:08+00:00

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
swistaczek
 

Re: How to split image to 2 parts?

Postby Bonzo » 2009-06-01T02:38:43+00:00

Bonzo
 
Posts: 2208
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: How to split image to 2 parts?

Postby swistaczek » 2009-06-01T04:12:36+00:00

The problem is that the image is diffrent size each time. I want split images by founding white space beetwen objects.
swistaczek
 

Re: How to split image to 2 parts?

Postby Bonzo » 2009-06-01T04:53:25+00:00

Did you look at the second link?
Bonzo
 
Posts: 2208
Joined: 2006-05-20T08:08:19+00:00
Location: Cambridge, England

Re: How to split image to 2 parts?

Postby anthony » 2009-06-01T17:57:44+00:00

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
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8731
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: How to split image to 2 parts?

Postby swistaczek » 2009-06-02T01:43:34+00:00

Hey,
I tried to use this script, but script returns me only 2 images of this:
Image
containing 1px white color, and rest.
swistaczek
 

Re: How to split image to 2 parts?

Postby anthony » 2009-06-02T05:59:36+00:00

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
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8731
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: How to split image to 2 parts?

Postby swistaczek » 2009-06-03T04:14:09+00:00

Thanks!
Code: Select all
convert input.jpeg -rotate 90 miff:- | ./divide_vert.sh -i - miff:- |convert - -rotate -90 +repage image_%d.jpeg
works great!
swistaczek
 

Re: How to split image to 2 parts?

Postby Geremia » 2012-01-24T15:57:32+00:00

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%.
Geremia
 
Posts: 2
Joined: 2011-07-04T18:35:42+00:00

Re: How to split image to 2 parts?

Postby fmw42 » 2012-01-24T16:29:32+00:00

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.
User avatar
fmw42
 
Posts: 14869
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA


Return to Users

Who is online

Users browsing this forum: Baidu [Spider], dlemstra, Google [Bot], Google Adsense [Bot], pietrob71 and 27 guests