-fx return raw values?

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
TedBaker
Posts: 50
Joined: 2017-10-10T14:14:55-07:00
Authentication code: 1151

-fx return raw values?

Post by TedBaker »

Is there a simple way to use the -fx command with raw values rather than normalised, i.e. 0-1

for example

convert rose: -fx 'debug(u)' null

I would like to work with the raw 16bit value stored, or even its 8-bit equivalent, if possible.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -fx return raw values?

Post by fmw42 »

try

Code: Select all

convert rose: txt:
or

Code: Select all

convert rose: -fx 'debug(65535*u)' null:
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -fx return raw values?

Post by snibgo »

The constant Fred give, 65535, is correct for Q16 IM. For portability across any Q-number IM, use QuantumRange.
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: -fx return raw values?

Post by fmw42 »

snibgo wrote: 2018-02-23T15:30:17-07:00 The constant Fred give, 65535, is correct for Q16 IM. For portability across any Q-number IM, use QuantumRange.
Good point.

But if he is on Q16 and wants 8-bit values, then it would need to be

Code: Select all

convert rose: -fx 'debug(255*u)' null:
The txt: output provides 8-bit values in the srgb(...) values and quantum range in the raw values right after the coordinates.
TedBaker
Posts: 50
Joined: 2017-10-10T14:14:55-07:00
Authentication code: 1151

Re: -fx return raw values?

Post by TedBaker »

Thanks for those, was just wondering if there was switch as it can be a bit laborious, with long fx statements.

With the precision of the value give by of u, will i get the exact value when I do 65535*u?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -fx return raw values?

Post by fmw42 »

u is a float in the range of 0 to 1. So multiplying by 65535 would produce a floating point value. I do not know if it is being rounded or truncated to an integer. But I suspect that the IM developers have done whatever is correct to make it properly an integer.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -fx return raw values?

Post by snibgo »

fmw42 wrote:I do not know if it is being rounded or truncated to an integer. But I suspect that the IM developers have done whatever is correct to make it properly an integer.
It isn't deliberately rounded or truncated to an integer, but the current "-precision" setting may round it to an integer. The output may not be an integer, eg it could be "29183.999999999996". If an integer is required, a common technique is to add 0.5 and take the floor of the result, eg

Code: Select all

convert toes.png -precision 19 -fx debug(floor(QuantumRange*u+0.5)) null:
snibgo's IM pages: im.snibgo.com
Post Reply