-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jeol_Scalebar_Detection.m
67 lines (59 loc) · 1.6 KB
/
Jeol_Scalebar_Detection.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
function [ScaleBar_Pixels,ScaleBar_Locsx, ScaleBar_Locsy] = Jeol_Scalebar_Detection(Image)
%% Scalebar Image Definition
Scale_Image=[
0 0 0 0 0;
0 1 1 1 0;
0 1 0 1 0;
0 1 1 1 0;
0 0 0 0 0
]; %% The format of the scale bar markers
%% Scalebar Detection
[r, c] = size(Image);
[rc, cc] = size(Scale_Image);
count = 0;
New_Im = double(Image)/255;
mat = [];
for i = 1:(r-rc-5)
for j = 1:(c-cc-5)
Testmat=New_Im(i:(i+rc-1), j:(j+cc-1));
%imshow(Testmat)
if isequal((Scale_Image), (Testmat))
count = count+1;
mat(count, :)=[i j];
end
end
end
if isempty(mat)
Scale_Image=[
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 1 1 1 1 1 1 1 0 0;
0 0 1 1 1 1 1 1 1 0 0;
0 0 1 1 0 0 0 1 1 0 0;
0 0 1 1 0 0 0 1 1 0 0;
0 0 1 1 0 0 0 1 1 0 0;
0 0 1 1 1 1 1 1 1 0 0;
0 0 1 1 1 1 1 1 1 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0
]; %% The format of the scale bar markers
%% Scalebar Detection
[r, c] = size(Image);
[rc, cc] = size(Scale_Image);
count = 0;
New_Im = double(Image)/255;
for i = 1:(r-rc-11)
for j = 1:(c-cc-11)
Testmat = New_Im(i:(i+rc-1), j:(j+cc-1));
%imshow(Testmat)
if isequal((Scale_Image), (Testmat))
count = count+1;
mat(count, :) = [i j];
end
end
end
end
ScaleBar_Pixels = max(mat(:,2))-min(mat(:,2));
ScaleBar_Locsx = [max(mat(:,2))+2 min(mat(:,2))+2];
ScaleBar_Locsy = [max(mat(:,1)) min(mat(:,1))];
end