MATLAB: How can i get each coordinates of binary image

binarycoordinatesImage Processing Toolbox

how can i get the each coordinates that shown in this image http://www.freeimagehosting.net/pd85c (up, down, right, left and center)

Best Answer

Find the centroid with regionprops(). See my Image Segmentation Tutorial if you don't know how. Then convert the centroid to integer to get the row and column.
centroidColumn = int32(centroid(1)); % "X" value
centroidRow = int32(centroid(2)); "Y" value.
Then extract a row or column and use find to find the first and last element that's set:
middleColumn = binaryImage(:, centroidColumn);
topRowY = find(middleColumn, 1, 'first'); % Find top.
bottomRowY = find(middleColumn, 1, 'last'); % Find bottom.
middleRow = binaryImage(centroidRow, :);
leftColumnX = find(middleRow, 1, 'first'); % Find left.
rightColumnX= find(middleRow, 1, 'last'); % Find right.