Using SVM on Test data gives the same result for different classes

3 ビュー (過去 30 日間)
Warid Islam
Warid Islam 2020 年 6 月 19 日
編集済み: Warid Islam 2020 年 6 月 19 日
Hello,
I am using SVM to classify breast tissues. Training was performed on 16 Benign and 16 Malignant tissues. However, when I applied my model on my test data set which had 4 benign and 4 malignant images, all the results show me the same output(benign) for all the test images. The Labels.xlsx file shows the feature extracted by the Gray-Level Cooccurence Matrix(GLCM) of the 32 images and is used as the training set.Classes 1 and 2 corresponds to Benign and Malignant tissues respectively. Ben 1 and Ben5 are one of Benign and Malignant test image respectively. Please find my code below: Any help would be very much appreciated.
inp=input('Enter Image:');
i=imread(inp);
try
i=rgb2gray(i);
end
z=im2bw(i,0.1);
figure(2)
imshow(z);title('Original B&W')
info=regionprops(z);
a=cat(1,info.Area);
[m,l]=max(a);
X=info(l).Centroid;
bw2=bwselect(z,X(1),X(2),8);
i=immultiply(i,bw2);
figure(3)
imshow(i);
title('Getting the Breast and Muscle')
%% Deleting Black Ground
% We will delete the black corners
% So that we can select the muscle
% using bwselect
% convert to B&W first time
[x,y]=size(z);
tst1=zeros(x,y);
% detect empty rows
r1=[];
m=1;
for j=1:x
if z(j,:)==tst1(j,:)
r1(m)=j;
m=m+1;
end
end
% detect empty columns
r2=[];
m=1;
for j=1:y
if z(:,j)==tst1(:,j)
r2(m)=j;
m=m+1;
end
end
% Deleting
i(:,r2)=[];
i(r1,:)=[];
figure(4)
imshow(i);title('after deleting background');
%% Deleting the Muscle
if i(1,1)~=0
c=3;
r=3;
else
r=3;
c=size(i,2)-3;
end
z2=im2bw(i,0.5);
bw3=bwselect(z2,c,r,8);
bw3=~bw3;
ratio=min(sum(bw3)/sum(z2));
if ratio>=1
i=immultiply(i,bw3);
else
z2=im2bw(i,0.75);
bw3=bwselect(z2,c,r,8);
ratio2=min(sum(bw3)/sum(z2));
if round(ratio2)==0
lvl=graythresh(i);
z2=im2bw(i,1.75*lvl);
bw3=bwselect(z2,c,r,8);
bw3=~bw3;
i=immultiply(i,bw3);
else
bw3=~bw3;
i=immultiply(i,bw3);
end
end
figure(5)
imshow(i)
title('Getting only the Breast')
J = imnoise(i,'salt & pepper', 0.02);
NoisyImage=J;
[R C P]=size(NoisyImage);
OutImage=zeros(R,C);
figure;
% imshow(J);
Zmin=[];
Zmax=[];
Zmed=[];
for i=1:R
for j=1:C
if (i==1 & j==1)
% for right top corner[8,7,6]
elseif (i==1 & j==C)
% for bottom left corner[2,3,4]
elseif (i==R & j==1)
% for bottom right corner[8,1,2]
elseif (i==R & j==C)
%for top edge[8,7,6,5,4]
elseif (i==1)
% for right edge[2,1,8,7,6]
elseif (i==R)
% // for bottom edge[8,1,2,3,4]
elseif (j==C)
%// for left edge[2,3,4,5,6]
elseif (j==1)
else
SR1 = NoisyImage((i-1),(j-1));
SR2 = NoisyImage((i-1),(j));
SR3 = NoisyImage((i-1),(j+1));
SR4 = NoisyImage((i),(j-1));
SR5 = NoisyImage(i,j);
SR6 = NoisyImage((i),(j+1));
SR7 = NoisyImage((i+1),(j-1));
SR8 = NoisyImage((i+1),(j));
SR9 = NoisyImage((i+1)),((j+1));
TempPixel=[SR1,SR2,SR3,SR4,SR5,SR6,SR7,SR8,SR9];
Zxy=NoisyImage(i,j);
Zmin=min(TempPixel);
Zmax=max(TempPixel);
Zmed=median(TempPixel);
A1 = Zmed - Zmin;
A2 = Zmed - Zmax;
if A1 > 0 && A2 < 0
% go to level B
B1 = Zxy - Zmin;
B2 = Zxy - Zmax;
if B1 > 0 && B2 < 0
OutImage(i,j)= Zxy;
else
OutImage(i,j)= Zmed;
end
else
if ((R > 4 && R < R-5) && (C > 4 && C < C-5))
S1 = NoisyImage((i-1),(j-1));
S2 = NoisyImage((i-2),(j-2));
S3 = NoisyImage((i-1),(j));
S4 = NoisyImage((i-2),(j));
S5 = NoisyImage((i-1),(j+1));
S6 = NoisyImage((i-2),(j+2));
S7 = NoisyImage((i),(j-1));
S8 = NoisyImage((i),(j-2));
S9 = NoisyImage(i,j);
S10 = NoisyImage((i),(j+1));
S11 = NoisyImage((i),(j+2));
S12 = NoisyImage((i+1),(j-1));
S13 = NoisyImage((i+2),(j-2));
S14 = NoisyImage((i+1),(j));
S15 = NoisyImage((i+2),(j));
S16 = NoisyImage((i+1)),((j+1));
S17 = NoisyImage((i+2)),((j+2));
TempPixel2=[S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15,S16,S17];
Zmed2=median(TempPixel2);
OutImage(i,j)= Zmed2;
else
OutImage(i,j)= Zmed;
end
end
end
end
end
imshow(OutImage,[]);
title('Adaptive Median Filter')
disp('exit');
%%GLCM Feature Extraction
% Y=rgb2gray(OutImage);
Y=double(OutImage);
glcm2=graycomatrix(Y);
stats = GLCM_Features1(glcm2,0);
stats=stats';
ExtractedFeaturesm16=stats;
% save('ExtractedFeaturesm16.mat')
statsTable = struct2table(stats);
% statsArray = table2array(statsTable);
statsArray1 = table2array(statsTable);
% statsArray'
TestSet=statsArray1;
Training=Labels1(1:32,1:22);
class=Labels1(:,23);
SVMmodel=fitcsvm(Training,class);
result = predict(SVMmodel, TestSet);
if result == 1
helpdlg(' Benign ');
disp(' Benign Tissue ');
else
helpdlg(' Malignant ');
disp('Malignant Tissue');
end

回答 (0 件)

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by