Evaluate-sequence add - values over 255?

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
Sorbus
Posts: 3
Joined: 2018-04-21T17:47:53-07:00
Authentication code: 1152

Evaluate-sequence add - values over 255?

Post by Sorbus » 2018-04-21T18:09:53-07:00

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!

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

Re: Evaluate-sequence add - values over 255?

Post by fmw42 » 2018-04-21T18:14:15-07:00

What is your Q level of the IM compile? Note that in IM 7, convert is replaced by magick.

Code: Select all

magick -version 
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?

Sorbus
Posts: 3
Joined: 2018-04-21T17:47:53-07:00
Authentication code: 1152

Re: Evaluate-sequence add - values over 255?

Post by Sorbus » 2018-04-21T18:44:18-07:00

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

Code: Select all

-compress none
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!

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

Re: Evaluate-sequence add - values over 255?

Post by fmw42 » 2018-04-21T19:15:54-07:00

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

Sorbus
Posts: 3
Joined: 2018-04-21T17:47:53-07:00
Authentication code: 1152

Re: Evaluate-sequence add - values over 255?

Post by Sorbus » 2018-04-21T19:42:54-07:00

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 :)

Post Reply