-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageProcess.m
More file actions
191 lines (147 loc) · 4.58 KB
/
Copy pathImageProcess.m
File metadata and controls
191 lines (147 loc) · 4.58 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
%% Read image
stackNinjaOne = imread("StackNinja1.bmp");
stackNinjaTwo = imread("StackNinja2.bmp");
stackNinjaThree = imread("StackNinja3.bmp");
%% First plots of the original images being plotted out
figure();
subplot(5,3,1);
imshow(stackNinjaOne);
title('Figure 1: StackNinjaOne');
subplot(5,3,2);
imshow(stackNinjaTwo);
title('Figure 2: StackNinjaTwo');
subplot(5,3,3);
imshow(stackNinjaThree);
title('Figure 3: StackNinjaThree');
%% Changing colour space
% getting the grayscale array of green colour pane of cell nucleii
% multiply stack ninja to alter contrast
greyOne = stackNinjaOne(:,:,2) * 2;
subplot(5,3,4);
imshow(greyOne);
title('Figure 1a: Colour space conversion');
% higher value needed due to more shade - not as automatic
greyTwo = stackNinjaTwo(:,:,2) * 1.5;
subplot(5,3,5);
imshow(greyTwo);
title('Figure 2a: Colour space conversion');
greyThree = stackNinjaThree(:,:,2) * 1.5;
subplot(5,3,6);
imshow(greyThree);
title('Figure 3a: Colour space conversion');
%{
%% Test: Grey colour space conversion using matlab function (rgb2gray)
greySNOne = rgb2gray(stackNinjaTwo);
subplot(4,3,4);
imshow(greySNTwo);
title('Figure 2a:');
greySNTwo = rgb2gray(stackNinjaTwo);
subplot(4,3,5);
imshow(greySNTwo);
title('Figure 2a:');
greySNThree = rgb2gray(stackNinjaThree);
subplot(4,3,6);
imshow(greySNThree);
title('Figure 3a:');
%}
%% Noise Reduction
fixedMedOne = medfilt2(greyOne);
fixedMedTwo = medfilt2(greyTwo);
fixedMedThree = medfilt2(greyThree);
subplot(5,3,7);
imshow(fixedMedOne);
title('Figure1b: Noise removal with Median Filter');
subplot(5,3,8);
imshow(fixedMedTwo);
title('Figure2b: Noise removal with Median Filter');
subplot(5,3,9);
imshow(fixedMedThree);
title('Figure3b: Noise removal with Median Filter');
%% Test: Gaussian filtering
%{
gauss1 = fspecial('gaussian',[3 3],0.5);
gauss2 = fspecial('gaussian',[5 5],1.0);
gauss3 = fspecial('gaussian',[7 7],1.5);
gauss4 = fspecial('gaussian',[12 12],3.0);
fixedGuassOne = imfilter(greyOne,gauss4);
fixedGuassTwo = imfilter(greyTwo,gauss4);
fixedGuassThree = imfilter(greyThree,gauss4);
subplot(4,3,7);
imshow(fixedGuassOne);
title('Noise removal with Gaussian Smoothing');
subplot(4,3,8);
imshow(fixedGuassTwo);
title('Noise removal with Gaussian Smoothing');
subplot(4,3,9);
imshow(fixedGuassThree);
title('Noise removal with Gaussian Smoothing');
%}
%% Thresholding
% adapative thresholding
otsuThreshOne = graythresh(fixedMedOne);
otsuThreshTwo = graythresh(fixedMedTwo);
otsuThreshThree = graythresh(fixedMedThree);
otsuThreshOneLocal = adaptthresh(fixedMedOne,0.1);
otsuThreshTwoLocal = adaptthresh(fixedMedTwo,0.1);
otsuThreshThreeLocal = adaptthresh(fixedMedThree,0);
%{
otsuThreshOne = graythresh(fixedMedOne);
otsuThreshTwo = graythresh(fixedMedTwo);
otsuThreshThree = graythresh(fixedMedThree);
%otsuThreshTwo = adaptthresh(fixedMedTwo,0.1);
%otsuThreshThree = adaptthresh(fixedMedThree,0);
%otsuThreshThree = medfilt2(otsuThreshThree);
%}
%{
%% Test: Using fixed threshold
thresholdOne = 170;
thresholdTwo = 100;
thresholdThree = 100;
%fixedMedThree = fixedMedThree/255;
BWThree = fixedMedThree;
BWThree(BWThree>otsuThreshThree) = 255;
BWThree(BWThree<=otsuThreshThree) = 0;
FixedBWOne = fixedMedOne;
FixedBWOne(FixedBWOne>otsuThreshOne) = 255;
FixedBWOne(FixedBWOne<=otsuThreshOne) = 0;
FixedBWTwo = fixedMedThree;
FixedBWTwo(FixedBWTwo>thresholdTwo) = 255;
FixedBWTwo(FixedBWTwo<=thresholdTwo) = 0;
FixedBWThree = fixedMedThree;
FixedBWThree(FixedBWThree>thresholdThree) = 255;
FixedBWThree(FixedBWThree<=thresholdThree) = 0;
%}
%% Binary Image
%{
%% Test: using fixed threshold
binaryOne = imbinarize(FixedBWOne);
binaryTwo = imbinarize(FixedBWTwo);
binaryThree = imbinarize(FixedBWThree);
%}
% extracting binary image using adaptive thresholding
%global thresholding
binaryOne = imbinarize(fixedMedOne, otsuThreshOne);
binaryTwo = imbinarize(fixedMedTwo, otsuThreshTwo);
binaryThree = imbinarize(fixedMedThree, otsuThreshThree);
%local thresholding
binaryOneLocal = imbinarize(fixedMedOne, otsuThreshOneLocal);
binaryTwoLocal = imbinarize(fixedMedTwo, otsuThreshTwoLocal);
binaryThreeLocal = imbinarize(fixedMedThree, otsuThreshThreeLocal);
subplot(5, 3, 10),
imshow(binaryOne),
title('Figure 1c: Gloabl Binary Image');
subplot(5, 3, 11),
imshow(binaryTwo),
title('Figure 2c: Global Binary Image');
subplot(5, 3, 12),
imshow(binaryThree),
title('Figure 3c: Gloabl Binary Image');
subplot(5, 3, 13),
imshow(binaryOneLocal),
title('Figure 1d: Local Binary Image');
subplot(5, 3, 14),
imshow(binaryTwoLocal),
title('Figure 2d: Local Binary Image');
subplot(5, 3, 15),
imshow(binaryThreeLocal),
title('Figure 3d: Local Binary Image');