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.

답변 (2개)

Rik
Rik 2019년 12월 5일

1 개 추천

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

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.
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).

댓글을 달려면 로그인하십시오.

Adam Danz
Adam Danz 2019년 12월 5일
편집: Adam Danz 2019년 12월 6일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

질문:

2019년 12월 5일

편집:

2019년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by