Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I subtract pixels from Gaussian, divide by Gaussian, and normalize in imagemagick

I know exactly what I want to do, and could do it with python, scipy, and PIL. I want to use imagemagick, since it is designed specifically for these actions.

  1. T is highest legal intensity (0, of course is lowest)
  2. Input image into temporary MPC named I
  3. Gaussian blur I and store into temporary MPC named G
  4. Subtract and divide D = (I - G) / G
  5. Get maximum M = max (T * abs(D))
  6. Offset, normalize, and scale O = T * (D + M) / (2 * M)
  7. Output O into file name output.png

I can't figure out how to do this from the online documentation. Imagemagick documentation vocabulary seems to be for image manipulation professionals and it is beyond my understanding.

like image 203
jlettvin Avatar asked Dec 31 '25 19:12

jlettvin


1 Answers

I have tried to reproduce your commands in Imagemagick, but I am not sure of the result or about whether T and M should be in range 0 to 1 or 0 to Quantumrange (0 to 65535 for Q16 HDRI IM compile). I tested on the Imagemagick logo: image using Imagemagick 7.0.7.21 Q16 HDRI.

enter image description here

T="65000"
sigma=5
magick logo: I.mpc
magick I.mpc -blur 0x$sigma G.mpc
magick I.mpc G.mpc +swap -compose minus -composite G.mpc +swap -compose divide -composite D.mpc
M=`magick D.mpc D.mpc -compose multiply -composite -evaluate pow 0.5 -evaluate multiply $T -format "%[fx:maxima]" info:`
M2=`magick xc: -format "%[fx:2*$M]" info:`
magick D.mpc -evaluate add $M -evaluate divide $M2 -evaluate multiply $T output.png

Line 1: Set T=65000 (range 0 to 65355)
Line 2: Set gaussian blur sigma to 5
Line 3: Read the input into I.mpc
Line 4: Apply gaussian blur to I.mpc to create G.mpc
Line 5: Create D=(I-G)/G (requires HDRI IM 7 compile to keep negative values)
Line 6: Compute M=T*Max(sqrt(D*D)) as a single number variable in the range 0 to 65535 (Quantumrange for 16-bit IM compile)
Line 7: Compute 2*M as variable M2
Line 8: Compute output O = T * (D + M) / (2 * M)

enter image description here

If this is not correct (does not match your python, etc, approach, then please post and input and output example and then I might be able to correct any false assumptions or mistakes and make it work the same.

If wanting to use Imagemagick 6, then one would have to compile or get a version that is Q16 HDRI compiled. Then in the above commands, just change magick to convert.

like image 96
fmw42 Avatar answered Jan 04 '26 16:01

fmw42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!