Actual pixel value

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
mikjsmith
Posts: 8
Joined: 2016-04-02T23:46:59-07:00
Authentication code: 1151

Actual pixel value

Post by mikjsmith »

Version: ImageMagick 6.9.1-2 Q16 x86 2015-04-14

I using the following to extract a pixel value (I think this is a normalised percentage value)

convert t_mean.tif -precision 20 -format '%[pixel:p{40,30}]' info:-

Is there an easy way to get the actual pixel value itself?

thanks

mike
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Actual pixel value

Post by snibgo »

There is one value per channel. We often use a suffix ".r", ".g" or ".b". I generally use fx, and multiply by QuantumRange if I (rarely) want the actual number instead of a percentage. For example:

Code: Select all

f:\web\im>%IM%convert rose: -precision 20 -format [fx:p{40,30}.r*QuantumRange] info:

59624
snibgo's IM pages: im.snibgo.com
mikjsmith
Posts: 8
Joined: 2016-04-02T23:46:59-07:00
Authentication code: 1151

Re: Actual pixel value

Post by mikjsmith »

I tried this
convert t_mean.tif -precision 20 -format '%[pixel:p{40,30}]' info:-
srgb(3.464815393896963

which was OK, then this

convert t_mean.tif -precision 20 -format [fx:p{40,30}*r.32] info:-
convert: unable to open image `p30*r.32]': No such file or directory @ error/blob.c/OpenBlob/2702.
convert: no decode delegate for this image format `[FX' @ error/constitute.c/ReadImage/501.

have I done something stupid here?!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Actual pixel value

Post by snibgo »

[fx:p{40,30}*r.32]
What is "r.32"? Why is there no percent % symbol there?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Actual pixel value

Post by fmw42 »

[pixel:...] will give you either an srgb triplet or a color name. If you want normalize (0-1) values then use [fx:...]

Code: Select all

convert rose:[1x1+40+30] -format "%[fx:u.r],%[fx:u.g],%[fx:u.b]\n" info:
0.909804,0.211765,0.227451

or scale to range 0-255

Code: Select all

convert rose:[1x1+40+30] -format "%[fx:round(255*u.r)],%[fx:round(255*u.g)],%[fx:round(255*u.b)]\n" info:
232,54,58
Post Reply