Image not generated after separation..?
1 次查看(过去 30 天)
显示 更早的评论
In this code finally image is not being generate. I have following code... I want to detect Lung cancer.
% This code reads image , extract the part of lung
% and then dispaly the result.
%%Read the image data
im=imread('LungSeg_01.png');
im=rgb2gray(im);
[row column]=size(im);
imshow(im)
title('the Original Image')
%%Get the threshold for segmentation using iteration process
%get the maximun and minimun value of the vector
Gmax=max(max(im));
Gmin=min(min(im));
%supposing T0 is the threshold
T0=(Gmax+Gmin)/2;
%mean of both parts,then get the new threshold T1
M0=mean(im(find(im<T0)));
M1=mean(im(find(im>=T0)));
T1=(M0+M1)/2;
%get the appropriate threshold
%by no more then 5000 loops
for i=1:5000 %here gives the maximun numbers of trying
if T1~=T0
T0=T1;
M0=mean(im(find(im<T0)));
M1=mean(im(find(im>=T0)));
T1=(M0+M1)/2;
else break
end
end
thresh=T0
%%Segmentation
for index=1:row*column
if im(index)>thresh
im(index)=0;
end
end
figure,imshow(im)
title('After Segmentation')
%make a copy,using to get the position
im0=im;
%%Extract
%divided the image into 2 parts
%foreground with 1,background with 0
for index=1:row*column
if im0(index)~=0
im0(index)=1;
end
end
%transform im0 into 'logical',then label
%the part of lung has been labelled with 20
im0=logical(im0);
im0=bwlabel(im0);
%display the relational pixel
for i=1:row*column
if im0(i)~=20
im(i)=0;
end
end
figure,imshow(im)
title('After Extract')
3 个评论
Walter Roberson
2015-7-2
What reason do you have to expect that there will definitely be 20 or more different labels?
回答(1 个)
drummer
2015-7-2
uHm... Did you try to set a displayrange in your imshow?
I don't know... it should work.
figure,imshow(im, 'DisplayRange', [])
1 个评论
Walter Roberson
2015-7-2
[] is the default for imshow(). imagesc() uses the same as imshow(). It is image() that defaults to a different display range.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biomedical Imaging 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!