Using -format to get and/or work on a sequence 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
pitosalas

Using -format to get and/or work on a sequence of pixels?

Post by pitosalas »

Lets say I have a 1x100 pixel image called scanline.tif

I would like to use a convert -format ... form to output (to stdout) a list of the pixels (in any form -- what I need is the coordinate and the red color value, but I can parse that out myself.)

I played with a lot of the options (-format as well as the -fx stuff) and I can't see how to do it.

I see that I can convert the whole thing to a text format but then a file is written which I would prefer not.

Thanks!

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

Re: Using -format to get and/or work on a sequence of pixels?

Post by fmw42 »

First 10 red pixels in rose: image (values between 0 and 1).

convert rose:[10x1+0+0] -channel red -separate -fx "debug(u)" null:
ROSE[0,0].red: u=0.188235
ROSE[1,0].red: u=0.196078
ROSE[2,0].red: u=0.211765
ROSE[3,0].red: u=0.219608
ROSE[4,0].red: u=0.227451
ROSE[5,0].red: u=0.223529
ROSE[6,0].red: u=0.219608
ROSE[7,0].red: u=0.223529
ROSE[8,0].red: u=0.219608
ROSE[9,0].red: u=0.219608


see fx debugging at http://www.imagemagick.org/Usage/transform/#fx_escapes
pitosalas

Re: Using -format to get and/or work on a sequence of pixels?

Post by pitosalas »

Thanks!!

By the way, although the doc says so, it appears to me that mogrify doesn't accept -fx:

$ mogrify slither.tif -channel red -separate -fx "debug(u)"
mogrify: unrecognized option `-fx' @ mogrify.c/MogrifyImageCommand/4563.

(one of many variations I tried.)

Am I missing it again?

Pito
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Using -format to get and/or work on a sequence of pixels?

Post by anthony »

The easiest way is txt:

See Im Examples, Files, Special Formats, Txt
txt http://www.imagemagick.org/Usage/files/#txt


As -fx is a list operator, in that it will replace ALL the images in the current image list with the one resulting image. "mogrify" does not accept a list operator by its defination as it only deals with ONE image at a time.

You can use txt: though...
mogrify -format txt images....

That will create a Enumerated Pixel Image Text File (.txt) for every image given.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply