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
Check single column of pixels
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Check single column of pixels
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.
Example using the IM internal image logo: See http://www.imagemagick.org/script/forma ... tin-images
srgb(210,209,223) 0.0298383
Code: Select all
magick image -gravity north -crop 1x+0+0 +repage -scale 1x1! -format "%[pixel:u.p{0,0}] %[fx:standard_deviation]" info:
Code: Select all
magick logo: -gravity north -crop 1x+0+0 +repage -scale 1x1! -format "%[pixel:u.p{0,0}] %[fx:standard_deviation]" info:
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Check single column of pixels
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Check single column of pixels
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.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"
Re: Check single column of pixels
Is toes.png an image you test with?
I tried this:
but I got an error:
ImageMagick 7.0.7-14 Q16 x86_64 2017-12-07 <-- upgraded since first posting
MacOS 10.13.1
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"
I'm guessing the second line is the standard deviation.magick: MissingArgument `-format' at CLI arg 13 @ fatal/magick-cli.c/ProcessCommandOptions/447.
0.262759
ImageMagick 7.0.7-14 Q16 x86_64 2017-12-07 <-- upgraded since first posting
MacOS 10.13.1
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Check single column of pixels
Yes, toes.png is my usual test image.
You need "info:" at the end. Sorry, my copy-paste error.
You need "info:" at the end. Sorry, my copy-paste error.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Check single column of pixels
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: