Check single column of pixels

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
Devpool
Posts: 5
Joined: 2017-12-07T11:40:56-07:00
Authentication code: 1152

Check single column of pixels

Post by Devpool » 2017-12-07T13:41:14-07:00

I'm processing a series of images similar to book scans. Most of the time they can simply be split in two, and I've set up a bash script calling convert to do just that. However, occasionally a single image runs across the entire spread. I want to flag these for manual checking.

I'm thinking that I should check the center row of pixels, and if they're not all one color (usually black or white) set a flag. The sample script divide_vert suggests in its comment that -scale could be used to do this (at least for white backgrounds) but I'm not sure how to implement it.

I'm new to both ImageMagick and bash scripting, so any pointers would be appreciated.

Thanks!

ImageMagick 7.0.7-11 Q16 x86_64 2017-11-12
MacOS 10.13

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

Re: Check single column of pixels

Post by fmw42 » 2017-12-07T16:13:44-07:00

If you just want to get one column of pixels in the middle, you can crop one column and average down to 1 pixels using -scale to get the average color and standard_deviation. If it is one color, then the standard-deviation will be 0.

Code: Select all

magick image -gravity north -crop 1x+0+0 +repage -scale 1x1! -format "%[pixel:u.p{0,0}] %[fx:standard_deviation]" info:
Example using the IM internal image logo: See http://www.imagemagick.org/script/forma ... tin-images

Code: Select all

magick logo: -gravity north -crop 1x+0+0 +repage -scale 1x1! -format "%[pixel:u.p{0,0}] %[fx:standard_deviation]" info:
srgb(210,209,223) 0.0298383

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

Re: Check single column of pixels

Post by snibgo » 2017-12-07T16:46:27-07:00

Fred: you are finding the standard deviation after scaling to a single pixel. The SD of a single pixel is always zero. Perhaps you intended to find the SD, then scale to a single pixel, and output its colour:

Code: Select all

magick toes.png -gravity north -crop 1x+0+0 +repage -format "%[fx:standard_deviation]\n" +write info: -scale 1x1! -format "%[pixel:u.p{0,0}]\n"
snibgo's IM pages: im.snibgo.com

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

Re: Check single column of pixels

Post by fmw42 » 2017-12-07T16:48:56-07:00

snibgo wrote:
2017-12-07T16:46:27-07:00
Fred: you are finding the standard deviation after scaling to a single pixel. The SD of a single pixel is always zero. Perhaps you intended to find the SD, then scale to a single pixel, and output its colour:

Code: Select all

magick toes.png -gravity north -crop 1x+0+0 +repage -format "%[fx:standard_deviation]\n" +write info: -scale 1x1! -format "%[pixel:u.p{0,0}]\n"
Yes, you are correct. I am not sure what I was thinking. In too much hurry to get on to other things. Thanks for correcting me. Odd though that I did not get zero for the std. I think this is a bug. I will report it.

Devpool
Posts: 5
Joined: 2017-12-07T11:40:56-07:00
Authentication code: 1152

Re: Check single column of pixels

Post by Devpool » 2017-12-09T14:32:47-07:00

Is toes.png an image you test with?

I tried this:

Code: Select all

magick image02.jpeg -gravity north -crop 1x+0+0 +repage -format "%[fx:standard_deviation]\n" +write info: -scale 1x1! -format "%[pixel:u.p{0,0}]\n"
but I got an error:
magick: MissingArgument `-format' at CLI arg 13 @ fatal/magick-cli.c/ProcessCommandOptions/447.
0.262759
I'm guessing the second line is the standard deviation.

ImageMagick 7.0.7-14 Q16 x86_64 2017-12-07 <-- upgraded since first posting
MacOS 10.13.1

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

Re: Check single column of pixels

Post by snibgo » 2017-12-09T15:32:43-07:00

Yes, toes.png is my usual test image.

You need "info:" at the end. Sorry, my copy-paste error.
snibgo's IM pages: im.snibgo.com

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

Re: Check single column of pixels

Post by fmw42 » 2017-12-09T15:33:43-07:00

Snibgo left off the final "info:" at the end of the command. Try

Code: Select all

magick image02.jpeg -gravity north -crop 1x+0+0 +repage -format "%[fx:standard_deviation]\n" +write info: -scale 1x1! -format "%[pixel:u.p{0,0}]\n" info:

Post Reply