Page 1 of 1
Evaluate-sequence add - values over 255?
Posted: 2018-04-21T18:09:53-07:00
by Sorbus
I am adding pixel values together from multiple images, for GIS analysis, using ImageMagick 7.0.7-11. My source images are 8-bit, greyscale pngs, with black and white pixels only to be treated as 0s and 1s. I am using .pgm output.
The following code which works perfectly on 255 images or less:
Code: Select all
convert "*.png" -depth 1 -negate -evaluate-sequence add -colorspace gray out.pgm
If I have over 255 images, values over 255 appear to loop back to 0 (multiple times as I am adding 800+ images together). Can my output have pixel values over 255?
Many thanks!
Re: Evaluate-sequence add - values over 255?
Posted: 2018-04-21T18:14:15-07:00
by fmw42
What is your Q level of the IM compile? Note that in IM 7, convert is replaced by magick.
will tell you that. If Q16, then you will get 16-bit values (range 0 to 65535), unless you add -depth 8. But the issue is likely whether your output format supports 16-bits or only 8-bits. I think PGM supports larger values, but I am not sure how you tell it that? Try adding -depth 16 to your command before the output and see if that helps.
See
http://netpbm.sourceforge.net/doc/pgm.html which says it can support up to 16-bit values
Try
Code: Select all
magick "*.png" -colorspace gray -depth 1 -negate -evaluate-sequence add -depth 16 -type grayscale out.pgm
How are you determining the values in your output pgm file?
Can you post one of your input images to some free hosting service and put the URL here?
Re: Evaluate-sequence add - values over 255?
Posted: 2018-04-21T18:44:18-07:00
by Sorbus
Thank you for the speedy response!
Q level is Q16. When I use -depth 16, I get an image only made up of values of 0 and 65535.
I'm determining the output values using the GIS program, or by using
to get an ASCII .pgm instead of binary and viewing the output in a text editor.
Here is a single sample image:
https://pasteboard.co/HhIRiMn.png
Cheers!
Re: Evaluate-sequence add - values over 255?
Posted: 2018-04-21T19:15:54-07:00
by fmw42
This seems to work for me, with 3 images.
Code: Select all
magick HhIRiMn.png -duplicate 2 -colorspace gray -negate -evaluate-sequence add -evaluate divide 65535 -type grayscale -depth 16 -compress none out.pgm
and this with 300 images.
Code: Select all
magick HhIRiMn.png -duplicate 299 -colorspace gray -negate -evaluate-sequence add -evaluate divide 65535 -type grayscale -depth 16 -compress none out.pgm
Re: Evaluate-sequence add - values over 255?
Posted: 2018-04-21T19:42:54-07:00
by Sorbus
It works for me too, thank you so much! .pgm binary and .tif export work well with QGIS. I must say, this is hugely quicker than looping the execution of GDAL raster calc scripts that only allow 26 images at a time. Fantastic