remove double boundary at image border (bwareaopen, bwperim)

조회 수: 3 (최근 30일)
Christoph
Christoph 2013년 1월 14일
I am using a Matlab example to find the contours in an image and outline them. This technique works very well for all structures on the inside of the image. If one of the structures (finger-like electrodes under the microscope) is cut at the image's border the routine tries to close it, resulting in a "double contour" of the finger.
I need to make the program realize that the structure is in fact at the border and the outer contour should be the only one detected.
Using imclearborder I can remove the contours of objects affected, but this would affect to many of the shapes I am trying to trace!
I tried uploading an snapshot of the problem, but my university seems to be blocking every site I know and tried, so I can only attach the code (pretty straight forward from the ML examples) and abused my profile photo for the image. Sorry for that.
function [ output_args ] = process_sem( I_sem, diamondsize, bwareaopensize, bwperimconnectors )
%Finds outlines in a grayscale image and displays them in overlay
J = adapthisteq(I_sem,'NumTiles', [8 8], 'clipLimit', 0.002,'Distribution', 'exponential');
h1 = fspecial('gaussian',5,5); % set up a Gaussain filter
Im1 = imfilter(J,h1,'replicate'); % filter the signal by Gaussian filter
Im2 = im2bw(Im1,graythresh(Im1)+0.1);
se=strel('diamond',diamondsize);
Im2=imdilate(Im2,se);
Im2=imerode(Im2,se);
%If border-connection should be removed uncomment the following line
%clearbordersconn=4;
%Im2=imclearborder(Im2,clearbordersconn);
se90 = strel('line', 3, 45);
se0 = strel('line', 3, 0);
Im2= imdilate(Im2, [se90 se0]);
Im3 = bwareaopen( Im2, bwareaopensize);
Im3=imfill(Im3, 'holes');
%final smoothing
seD = strel('diamond',1);
Im2 = imerode(Im2,seD);
Im2 = imerode(Im2,seD);
%final smoothing end
Im3outline = bwperim(Im3,bwperimconnectors);
Segout = I_sem;
Segout(Im3outline) = 255;
figure;imshow(Segout), title('outlined original image');
[imx,imy] = gradient(double(Im3outline),1.0);
output_args = [imx, imy, Im3 ];
Any help is very much appreciated!
Kind regards, Chris

채택된 답변

Image Analyst
Image Analyst 2013년 1월 14일
Why would imclearborder() change the contours of the remaining objects? Any object touching the border you want to remove because you don't have the entire object in the field of view. Unless you're talking about the insides of those rod-shaped things and you want to keep the inside even if the bright perimeter slightly touches the edge. It would be good for you to somehow find a way to upload an image. How about a site on your university's own server? It should not complain about that.
  댓글 수: 5
Image Analyst
Image Analyst 2013년 1월 15일
Sure - you have all the coordinates. Use norm(), hypot() or the Pythagorean theorem.
Christoph
Christoph 2013년 1월 16일
Thank you so much for your help! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by