How I can develop this segmentation codes ? I am so close to exact shape
Mostra commenti meno recenti

I am using miasdatabase and this is mdb005 image segmentation process. I found this image in a scientific paper .
And part (c) shows exact segmentation . Actually I need part c . My codes is below and result is so close to part (c) but not exactly.
What can I do to get it ? I added mdb005 image on the attachment part.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear;
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
imgf=imread('mdb005.png');
if(size(imgf,3)>1)
imgf=rgb2gray(imgf);
end
img=imgaussfilt(imgf);
IM=img;
subplot(3,3,1),imshow(IM);
title('Original Image', 'FontSize', fontSize);
% Maximize the figure window.
set(gcf, 'Position', get(0, 'ScreenSize'));
axis square;
thresholdValue = 135;
binaryImage = IM > thresholdValue;
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Area');
% Get all the areas
allAreas = [measurements.Area];
[biggestArea, indexOfBiggest] = sort(allAreas, 'descend');
% Extract biggest
biggestBlob = ismember(labeledImage, indexOfBiggest(1));
% Convert to binary
biggestBlob = biggestBlob > 0;
subplot(3, 3, 2);
% figure,
imshow(biggestBlob, []);
axis on;
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
title('Final', 'fontSize', fontSize);
drawnow;
maskedGrayImage = imgf; % Initialize.
maskedGrayImage(~biggestBlob) = 0;
% Display the masked grayscale image.
subplot(3, 3, 3);
imshow(maskedGrayImage);
axis on;
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
title('Masked Gray Scale Image', 'fontSize', fontSize);
drawnow;
I_eq = adapthisteq(maskedGrayImage);
subplot(3,3,4),imshow(I_eq);
title('Equalized Image', 'FontSize', fontSize);
se = strel('disk',20);
Io = imopen(I_eq,se);
subplot(3, 3, 5);
imshow(Io)
title('Opening')
Ie = imerode(I_eq,se);
Iobr = imreconstruct(Ie,I_eq);
subplot(3, 3, 6);
imshow(Iobr)
title('Opening-by-Reconstruction')
Ioc = imclose(Io,se);
subplot(3, 3, 7);
imshow(Ioc)
title('Opening-Closing')
Iobrd = imdilate(Iobr,se);
Iobrcbr = imreconstruct(imcomplement(Iobrd),imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
subplot(3, 3, 8);
imshow(Iobrcbr)
title('Opening-Closing by Reconstruction')
fgm = imregionalmax(Iobrcbr);
subplot(3, 3, 9);
imshow(fgm)
title('Regional Maxima of Opening-Closing by Reconstruction')
se2 = strel(ones(5,5));
fgm2 = imclose(fgm,se2);
fgm3 = imerode(fgm2,se2);
fgm4 = bwareaopen(fgm3,10);
% I3 = labeloverlay(grayImage,fgm4);
figure,
subplot(2, 2, 1);
imshow(fgm4)
title('Modified Regional Maxima Superimposed on Original Image')
IM_cb = imclearborder(fgm4);
BW2 = bwareaopen(IM_cb, 200);
BW_filled = imfill(BW2, 'holes');
subplot(2, 2, 2);
imshow(BW_filled);
axis on;
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
title('Small Lines Eliminated', 'fontSize', fontSize);
Risposte (2)
yanqi liu
il 23 Nov 2021
0 voti
sir,use the code at 《Detection-of-Breast-Cancer-using-Neural-Networks-master》
the result is

7 Commenti
Ali Zulfikaroglu
il 23 Nov 2021
yanqi liu
il 24 Nov 2021
yes,sir,use some morphological process,get the result

Ali Zulfikaroglu
il 24 Nov 2021
yanqi liu
il 25 Nov 2021

clc; clear all; close all;
warning off all
a=imread('demo.jpg');
b=rgb2gray(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);
bw = im2bw(rgb2gray(Y));
bw = imclearborder(bw);
bw2 = imopen(bw, strel('line', round(size(bw,2)*0.05), 0));
bw3 = bwareafilt(bw2, 1);
be1 = PreProcessedImage;be2 = PreProcessedImage;be3 = PreProcessedImage;
be1(bw3) = 255;be2(bw3) = 0;be3(bw3) = 0;
be = cat(3,be1,be2,be3);
figure; montage({bw3,mat2gray(be)}, 'Size', [1 2], 'BackgroundColor', 'w', 'BorderSize', [2 2]);
Ali Zulfikaroglu
il 25 Nov 2021
yanqi liu
il 26 Nov 2021
yes,sir,because the image exist white block in upper right,may be use the image
to test
or upload your image to do some analysis
Ali Zulfikaroglu
il 26 Nov 2021
Image Analyst
il 26 Nov 2021
0 voti
I didn't read the paper but assuming you implemented the functions correctly, the problem may be that your image sizes don't match theirs and you need to adjust some of the image processing parameters like window sizes or min acceptable blob size or something like that.
Categorie
Scopri di più su Read, Write, and Modify Image in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
