What does the 'imfuse' output mean?

2 views (last 30 days)
Ricardo Checchia Whitaker
Edited: Adam Danz on 6 Dec 2019
Hello Everyone,
I am using the function "imfuse", with default 'falsecolor' method to check overlap of two images. I am then applying rgb2gray and changing units from uint8 to double. Finally, it ouputs me a matrix with a bunch of numbers. What do they mean? Also, is it correct for me to quantify amount of overlapping by dividing the values on the outputted matrix that are greater than zero, by the size of the matrix? Code is shown below:
Fused = imfuse(Image3, Image4, 'falsecolor');
Fused = rgb2gray(Fused);
Fused = double(Fused);
Size_Final1 = size(Fused);
Number_Matching_Pixels10 = sum(Fused(:) > 0);
AllPixels1 = Size_Final1(1)*Size_Final1(2);
Percentage_Of_Overlaying10 = (Number_Matching_Pixels10/AllPixels)*100;
Thank you for your support.

Answers (2)

Rik
Rik on 5 Dec 2019
The output is an image. If you don't understand a function reading its documentation is an excellent start. Here is a link to the imfuse documentation. Typing doc imfuse in you command window will also work.
  2 Comments
Ricardo Checchia Whitaker
I understand that, and I have checked the doc for that. But it outputs me matrix in the workspace, and I am curious of what the numbers mean.
Rik
Rik on 5 Dec 2019
An image is just a matrix with fancy formatting. So the way you're calculating the number of matching pixels doesn't really make sense. For a grayscale, truecolor or binary image You can use the code below to find matching pixels. It doens't do the padding for you that imfuse does.
%generate example 'images'
A=uint8(randi([0 255],100,120,3));
B=uint8(randi([0 255],100,120,3));
tol=2*eps;
matchingPixels= abs(double(A)-double(B))<=tol ;%logical matrix
matchingPixels=all(matchingPixels,3);%reduce 3rd dimension to 1
Number_Matching_Pixels=sum(matchingPixels(:));
This code converts to double (preventing 50-60=0), takes the absolute value to make everything positive, and then compares to a tiny tolerance (to prevent issues with floats).

Sign in to comment.


Adam Danz
Adam Danz on 5 Dec 2019
Edited: Adam Danz on 6 Dec 2019
Regarding the line of code Fused = imfuse(Image3, Image4, 'falsecolor');
For the falsecolor method, by default, Fused is a composite RGB image showing A and B overlaid in different color bands. Gray regions in the composite image show where the two images have the same intensities. Magenta and green regions show where the intensities are different.
The output is an 8-bit unsigned integer array. Its values will typically range from 0 to 255. To confirm that:
min(Fuse(:))
max(Fused(:))
The size of Fused is a 3D array where the first two dimension cover the range of pixels in your image and the 3rd dimension specifies the grayscale, truecolor, or binary image values depending on the function's input.
Check out this link for a detailed explanation.

Community Treasure Hunt

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

Start Hunting!