Detect separating vertical white line in the middle

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
mcbitman
Posts: 2
Joined: 2019-05-02T05:03:51-07:00
Authentication code: 1152

Detect separating vertical white line in the middle

Post by mcbitman »

Hi all,

I'm on version 6.8.9-9 Q16 x86_64 on Ubuntu.
I have a lot of images which are divided into two or more images, separated by a white column in the middle.

http://jessytucky.nl/imagick/img.jpg

Also, all these images have a white border.

Is there a way to detect a splitting white column in the middle (no matter the width of the column)?
Or, say, print a number of vertical white columns to the command line?

I just need to know if there's a column in the middle. I don't need to do any adjustments.

In this case it would be 3, because the left and right border would also account for a vertical white column.

Any help would be greatly appreciated.

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

Re: Detect separating vertical white line in the middle

Post by fmw42 »

You can trim the image, threshold it to binary, scale the image to one row, then search for any white pixels.

Code: Select all

convert img.jpg -auto-level -negate -threshold 15% -negate -trim +repage -scale x1! -type bilevel txt: | grep "gray(0)" | head -n 1
If this returns nothing, then there is no white area in the middle; otherwise if a spacer, it will show something like:

Code: Select all

0,0: (0,0,0)  #000000  gray(0)
mcbitman
Posts: 2
Joined: 2019-05-02T05:03:51-07:00
Authentication code: 1152

Re: Detect separating vertical white line in the middle

Post by mcbitman »

Hi Fred,

Thanks a lot! You definitely helped me on my way.
I ended up cropping a column with a width of 2 px from the center of the image, turned all pixels into black and white with a little fuzz and checked with grep if black = 0. If so, it is a white spacer. Works like a charm!

Code: Select all

convert img.jpg  -gravity Center -crop 2x+0+0 +repage -fuzz 5% -fill White -opaque White txt: | grep -c "black"
Post Reply