Matlab 试图实施;imabsdiff“;功能
我试图在scliab中实现imabsdiff函数,但在理论上和使用内置函数时,我得到了不同的结果Matlab 试图实施;imabsdiff“;功能,matlab,image-processing,scilab,Matlab,Image Processing,Scilab,我试图在scliab中实现imabsdiff函数,但在理论上和使用内置函数时,我得到了不同的结果 //Image subtraction with absolute difference and its effect //Image 2 is being subtracted from image 1 clc; clear; //reading the image A=ReadImage('E:\pruthvi iitb\DIP\Chapter 3 DIP\cocacola1.png');
//Image subtraction with absolute difference and its effect
//Image 2 is being subtracted from image 1
clc;
clear;
//reading the image
A=ReadImage('E:\pruthvi iitb\DIP\Chapter 3 DIP\cocacola1.png');
B=ReadImage('E:\pruthvi iitb\DIP\Chapter 3 DIP\cocacola2.png');
A=RGB2Gray(A);
B=RGB2Gray(B);
figure(1);
ShowImage(A,'First Image');
title("First Image");
figure(2);
ShowImage(B,'Second Image');
title("Second Image");
[m n]=size(A);//size om image , M rows and N cols
//C=[][];//Absolute Subtracted Image
for i=1:m
for j=1:n
a=A(i,j);
b=B(i,j);
C(i,j)=abs(a -b);// absolute difference
end
end
figure(3);
ShowImage(C,'Absolute Subtracted Image');
title("Absolute Subtracted Image");
figure(4);
ShowImage(imabsdiff(A,B),'formula Image');
title("Absolute Subtracted Image");
Cocalcola1.png
Cocacola2.png
结果
右侧使用内置函数
您的问题可能是试图从彼此之间减去
uint8
值。由于uint8
不能为负,当您执行a-b
(将在将其放入abs
功能之前进行计算)时,对于b大于a的任何情况,您都不会得到正确答案
使用im2double
将图像转换为double,使用im2uint8
将图像转换回double
顺便说一下,这里不需要循环像素。您可以简单地执行以下操作(一旦图像被转换为双倍):
这就是问题所在,我试着调试它,得出了相同的结论。
C = abs(A-B)