Refer to Hebei Normal University master's degree thesis--Research on edge detection algorithm based on eight direction Sobel operator.
Due to the implementation of the filter operation, the calculation speed is very slow, later have the ability to improve.
Operators are defined as follows:
Algorithm ideas:
1. Convert the RGB image to an image of the cielab color space.
2. Calculate the gradient in different directions, multiply the weights and take the maximum value as the output value.
The effect is as follows:
Running time: 33.543444 seconds.
Running time: 79.695009 seconds.
Good run, slow qaq.
The code is as follows:
CIELABEDGE.M (total entrance of the algorithm)
% edge detection of images in Cielab color space (parameters for RGB images to be processed)
% using the Sobel operator in the paper, the
paper is quoted--Zheng. Edge detection algorithm based on eight-direction Sobel operator. Master's degree thesis of Hebei Normal University. 2013.3.26
%from:yinggang Wang
%create date:2018.3.30
function [] = Cielabedge (img)
% color space conversion
Lab = Rgb2lab (IMG);
% filter processing
Edge = Myfilter (Lab);
% output Figure
(' numbertitle ', ' off ', ' Name ', ' edge ');
Imshow (edge,[]);
Figure (' Numbertitle ', ' off ', ' Name ', ' Edge (negative) ');
Imshow (Imcomplement (Edge), []);
MYFILTER.M (self-implemented filter)
% using filter filter (parameter: Cielab three-dimensional matrix of color space) (Image output size is smaller than actual)
%
%from:yinggang Wang
%create date:2018.3.30
function im = Myfilter (ori)
s = size (ori);
im = Zeros (s (1), S ());
For i = 3: (s (1)-2) for
j = 3: (s (2)-2)
im (i-2,j-2) = GetOutput (ori,i,j);
End
End
GETOUTPUT.M (Gets the output value of each point)
% get x, y coordinate pixel output value%%from:yinggang Wang%create date:2018.3.30 function out = getoutput (ori,x,y)% below is operator in eight directions D0 = [1,2,4,2
, 1];
D22_5 = [1,2,4,2,4];
D45 = [1,4,2,4,1];
D67_5 = [1,2,4,2,4];
D90 = [1,2,4,2,1];
D112_5 = [1,2,4,2,1];
D135 = [1,4,2,4,1];
D157_5 = [1,2,4,2,4];
A = zeros (1,8); A (1) = SUM (D0. * [CD] (Ori (x-2,y-1), Ori (x-2,y+1)), CD (Ori (X-1,Y-1), Ori (x-1,y+1)), CD (Ori (X,Y-1), Ori (x,y+1)), CD (Ori (x+1
, y-1), Ori (x+1,y+1)), CD (Ori (x+2,y-1), Ori (x+2,y+1))]); A (2) = SUM (d22_5. * [CD] (Ori (x-2,y), Ori (X+2,y)), CD (Ori (X-1,Y+1), Ori (X+1,Y-1)), CD (Ori (X,Y-1), Ori (x,y+1)), CD (Ori (X-1),
Y-1), Ori (x+1,y+1)), CD (Ori (x-1,y), Ori (X+1,y))]); A (3) = SUM (D45. * [CD] (Ori (x+1,y-2), Ori (X+2,Y-1)), CD (Ori (X,Y-1), Ori (X+1,y)), CD (Ori (X-1,Y-1), Ori (x+1,y+1)), CD (Ori (
X-1,y), Ori (x,y+1)), CD (Ori (x-2,y+1), Ori (x-1,y+2))]); A (4) = SUM (d67_5. * [CD] (Ori (x,y-2), Ori (x,y+2)), CD (Ori (X-1,Y-1), Ori (x+1,y+1)), CD (Ori (X-1,y), Ori (X+1,y)), CD (Ori (X-1),
y+1), Ori (x+1,y-1)), CD (Ori (x,y+1), Ori (X,Y-1))]); A (5) = SUM (D90. * [CD] (Ori (x-1,y-2), Ori (x+1,y-2)), CD (Ori (x-1,Y-1), Ori (X+1,Y-1)), CD (Ori (X-1,y), Ori (X+1,y)), CD (Ori (X-1,Y-2), Ori (x+1,y-2)), CD (Ori (X-1,Y+2), Ori (x+1,y+2))]); A (6) = SUM (d112_5. * [CD] (Ori (x,y-2), Ori (x,y+2)), CD (Ori (X-1,Y-1), Ori (x+1,y+1)), CD (Ori (X-1,y), Ori (X+1,y)), CD (Ori (x-1
, y+1), Ori (x+1,y-1)), CD (Ori (x,y+1), Ori (X,Y-1))]); A (7) = SUM (D135. * [CD] (Ori (x-1,y-2), Ori (X-2,Y-1)), CD (Ori (X,Y-1), Ori (X-1,y)), CD (Ori (X+1,Y-1), Ori (x-1,y+1)), CD (Ori (x
+1,y), Ori (x,y+1)), CD (Ori (x+2,y+1), Ori (x+1,y+2))]); A (8) = SUM (d157_5. * [CD] (Ori (x-2,y), Ori (X+2,y)), CD (Ori (X-1,Y+1), Ori (X+1,Y-1)), CD (Ori (X,Y-1), Ori (x,y+1)), CD (Ori (x-1
, y-1), Ori (x+1,y+1)), CD (Ori (x-1,y), Ori (X+1,y))]);
A (1) = a (1)/10.0;
A (2) = A (2)/13.0;
A (3) = A (3)/12.0;
A (4) = A (4)/13.0;
A (5) = A (5)/10.0;
A (6) = A (6)/13.0;
A (7) = A (7)/12.0;
A (8) = A (8)/13.0; out = ((max (a) +0.5));
CD.M (for two-point Euclidean distance)
% two Euclidean distance
%
%from:yinggang Wang
%create date:2018.3.30
function dis = CD (A, b)
dis = sqrt ((a) ^2 + (a) ^2 + (A-B) ^2);
Code has been uploaded: Click to go to download page