Page 1 of 1
Check single column of pixels
Posted: 2017-12-07T13:41:14-07:00
by Devpool
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
Re: Check single column of pixels
Posted: 2017-12-07T16:13:44-07:00
by fmw42
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
Re: Check single column of pixels
Posted: 2017-12-07T16:46:27-07:00
by snibgo
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"
Re: Check single column of pixels
Posted: 2017-12-07T16:48:56-07:00
by fmw42
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.
Re: Check single column of pixels
Posted: 2017-12-09T14:32:47-07:00
by Devpool
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
Re: Check single column of pixels
Posted: 2017-12-09T15:32:43-07:00
by snibgo
Yes, toes.png is my usual test image.
You need "info:" at the end. Sorry, my copy-paste error.
Re: Check single column of pixels
Posted: 2017-12-09T15:33:43-07:00
by fmw42
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: