This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_6.m
executable file
·107 lines (83 loc) · 2.5 KB
/
main_6.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
clear all;
close all;
clc;
%% preparation
I = imread('village.gif');
% Let us define some structuring elements here
% for ease of modularity.
seDiamond = strel('diamond' , 5);
seDisk = strel('disk' , 3);
seDiskBig = strel('disk' , 7);
seLine = strel('line' , 3, 0);
seLineRotated = strel('line' , 3, 90);
seSquare = strel('square' , 2);
%% Binarise
% edges = imdilate(I,seDiskBig)-imerode(I,seDisk);
% level = graythresh(uint8(edges));
level = 0.21345;
BW = im2bw(uint8(I),level);
figure();
subplot(1,2,1); imshow(I,'displayrange',[]);
title('Original Image.', 'FontSize', 15)
subplot(1,2,2); imshow(BW);
title('Binarized Image.', 'FontSize', 15)
%% UrbanDetect
detected = UrbanDetec('village.gif','out.gif',5,level-0.07);
%% Algorithm Implementation
%% Step 1 -- TH & BH
% TH by opening: WTH(f) = f − (f o B)
% (erosion followed by dilation)
TH = imerode(I,seDiamond);
TH = imdilate(TH,seDiamond);
TH = I - TH;
% BH by closing: BTH(f) = f − (f • B)
% (dilation followed by erosion)
BH = imdilate(I,seDiamond);
BH = imerode(BH,seDiamond);
BH = BH - I;
% plot
figure();
subplot(2,2,1); imshow(TH);
title('Our TopHat Image.', 'FontSize', 15)
subplot(2,2,2); imshow(imtophat(I,seDiamond));
title('TopHat Image using imtophat().', 'FontSize', 15)
subplot(2,2,3); imshow(BH);
title('BotHat Image.', 'FontSize', 15)
subplot(2,2,4); imshow(imbothat(I,seDiamond));
title('BotHat Image using imbothat().', 'FontSize', 15)
%% Step 2 -- Normalize
normTH = im2double(TH);
normBH = im2double(BH);
%% Step 3 -- Otsu
edgesTH = imdilate(normTH,seDiskBig)-imerode(normTH,seDisk);
edgesBH = imdilate(normBH,seDiskBig)-imerode(normBH,seDisk);
%
level = graythresh(edgesTH);
BWITH = im2bw(normTH,level);
%
level = graythresh(edgesBH);
BWIBH = im2bw(normBH,level);
%% Step 4
figure();
subplot(1,2,1); imshow(BWITH);
title('BWTH Image.', 'FontSize', 15)
subplot(1,2,2); imshow(BWIBH);
title('BWBH Image.', 'FontSize', 15)
%% Step 5
newTH = imopen(BWITH,seLine);
figure();
subplot(1,2,1); imshow(newTH);
title('newTH Image.', 'FontSize', 15)
%% Step 6
newBH = imopen(BWIBH,seLine);
newBH = imclose(newBH,seLineRotated);
subplot(1,2,2); imshow(newBH);
title('newBH Image.', 'FontSize', 15)
%% Step 7
fused = imfuse(newTH,newBH);
figure();
imshow(fused);
title('Fused Image.', 'FontSize', 15)
return;
%% Usefull Links
% http://www.mi.fu-berlin.de/wiki/pub/ABI/QuantProtP4/signal-processing.pdf