scaling on black and white images

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
perlwle
Posts: 2
Joined: 2014-10-21T03:18:31-07:00
Authentication code: 6789

scaling on black and white images

Post by perlwle »

a quick background of my problem: I am trying to separating lines with text from many black and white images with different dimensions.

In IM's divide_vert script, There is a comment:

# SPEEDUP
# If your input image uses a white background one way of speeding up this
# process is to simply compress (-scale) the image directory down to a
# single column. Any pixel that remains white will then represent a blank
# row of pixels. That would be a major speed increase, but only for
# images with a pure-white (or pure-black) background.

http://www.imagemagick.org/Usage/scripts/divide_vert

Can someone explain why and how the speedup realized? How can I use it?

I have tried -scale and -resize with same percentage and they seems to generate same image.

convert bw.bmp -scale '50%' bw_scaled.bmp

bw_scaled.bmp BMP 384x288 384x288+0+0 8-bit sRGB 332KB 0.000u 0:00.000
perlwle
Posts: 2
Joined: 2014-10-21T03:18:31-07:00
Authentication code: 6789

Re: scaling on black and white images

Post by perlwle »

after reread it few times, I think it is related to average color. but I am still not sure about the 'down to a single column' in the comment.

we can use "-scale" to reduce an image to a single pixel to get the average color. however, to separate lines, one needs to crop each row and average this rows. At least that's my understanding. so that involves:

1. crop each row
2. scale each row to 1 pixel
3. if average color is black(assume white background), then it's a content line.
4. repeat 1-3.
5. at this point, we get a list of coordinates of the content lines.

Did I get it right?

Is that the correct way to separate lines from image?
Post Reply