Splitting image using vertical line

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
bulgaria_1
Posts: 4
Joined: 2018-12-28T04:21:31-07:00
Authentication code: 1152

Splitting image using vertical line

Post by bulgaria_1 »

Hi all i am a new member of this forum. I have a question is it possible to divide one image to 4 images using only the vertical lines in the image? What i want to do is first split this image into 2 images and left with 2 images for page 4 and page 5 and then split on more time each images of there vertical line and left with a total of 4 images. Is this possible and how is it achievable? Thanks!

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Splitting image using vertical line

Post by snibgo »

What version of IM, on what platform?

Yes, it is possible, but not simple.

The first step is to find the central "vertical" line. The difficulty is that it isn't vertical. You might first crop to the central portion of the image ...

Code: Select all

magick KR8E04s.png -gravity Center -crop 50%x50%+0+0 +repage x.png
... and crop that to the top few lines and bottom few lines, and find the thick black portions (eg by blurring, then finding the darkest pixels).

That gives the position and angle of the central line. Rotate the image to make the line exactly vertical, and crop at that position. That gives two images, one per page.

I don't understand how you want to get four images.
snibgo's IM pages: im.snibgo.com
bulgaria_1
Posts: 4
Joined: 2018-12-28T04:21:31-07:00
Authentication code: 1152

Re: Splitting image using vertical line

Post by bulgaria_1 »

sorry i didnt say i am using ImageMagick 6.9.10-8 Q16 x86_64 20180723 on Ubuntu 18.10

and how can i rotate the image so the line can be exactly vertical?

I want to get 4 images out of this image because each page (4 and 5 in this case) have vertical lines on there own between the text as u can see so i want to cut 3 vertical lines and get 4 images
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Splitting image using vertical line

Post by snibgo »

Ah, yes, each page has a thin "vertical" line.

For individual options, see www.imagemagick.org/script/command-line-options.php

Sorry, I don't have time to write a complete script for you. And it would probably need adjusting for other sample inputs.
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: Splitting image using vertical line

Post by fmw42 »

As part of your processing, you can average the image down to one row. Then find the darkest region in the middle of the row. That X coordinate should be where you can split the original image in half. Once you have those two halves, you can try to use my textdeskew bash unix shell script to rotate each half so that the rows of text are horizontal. See my scripts at my link below.
bulgaria_1
Posts: 4
Joined: 2018-12-28T04:21:31-07:00
Authentication code: 1152

Re: Splitting image using vertical line

Post by bulgaria_1 »

Maybe a stupid question, but how do you execute this file? I tried to make it executable with
chmod +x textdeskew
and then run it like that
./textdeskew inoputFile.png outputfile.png
, but it is loading and nothing is happening i awaited for 15 mins and nothing.... what I am doing wrong?
snibgo wrote: 2018-12-28T05:09:55-07:00 Ah, yes, each page has a thin "vertical" line.

For individual options, see www.imagemagick.org/script/command-line-options.php

Sorry, I don't have time to write a complete script for you. And it would probably need adjusting for other sample inputs.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Splitting image using vertical line

Post by fmw42 »

Code: Select all

chmod u+x textdeskew
Try

Code: Select all

bash ./textdeskew inoputFile.png outputfile.png
Did you follow the Pointers For Use at http://www.fmwconcepts.com/imagemagick/index.php

What is your platform? My scripts only run on Unix-like systems.

How big is your image? Did you split it in two parts first?

Post the image you are trying to use and I can test to see if there is an issue with the script.

If the image is very large, it might take a while to process.
bulgaria_1
Posts: 4
Joined: 2018-12-28T04:21:31-07:00
Authentication code: 1152

Re: Splitting image using vertical line

Post by bulgaria_1 »

I manage to run the script (the problem was on my end, something was happening with my HDD i dont know what but it was running very slow, but thats other topic), but now i get those errors:

Code: Select all

./multicrop: line 618: unrotate: command not found
convert-im6.q16: unable to open image `./multicrop_5_2290.miff': No such file or directory @ error/blob.c/OpenBlob/2871.
convert-im6.q16: no images defined `Desktop/2/demo-003.jpg' @ error/convert.c/ConvertImageCommand/3258.
i ran this script
./multicrop -f 10 -u 2 Desktop/2/SKMBT_C22017091416590.jpg Desktop/2/demo.jpg
Update: when expected the code i think there is something wrong on like 618: unrotate -C "$bcolor" -f ${fuzzval}% - $tmpA5 as there is no such a command unrotate in linux and i guess it is a part from convert, but i tried convert -u didint work i also tried convert -unrotate didnt work as well i also tried $unroate, but that didnt work as well. what i should do?

Update2: i tried to place this one on the first two lines, but that did not work as well:

Code: Select all

 imdir="/usr/bin"
 PATH="${imdir}:${PATH}"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Splitting image using vertical line

Post by fmw42 »

multicrop uses my script unrotated. Read the documentation.
# REQUIREMENTS:
# If using unrotate method 2, then my script, unrotate, is required.
# If using innertrim, then my script, autotrim is required.
You may prefer to use my script multicrop2. It performs better. But it has the same requirements.
Post Reply