What is the mistake which I did in this Breast cancer detection codes especially on segmentation part ?

1 vue (au cours des 30 derniers jours)
There is a link above breast cancer detection system .
I tried to use code , I couldn't manage to apply exactly especially image segmentation part.
I follow codes in the link guidemo.m part and wrote this codes . What are my mistakes ?
Or how can I use codes in the link exactly ?
I inserted image mdb005.png
clear;
close all;
a=imread('C:\Users\Ali\Desktop\all-mias\mdb005.png');
b=im2gray(a);
%adaptive median filter part
NoisyImage=b;
NoisyImage=double(b);
[R C P]=size(NoisyImage);
OutImage=zeros(R,C);
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
PreProcessedImage(i,j)= Zxy;
else
PreProcessedImage(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);
PreProcessedImage(i,j)= Zmed2;
else
PreProcessedImage(i,j)= Zmed;
end
end
end
end
end
imshow(PreProcessedImage,[])
%Segmentation part
Y=double(PreProcessedImage);
k=2; % k: number of regions
g=2; % g: number of GMM components
beta=1; % beta: unitary vs. pairwise
EM_iter=10; % max num of iterations
MAP_iter=10; % max num of iterations
% fprintf('Performing k-means segmentation\n');
[X,GMM,ShapeTexture]=image_kmeans(Y,k,g);
[X,Y,GMM]=HMRF_EM(X,Y,GMM,k,g,EM_iter,MAP_iter,beta);
Y=Y*80;
Y=uint8(Y);
figure, imshow(Y);
  2 commentaires
Ali Zulfikaroglu
Ali Zulfikaroglu le 21 Nov 2021
Modifié(e) : Ali Zulfikaroglu le 21 Nov 2021
@Image Analyst I am still trying to apply segmentation part from 1,5 years .But I couldn't manage . Could you please look at codes . I have thesis , If I don't manage I have to quit. I just need this mdb005 image exact segmentation codes.
Image Analyst
Image Analyst le 21 Nov 2021
@Ali Zulfikaroglu it's not my code. I suggest you contact the author. He says he's a mentor so he should be willing to help you with his own code.

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 21 Nov 2021
In a couple of places, you end the indexing too early -- A((i)),((j)) where you should have had A((i),(j))
Cleaned up version of the code is attached.
Please re-examine your code. You have
if ((R > 4 && R < R-5) && (C > 4 && C < C-5))
What value of R exists such that R < R-5 could be true ? Subtract R from both sides and you see you are asking 0 < -5 which is always false.

yanqi liu
yanqi liu le 22 Nov 2021
clc; clear all; close all;
warning off all
a=imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/808504/mdb005.png');
a=imcrop(a,[270 147 377 533]);
b=im2gray(a);
%adaptive median filter part
NoisyImage=b;
NoisyImage=double(b);
[R, C, P]=size(NoisyImage);
OutImage=zeros(R,C);
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
PreProcessedImage(i,j)= Zxy;
else
PreProcessedImage(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);
PreProcessedImage(i,j)= Zmed2;
else
PreProcessedImage(i,j)= Zmed;
end
end
end
end
end
imshow(PreProcessedImage,[])
%Segmentation part
Y=double(PreProcessedImage);
k=2; % k: number of regions
g=2; % g: number of GMM components
beta=1; % beta: unitary vs. pairwise
EM_iter=10; % max num of iterations
MAP_iter=10; % max num of iterations
% fprintf('Performing k-means segmentation\n');
[X,GMM,ShapeTexture]=image_kmeans(Y,k,g);
if ndims(Y) == 2
Y = cat(3,Y,Y,Y);
end
[X,Y,GMM]=HMRF_EM(X,Y,GMM,k,g,EM_iter,MAP_iter,beta);
Y=Y*80;
Y=uint8(Y);
figure, imshow(Y);
  4 commentaires
Image Analyst
Image Analyst le 23 Nov 2021
@Ali Zulfikaroglu, so what did the authors (not yanqi, but the people who wrote the functions you found) say when you contacted them? Did they ignore you or tell you to get lost? Or did you not even try to contact them? It's possible that their algorithm was not meant for images such as yours, so ask them if they think it should work.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by