Tracing boundaries in a binary image

7 Ansichten (letzte 30 Tage)
Sid
Sid am 26 Jun. 2012
Hi guys,
The question relates to the tracing of a boundary in a binary image. What I am interested in doing are the following steps:
1) Determine the centroid of the image - This step is easy enough using regionprops.
2) Start tracing the boundary (clockwise or counterclockwise, doesn't matter), from the point where a line drawn parallel to the y-axis, and through the centroid, first crosses the boundary of the particle.
Please find a small sketch of what I would like to do at: http://i49.tinypic.com/2dsmr8k.png. The source image discussed in the previous link can be found at: http://i48.tinypic.com/312ig48.jpg
What I thought of doing was to identify the centroid, and shift the coordinate system so that the centroid is at the origin, and then try and trace the boundary starting from the point where the positive x-axis (where y=0) first intersects the boundary.
Please find below what I tried so far:
clc
clear all
set(0,'DefaultFigureWindowStyle','docked')
I = imread('blob.tif');
% please use the image at: http://i48.tinypic.com/312ig48.jpg
BW = im2bw(I, graythresh(I)); % threshold the image
[B,L,N,A] = bwboundaries(BW); % identify the boundary
centroid = regionprops(BW,'Centroid'); % regionprops centroid
Cx = centroid.Centroid(1,1); % x-coordinate of the centroid
Cy = centroid.Centroid(1,2); % y-coordinate of the centroid
% extract the border of the blob interested, as opposed to the image frame.
border = B{2};
% shift values so that the centroid is the new origin.
border_adj_x = (border(:,1)-Cx);
border_adj_y = (border(:,2)-Cy);
border = [border_adj_x,border_adj_y];
Where I got stuck was trying to start tracing the boundary at the location identified in step 2 above (or at http://i49.tinypic.com/2dsmr8k.png). I guess another question to ask would be, is there a way to get bwboundaries to start tracing always at a given location?
Any help would be much appreciated.
Thanks in advance.

Antworten (1)

Image Analyst
Image Analyst am 27 Jun. 2012
Why do you want to do that? I don't think it's necessary for anything as far as I can tell. Regardless, even if you did, bwboundaries gives you everything you need to do that task. You can use circshift() on the boundary coordinates returned by bwboundaries() to put the desired element as the first element. No need to trace again with bwtraceboundary(). But again, why bother? Who cares where the starting element is?

Community Treasure Hunt

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

Start Hunting!

Translated by