-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSOBEL_ANTO_OPTIM.m
More file actions
37 lines (29 loc) · 1.09 KB
/
SOBEL_ANTO_OPTIM.m
File metadata and controls
37 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [Filtered_img,Filtered_X,Filtered_Y] = SOBEL_ANTO_OPTIM(Gray_img)
%% Defining Kernels and flipping them to make convolution
Kernel_X=[-1 0 1; -2 0 2; -1 0 1];
Kernel_X=Kernel_X(:);
Kernel_X = flip(Kernel_X);
Kernel_Y=[-1 -2 -1; 0 0 0; 1 2 1];
Kernel_Y = Kernel_Y(:);
Kernel_Y = flip(Kernel_Y);
%% Pre-allocating arrays
sizeIMG = size(Gray_img);
Gray_reshaped = zeros((sizeIMG(1)-2) *(sizeIMG(2)-2),9);
sizeIMGFilterd = [sizeIMG(1)-2 sizeIMG(2)-2];
%% Sliding over image to create a rearranged 2D matrix with each row a different image window
k=1;
for i=1:(sizeIMGFilterd(2))
for j=1:(sizeIMGFilterd(1))
Gray_reshaped(k,:) = reshape(Gray_img(j:j+2,i:i+2),1,[]);
k=k+1;
end
end
%% Applying convolution with a dot-product
Filtered_X = Gray_reshaped*Kernel_X;
Filtered_Y = Gray_reshaped*Kernel_Y;
%% Reshaping to 2D matrix
Filtered_X = reshape(Filtered_X,sizeIMGFilterd(1),sizeIMGFilterd(2));
Filtered_Y = reshape(Filtered_Y,sizeIMGFilterd(1),sizeIMGFilterd(2));
%% Taking the modulus
Filtered_img = sqrt((Filtered_X.^2) + (Filtered_Y.^2));
end