matlab: find outer edges of objects in a picture

﹥>﹥吖頭↗ 提交于 2020-01-13 04:55:51

问题


I have a picture contains blood smear. What I want to do is to detect the edges of those cells.

I first convert this color image into grayscale image and then fill holes in those cells. And I use the edge() function in matlab to detect edges. Since you can observe the inner part of some cell is much lighter, so there are edges detected inside one cell. The result is shown below:

So is there any methods that only the outer edges of those cells can be detected?

My code is shown below:

I = imread('film02_pattern.jpg'); 
t1=graythresh(I);
k1=im2bw(I,t1);
k1=~k1;
se = strel('disk',1);
k1=imfill(k1,'holes');
imshow(k1);
k1=~k1;
bw = edge(k1,'canny',[],sqrt(2));
figure,imshow(bw);

回答1:


To deal with the contours that intersect with the edge of the image, you can use use bwconncomp to separate the background from the unfillable contours. Then, instead of edge, you can get the outer perimeters only via bwperim, but that is just a variation.

I = imread('asEW3.jpg');
t1=graythresh(I);
k1=im2bw(I,t1);
k1=~k1;
se = strel('disk',1);
k0=imfill(~k1,'holes');            % new
cc = bwconncomp(k0);               % new
k0(cc.PixelIdxList{1})=0;          % new
k1 = imfill(k1,'holes');
cellMask = k1 | k0;                % new
cellContours = bwperim(cellMask);  % new
cellContours2 = edge(cellMask,'canny',[],sqrt(2)); % new
k1=~k1;
bw = edge(k1,'canny',[],sqrt(2));
figure,imshow(bw); title('original')
figure,imshow(cellContours); title('new, bwperim()')
figure,imshow(cellContours2); title('new, edge()')

Using connected components seems a bit like overkill, but there doesn't seem to be an easier way to distinguish background from the centers of cells that hit the edge of the image, at least not while imfill is unable to fill those contours.



来源:https://stackoverflow.com/questions/20433882/matlab-find-outer-edges-of-objects-in-a-picture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!