How to show the segmented image with GUI,using guide

3 views (last 30 days)
Dear sir,
i have faced the following problem.Help me.Thanks all.
function pushbutton2_Callback(hObject, eventdata, handles)
if isfield(handles,'image')
% do stuff
Image=handles.image;
% Convert RGB image to gray scale image
%Main Program
I=Image;
k=1;p=1;
dim=ndims(I);
if dim==2
I=I;
else if dim==3
I=rgb2gray(I);
else fprintf('Nothing \n');
end
end
%imtool(I);
I=uint8(I);
I2=imopen(I,strel('disk',3));%before 3
%figure,imshow(I);
M=medfilt2(I2,[3 3]);
%imtool(M);
G=imgaussfilt(M,1);
%imtool(G);
%image=imsharpen(G);
AdjImg=imadjust(G);
%imtool(AdjImg);
initialT=mean2(AdjImg);
T=initialT;
Image=AdjImg;
[row,col]=size(Image);
newT=0;
while T-newT~=0
for i=1:row
for j=1:col
if Image(i,j)>=T;
Image(i,j)=Image(i,j);
else Image(i,j)=0;
end
end
j=j+1;
end
i=i+1;
%figure,imshow(Image);
m1=mean2(Image);
%m2=mean2(image);
newT=(m1)/2;
formerT=T;
T=newT;
newT=formerT;
end
%figure,imshow(Image);
%imtool(image);
[R,C]=size(Image);
for i=1:R
for j=1:C
if Image(i,j)==0
Image(i,j)=0;
else Image(i,j)=255;
end
end
j=j+1;
end
i=i+1;
Final=Image;
%imtool(Final);
openImg1=imopen(Final,strel('disk',4));% for 273.jpg //ealier 6 & 8
%imtool(openImg);
EdgeImg=edge(openImg1,'canny');
%figure,imshow(EdgeImg);
ThinnedImg=bwmorph(EdgeImg,'thin');
%figure,imshow(ThinnedImg);
Td=uint8(ThinnedImg);
Constructed=Td|openImg1;
%figure,imshow(Constructed);
OPENimg=double(Constructed);
%figure,imshow(OPENimg);
[ROW,COL]=size(OPENimg);
cropped = openImg1(1:ROW,1:COL); %%Crop region of interest
%imtool(cropped);
thresholded = cropped==0;%%Threshold to isolate lungs
%figure,imshow(thresholded);
%imtool(thresholded);
clearThresh = imclearborder(thresholded); %%Remove border artifacts in image
%figure,imshow(clearThresh);
ClosedClear=imclose(clearThresh,strel('disk',5));
%imtool(clearThresh);
Liver = bwareaopen(ClosedClear,100); %Remove objects less than 100 pixels
%figure,imshow(Liver);
Liver1 = imfill(Liver,'hole'); % fill in the vessels inside the lungs
%figure,imshow(Liver1);
Liver1=uint8(Liver1);
nodule=Liver1.*cropped;
%imtool(nodule);
nodule1=imopen(nodule,strel('disk',5));% 6 ,7and 8 before
%imtool(nodule1);
nodule1a=imclose(nodule1,strel('disk',1));
nodule1a=logical(nodule1a);
nodule2=bwareafilt(nodule1a,[1 4500]);%extract objects whose values are in these range
%imtool(nodule2);
nodule2a=bwareaopen(nodule2,150); % ealier 150,changed for 322.jpg
%imtool(nodule2a);
Nodule=nodule2a;
axes(handles.axes2)
imshow(Nodule)
[label, Nnodule]=bwlabel(Nodule,8);%label is labeled matrix that includes labeled objects
if Nnodule==1
I=double(I);
Nodule= Nodule.* I;
NoduleDatabase{k,p}=Nodule;
else if Nnodule>1
if Nnodule==2
[Row1, Col1]=find(label==1);
[Row2, Col2]=find(label==2);
NoduleOne=bwselect(label,Col1,Row1,8);
NoduleTwo=bwselect(label,Col2,Row2,8);
I=double(I);
NoduleOne= NoduleOne.* I;
NoduleTwo=NoduleTwo.*I;
NoduleDatabase{k,p}=NoduleOne;
NoduleDatabase{k,p+1}=NoduleTwo;
end
if Nnodule==3
[Row1, Col1]=find(label==1);
[Row2, Col2]=find(label==2);
[Row3, Col3]=find(label==3);
NoduleOne=bwselect(label,Col1,Row1,8);
NoduleTwo=bwselect(label,Col2,Row2,8);
Nodule3=bwselect(label,Col3,Row3,8);
I=double(I);
NoduleOne= NoduleOne.* I;
NoduleTwo=NoduleTwo.*I;
Nodule3= Nodule3.* I;
NoduleDatabase{k,p}=NoduleOne;
NoduleDatabase{k,p+1}=NoduleTwo;
NoduleDatabase{k,p+2}=Nodule3;
end
if Nnodule>3
[Row1, Col1]=find(label==1);
[Row2, Col2]=find(label==2);
[Row3, Col3]=find(label==3);
[Row4, Col4]=find(label==4);
NoduleOne=bwselect(label,Col1,Row1,8);
NoduleTwo=bwselect(label,Col2,Row2,8);
Nodule3=bwselect(label,Col3,Row3,8);
Nodule4=bwselect(label,Col4,Row4,8);
I=double(I);
NoduleOne= NoduleOne.* I;
NoduleTwo=NoduleTwo.*I;
Nodule3= Nodule3.* I;
Nodule4=Nodule4.*I;
NoduleDatabase{k,p}=NoduleOne;
NoduleDatabase{k,p+1}=NoduleTwo;
NoduleDatabase{k,p+2}=Nodule3;
NoduleDatabase{k,p+3}=Nodule4;
end
%imtool(Nodule);imtool(NoduleOne);imtool(NoduleTwo);
end
end
b=NoduleDatabase;
end
end

Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!