Page 1 of 1
A detail about -format
Posted: 2009-06-16T09:17:39-07:00
by pitosalas
Hi
(Sorry that I am posting so many little questions, I hope you don't mind. I do diligently try to answer them myself before posting but your answers have been very helpful time savers!)
$ convert revers3.tif -scale 1x1 -format "%[pixel:p{0,0}.r]" info:-
outputs:
rgb(227,227,227)
Because of the .r in -format "%[pixel:p{0,0}.r" I would have expected the output to be
227
Thanks mucho!
Pito
Re: A detail about -format
Posted: 2009-06-16T10:30:31-07:00
by fmw42
use this instead
convert revers3.tif -scale 1x1! -format "%[fx:floor(255*u.r)]" info:
for example with the IM special image rose:
convert rose: -scale 1x1! -format "%[fx:floor(255*u.r)]" info:
145
Re: A detail about -format
Posted: 2009-06-16T20:07:22-07:00
by anthony
%[pixel:...] returns a color, based on the fx pixel selection.
%[fx:...] returns a single number.
Re: A detail about -format
Posted: 2009-06-17T06:26:01-07:00
by pitosalas
Follow ups:
(1) What's better (faster etc?) if I want to have a series of integers corresponding to colors:
convert rose: -scale 10x1! txt:-
or
convert rose: -scale 1x1! -format "%[fx:floor(255*u.r)]" info:-
(2) How come those two commands give different answers for red?
$ convert rose: -scale 1x1! -format "%[fx:floor(255*u.r)]" info:-
145
convert rose: -scale 1x1! txt:-
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: (146, 89, 80) #925950 rgb(146,89,80)
and (3)
How come this produces just one number and not 10:
convert rose: -scale 10x1! -format "%[fx:floor(255*u.r)]" info:-
82
Thanks!!
-- Pito
Re: A detail about -format
Posted: 2009-06-17T09:20:27-07:00
by fmw42
remove the floor() and you get a float (145.712) as u varies from 0 to 1. so you can then round, int, floor, ceil however you want (see
http://www.imagemagick.org/script/fx.php). i am not sure what method is used by txt: to get its value. I used floor, but perhaps round() would be better.
convert rose: -scale 10x1! -format "%[fx:floor(255*u.r)]" info:-
takes only one pixel (not sure which), but you can tell it which one using u.p{i,0} where i=0 to 9
Re: A detail about -format
Posted: 2009-06-17T21:51:48-07:00
by anthony
txt: just output integers occording to the current -depth. Typically defaulting to the original images
depth, unless it was transofrmed by resize, scale etc into the compile time quantium depth (typically Q16)
fx 'u' has a value from 0.0 to 1.0 so the %[fx:..] formula tries to return a integer from 0 to 255
As FX is interpreted it is slow, BUT as it is a single once off that shoud be quite quick in this case. As such I would do a test of some kind to see which is faster. I don't think it matters though as the -scale will be a lot slower than either txt:, %[fx:..]