remove double boundary at image border (bwareaopen, bwperim)
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
