File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ function [ residual , y ] = img2data (x )
2
+
3
+ gray = rgb2gray( x );
4
+ BW = edge( gray );
5
+
6
+ [height , width ] = size(BW );
7
+ y = zeros(1 , width );
8
+ residual = zeros(1 , width );
9
+
10
+ % for i = 1:width
11
+ % if max(BW(:, i)) > 0
12
+ % val = 0;
13
+ % count = 0;
14
+ % for j = 1: height
15
+ % if BW(j,i) == 1
16
+ % val = val + j;
17
+ % count = count + 1;
18
+ % end
19
+ % end
20
+ % BW(:,i) = zeros(height, 1);
21
+ % val = round((val/count));
22
+ % BW(val, i) = 1;
23
+ % end
24
+ % end
25
+
26
+ imshowpair(gray ,BW ,' falsecolor' )
27
+
28
+ SE = strel(' line' , 4 , 0 );
29
+ BWprime= imclose(BW , SE );
30
+
31
+ imshowpair(gray ,BWprime ,' falsecolor' )
32
+
33
+ for i = 1 : width
34
+ for j = 0 : height - 1
35
+ if BWprime(height - j ,i ) == 1
36
+ y(1 ,i ) = (j );
37
+ end
38
+ end
39
+ end
40
+
41
+ t = 1 : width ;
42
+ z = zeros(1 , width );
43
+ c = fit (t ' , y ' , ' poly1' );
44
+
45
+ coeffs = coeffvalues(c );
46
+
47
+ slope = coeffs(1 );
48
+ intercept = coeffs(2 );
49
+
50
+ for k = 1 : width
51
+ residual(1 ,k ) = y(1 ,k ) - ( slope * k + intercept );
52
+ end
53
+
54
+ plot (t , residual , t , z )
You can’t perform that action at this time.
0 commit comments