-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzzyimage.m
117 lines (89 loc) · 3.49 KB
/
fuzzyimage.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
%function fuzzy_image
function out_matrix = fuzzyimage(im, imgtruth, i, outdir, patient, lamb,cluster, max_levels)
wt=size(im,2); % dimention of matrix
ht=size(im,1); % dimention of matrix
%out_matrix = zeros(ht,wt); % new matrix intermediate matrix
pi=22./7;
%input_image = im;
outdir = append('results/', patient);
%int_matrix = zeros(ht,wt); % new matrix intermediate matrix
%out_matrix = zeros(ht,wt); % new matrix intermediate matrix
%y = zeros(ht,wt); % cardianlity matrix
in_matrix = im;
%inp =in_matrix; % takng input gray image not doing anything
in_matrix = double (in_matrix)./255; % fuzzy_set
%in_matrix = im;
l=in_matrix;
in_matrix = double((pi/2)*in_matrix);
x = zeros (ht,wt);
w1 = zeros (ht,wt);
w2 = zeros (ht,wt);
a = 0;
[int_matrix,x] = Transit(in_matrix,ht,wt,lamb, cluster); % I1 -> I2
int_matrix(isnan(int_matrix))=0;
[out_matrix,x] = Transit(int_matrix,ht,wt,lamb, cluster); % I2 -> I3
out_matrix(isnan(out_matrix))=0;
[int_matrix,x] = Transit(out_matrix,ht,wt,lamb, cluster); % I3 -> I2
int_matrix(isnan(int_matrix))=0;
[out_matrix,w1] = Transit(int_matrix,ht,wt,lamb, cluster); % I2 -> I3
%fprintf("max1 %f lamb\t %f\n", max(out_matrix(:)), lamb);
count=0;
out_matrix(isnan(out_matrix))=0;
while(a==0)
%out_matrix = normalize(out_matrix);
[int_matrix, x] = Transit(out_matrix,ht,wt,lamb, cluster);
int_matrix(isnan(int_matrix))=0;
[out_matrix, w2] = Transit(int_matrix,ht,wt,lamb, cluster);
a = check(w1,w2,ht,wt);
w1 = w2;
count = count+1;
%disp(a);
if(count>40)
disp("a");
break;
end
end
%fprintf("max %f lamb\t %f\n", max(out_matrix(:)), lamb);
%disp(a);
%subplot (1,3,1), imshow(im); title ('Original Image');
%subplot (1,3,2), imshow(l); title ('Gray Image');
%subplot (1,3,3), imshow(out_matrix); title ('segmented Image')
%figure, imshow(out_matrix,[])
out_matrix(isnan(out_matrix))=0;
%quant = 'max'; threshold = 0;
%thresh = multithresh(out_matrix, max_levels);
%bestDiceImage = mat2gray(out_matrix >= thresh(end));
%quant8_I_min = out_matrix >= thresh(end);
%quant8_I_max = out_matrix <= thresh(end - 1);
%quant8_I_max = out_matrix.*quant8_I_max;
%bestDiceImage = quant8_I_min.*quant8_I_max;
%[bestDiceImage, bestDice, quant, threshold] = maximumDice(( out_matrix), imgtruth, max_levels);
%bestDice = calculateDice(bestDiceImage, mat2gray(imgtruth));
%
% RGB = label2rgb(imquantize(out_matrix, multithresh(out_matrix,max_levels)),'winter');
%
% subplot (1,3,1), imshow(bestDiceImage, []); title ('Segmented Image');
% subplot (1,3,2), imshow(imgtruth, []); title ('Truth Image');
% subplot (1,3,3), imshow(RGB, []); title ('Segmented Multiple Levels Image');
% filename = append(outdir,'/anay.txt');
% fid = fopen(filename,'a+');
% fprintf(fid,'%d \t %f \n', i, bestDice);
% fclose(fid);
% input_image = mat2gray(im);
% rgbImage = imoverlay(input_image,mat2gray(bestDiceImage), 'red');
% filename = sprintf('%s/Comb_%d.png',outdir, i);
% imwrite( rgbImage,filename);
%
% filename = sprintf('%s/Pred_%d.png',outdir, i);
%
% imwrite(RGB,filename);
%
% filename = sprintf('%s/liver_dice.txt',outdir);
% fid = fopen(filename,'a+');
% fprintf(fid,'%s\t%d\t%f\t%f\t\n',patient, i, lamb, bestDice);
% fclose(fid);
% filename = sprintf('%s/liver_cluster.txt',outdir);
% fid = fopen(filename,'a+');
% fprintf(fid,'%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d \n',clusterListUsed(:, pos));
% fclose(fid);
end