|
a |
|
b/Code/main1.m |
|
|
1 |
clear ; |
|
|
2 |
clear ; |
|
|
3 |
|
|
|
4 |
org=imread('4Perfect.jpg'); |
|
|
5 |
org=imresize(org,[256 256]); |
|
|
6 |
noisy= imnoise(org,'gaussian',0,0.001);% % add noise of mean 0, variance 0.005 |
|
|
7 |
subplot(3,3,1), imshow(org,[]), title('Original Image'); |
|
|
8 |
subplot(3,3,2), imshow(noisy,[]), title('Noisy Image'); |
|
|
9 |
|
|
|
10 |
% start of calling normal shrink denoising algorithm |
|
|
11 |
|
|
|
12 |
ns_r = normal_shrink(noisy(:,:,1)); |
|
|
13 |
ns_g = normal_shrink(noisy(:,:,2)); |
|
|
14 |
ns_b = normal_shrink(noisy(:,:,3)); |
|
|
15 |
ns_r= uint8(ns_r); |
|
|
16 |
ns_g= uint8(ns_g); |
|
|
17 |
ns_b= uint8(ns_b); |
|
|
18 |
ns = cat(3, ns_r, ns_g, ns_b); |
|
|
19 |
subplot(3,3,4), imshow(ns,[]), title('normal shrink'); |
|
|
20 |
|
|
|
21 |
% end of calling normal shrink denoising algorithm |
|
|
22 |
|
|
|
23 |
% start of calling bilateral filter |
|
|
24 |
|
|
|
25 |
ns2gray = rgb2gray(ns); |
|
|
26 |
ns2gray = double(ns2gray); |
|
|
27 |
B = bilateral(ns2gray); |
|
|
28 |
subplot(3,3,5), imshow(B,[]), title('bilateral'); |
|
|
29 |
|
|
|
30 |
% end of calling bilateral filter |
|
|
31 |
|
|
|
32 |
%enhanced image |
|
|
33 |
enha_imadj = imadjust(uint8(B)); |
|
|
34 |
enha_histeq = histeq(uint8(B)); |
|
|
35 |
enha_adapthisteq = adapthisteq(uint8(B)); |
|
|
36 |
|
|
|
37 |
% start of edge based segmentation |
|
|
38 |
|
|
|
39 |
%kirsch operator |
|
|
40 |
kris = krisch(B); |
|
|
41 |
subplot(3,3,7), imshow(kris,[]), title('krisch'); |
|
|
42 |
%extended kirsch operator |
|
|
43 |
kris55 = krisch55(B); |
|
|
44 |
subplot(3,3,8), imshow(kris55,[]), title('krisch55'); |
|
|
45 |
%extended sobel operator |
|
|
46 |
sob55 = sobel55(B); |
|
|
47 |
subplot(3,3,9), imshow(sob55,[]), title('sobel 5*5'); |
|
|
48 |
|
|
|
49 |
% end of edge based segmentation |
|
|
50 |
|
|
|
51 |
% start of threshold based segmentation |
|
|
52 |
|
|
|
53 |
%ostu threshold |
|
|
54 |
ostu_img = ostu(B); |
|
|
55 |
figure;imshow(ostu_img,[]),title('ostu'); |
|
|
56 |
|
|
|
57 |
% end of threshold based segmentation |
|
|
58 |
|
|
|
59 |
% kmeans clustering |
|
|
60 |
figure; |
|
|
61 |
[k, class, img_vect]= kmeans(B, 5); |
|
|
62 |
for clust = 1:k |
|
|
63 |
cluster = reshape(class(1:length(img_vect),clust:clust), [256,256] ); |
|
|
64 |
subplot(1,k,clust), imshow(cluster,[]), title('k-means cluster '); |
|
|
65 |
end |
|
|
66 |
|
|
|
67 |
%adaptive clustering |
|
|
68 |
[k, class, img_vect, noOfIter]= adaptive_kmeans(B); |
|
|
69 |
%title(['adaptive kmeans- total iteration' num2str(noOfIter)]); |
|
|
70 |
figure; |
|
|
71 |
for clust = 1:k |
|
|
72 |
cluster = reshape(class(1:length(img_vect),clust:clust), [256,256] ); |
|
|
73 |
subplot(1,k,clust), imshow(cluster,[]), title({'adaptivekmeans:';['iteration ' num2str(noOfIter)]}); |
|
|
74 |
end |
|
|
75 |
|
|
|
76 |
%fuzzy c means |
|
|
77 |
img = double(B); |
|
|
78 |
k = 5; |
|
|
79 |
[ Unew, centroid, obj_func_new ] = fuzzyCMeans( img, k ); |
|
|
80 |
figure; |
|
|
81 |
for i=1:k |
|
|
82 |
subplot(1,k,i); |
|
|
83 |
imshow(Unew(:,:,i),[]), title('fuzzy Cmeans'); |
|
|
84 |
end |
|
|
85 |
|
|
|
86 |
% watershed algorithm |
|
|
87 |
figure; |
|
|
88 |
watershedSeg(B, sob55); |
|
|
89 |
|