Code: Select all
img1 = im2double(imread('img1.tif'));
img2 = im2double(imread('img2.tif'));
img2_eq = im2uint16( img2 ./ mean2(img2) .* mean2(img1) );
Code: Select all
img1_mean=$(convert img1.tif -format "%[mean]" info:)
img2_mean=$(convert img2.tif -format "%[mean]" info:)
ratio=$(echo "x=$img1_mean/$img2_mean; scale=5; x/1" | bc -l)
convert img2.tif -evaluate Multiply $ratio img2_eq.tif
1. Is there a need to worry about image type when performing such conversions? Based on the fact that the output (img2_eq.tif) appears fine and is still 16-bit grayscale, it appears that ImageMagick handled integer to floating point to integer conversions transparently.
2. Is there a way to achieve this in one line (assuming that the mean of the reference image is precalculated and supplied as a shell variable)? Something along the lines of the following pseudocode:
Code: Select all
convert img2.tif -evaluate Divide "%[mean]" -evaluate Multiply $img1_mean img2_eq.tif