-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMarks.m
119 lines (90 loc) · 1.9 KB
/
getMarks.m
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function getMarks(image,namez);
im = imread(image);
if ndims(im)>=3
im = rgb2gray(im);
end
[origRow,origCol] = size(im);
new_im = im;
edgi = edge(im,'prewitt',[],'horizontal');
[H,theta,rho] = hough(edgi);
P = houghpeaks( H,7,'threshold', ceil( 0.3*max( H(:) ) ) );
x = theta(P(:,2));
y = rho(P(:,1));
lines = houghlines(edgi,theta,rho,P,'FillGap',5,'MinLength',10);
[rr,cc] = size(edgi);
vect = zeros(cc,2);
lin=0;
max_len = 0;
row=[1 length(lines)];
row(:,:) = rr+1;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
%plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green'); %= for line
row(1,k) = xy(2,2);
% Plot beginnings and ends of lines
%plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
%plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
temp = min(row(1,:));
mini =max(row(1,:));
totalLiness = length(lines);
finRow=0;
if(temp<= (300))
for i=1:totalLiness
if( (row(1,i) < mini) & row(1,i) >300 )
finRow = row(1,i);
mini = row(1,i);
end
end
else
finRow = temp;
end
finRow;
nim = zeros(240,cc);
start = finRow-120;
endi = finRow+120;
irow=1;
icol=1;
if(start<0)
start = -1*(start);
end
if(endi<0)
endi = -1*(endi);
end
for i=start:endi
for j=1:cc
nim(irow,icol) = im(i,j);
icol=icol+1;
end
irow=irow+1;
icol=1;
end
last_row = max(row(1,:));
start = last_row-290;
last_row = last_row+30;
Matcols = origCol-100;
start_coli=100;
marks = zeros(320,Matcols-start_coli);
[marksRows,marksCols] = size(marks)
start;
last_row;
u=1;
v=1;
for i=start:last_row
for j=start_coli:Matcols
marks(u,v) = im(i,j);
v=v+1;
end
v=1;
u=u+1;
end
close all
figure, imshow(marks,[]) , title('Marks');
edgi = edge(marks,'prewitt',[],'both');
imwrite(marks,gray(255),namez);