Imfuse 'blend' issues
3 ビュー (過去 30 日間)
古いコメントを表示
I have a function that takes two images and compares their overlapping areas using the imfuse 'blend' command. My function works most of the time, as it relies on the overlapping area to be black while the non-overlapping area is grey. However, in some cases, when I use the fuse command on two images, one of the two resulting images will remain completely black, even if it does not overlap the second image. This leads to my function not working when this happens, as my function depends on the non-overlapping area to be grey. I have attached both an example of the blend command where the images blend how I want them to, and I have attached an example of the blend command where the images do NOT blend how I want them to. Here is my function:
function [PSame,PDiff] = Comparison(FinalImage2,RotatedImage)
FI2=FinalImage2;
RI=RotatedImage;
Combined=imfuse(FI2,RI,'blend');
imshow(Combined);
Total=sum(Combined(:)~=255);
Same=sum(Combined(:)==0);
Diff=sum(Combined(:)==128);
IM1=sum(FinalImage2(:)==0);
IM2=sum(RotatedImage(:)==0);
PSame=(Same/Total)*100;
PDiff=(Diff/Total)*100;
PIM1=((IM1-Same)/Total)*100;
PIM2=((IM2-Same)/Total)*100;
fprintf("Percent Same: %0.2f \n",PSame)
fprintf("Percent Different: %0.2f \n",PDiff)
fprintf("Percent Just Image 1: %0.2f \n",PIM1)
fprintf("Percent Just Image 2: %0.2f \n",PIM2)
end
If you need any more information, please let me know! Thanks!
回答 (1 件)
DGM
2024 年 6 月 5 日
編集済み: DGM
2024 年 6 月 5 日
Like most cases, I don't see the point of using imfuse() here. If you're treating the images as if they're binarized, make sure they're binarized, and handle them using basic logical operations.
A = imread('monojagblob.png');
B = imread('tiltellipse.png');
B = imresize(B,size(A,1:2));
% if you want to visualize, imfuse() is a convenience
imshow(imfuse(A,B))
% the actual programmatically useful output doesn't require imfuse()
[PSame,PDiff] = Comparison(A,B,'positive') % the object is white on black
[PSame,PDiff] = Comparison(A,B,'negative') % the object is black on white
function [PSame,PDiff] = Comparison(A,B,polarity)
% instead of presuming that both images are necessarily uint8
% just work in unit-scale and ignore any quirks of imfuse()
% you're also assuming that the images are strictly binarized
% and contain no antialiasing or compression artifacts.
% if you want to treat things as binarized, make sure they are.
A = im2double(A)>0.5; % objects are light-on-dark features
B = im2double(B)>0.5;
% flip polarity if required
if nargin > 2
switch lower(polarity)
case 'positive'
% do nothing
case 'negative'
A = ~A;
B = ~B;
otherwise
error('write some error message here')
end
end
Total = nnz(A | B); % union (either)
Same = nnz(A & B); % intersection (both)
Diff = nnz(xor(A,B)); % disjunctive union (either, but not both)
areaA = nnz(A); % the total area of A
areaB = nnz(B); % the total area of B
% as percentages
PSame = (Same/Total)*100;
PDiff = (Diff/Total)*100;
PIM1 = ((areaA-Same)/Total)*100;
PIM2 = ((areaB-Same)/Total)*100;
fprintf("Percent Same: %0.2f \n",PSame)
fprintf("Percent Different: %0.2f \n",PDiff)
fprintf("Percent Just Image 1: %0.2f \n",PIM1)
fprintf("Percent Just Image 2: %0.2f \n",PIM2)
end
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!