We have the test image with M rows and N columns as f(x,y), for x∈ [1,M] and y∈ [1,N ]. The horizontal absolute difference value of a pixel is defined by D (x, y) = |f (x, y +1) − f (x, y −1)|. need help in how to implement it in matlab
Asked
Active
Viewed 191 times
3 Answers
1
This will generate same size matrix, that you need:
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)

Alamakanambra
- 5,845
- 3
- 36
- 43
0
D = abs( f(1:end-1,:) - f(2:end,:) );
check out diff
command as well. Note that D
has 1 row less than f
.

Shai
- 111,146
- 38
- 238
- 371
0
aux = abs(diff(f,[],2));
D = max(aux(:,1:end-1), aux(:,2:end));
For example: given
f = [3 5 6 4
2 5 4 3
8 9 3 1];
the result is
>> D
D =
2 2
3 1
6 6

Luis Mendo
- 110,752
- 13
- 76
- 147