Divide one image by another image?

I am working with two Geotiff images that have 16 bit depth. I need to estimate a ratio by using those images with equation such as below:
Ratio = (image1-image2)/(image1+image2);
The resulting ratio should be in the range of 0 to 1, but I am getting zero for all the pixels. I assumed it might have to do with image type conversion, so tried converting those images into double before estimating the ratio (as below), and it is still giving me zero for all pixels.
Ratio = (im2double(image1) - im2double(image2))/(im2double(image1) + im2double(image2))
What should be done to address this problem. Thanks.

 Respuesta aceptada

Image Analyst
Image Analyst el 17 de Sept. de 2017
Use dot slash instead of slash. Also use double() instead of im2double() because I'm not sure if im2double() scales each image independently of the others, which you would not want
Ratio = (double(image1) - double(image2)) ./ (double(image1) + double(image2));
imshow(Ratio, []); % Use the [] - it's important.

3 comentarios

Neo
Neo el 22 de Jul. de 2022
Why is the [] important?
Image Analyst
Image Analyst el 22 de Jul. de 2022
Because that scales the image so that you see the entire range. In this case we might have both positive and negative values in the range -1 to +1. If you don't use [] then all values less than 0 will show up as black since if [] is not used it expects that all values to be between 0 and 1. Anything below 0 will appear black and anything over 1 will appear white. With [] you will have no clipping and see the whole range.
Niklas Kurz
Niklas Kurz el 5 de Dic. de 2022
Awesome, you truely are The Image Analyst!

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 17 de Sept. de 2017

Comentada:

el 5 de Dic. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by