-3

对于x∈[1,M]和y∈[1,N],我们有M行N列的测试图像为 f(x,y)。 D(x,y)= | f(x,y + 1) - f(x,y-1)|定义像素的水平绝对值差值 。 需要在如何实现它在MATLABcompute一个像素的水平绝对差值

回答

0
D = abs(f(1:end-1,:) - f(2:end,:)); 

退房diff命令,以及帮助。请注意0​​比f少1排。

1

这将产生同样大小的矩阵,你需要:

mat1 = [zeros(2,size(f,2)); f];% adds 2 rows of zeros to begining 
mat2 = [f;zeros(2,size(f,2))]; %adds 2 row of zeros to the end 
Dd = mat1-mat2; 
D = Dd(2:((size(Dd,1)-1)),:);%crop Dd matrix to size(f) 
0
aux = abs(diff(f,[],2)); 
D = max(aux(:,1:end-1), aux(:,2:end)); 

例如:给定

f = [3 5 6 4 
    2 5 4 3 
    8 9 3 1]; 

结果是

>> D 
D = 
    2  2 
    3  1 
    6  6