is there any way to draw a vertical and horizontal line that pass through blobs centroid ?

I have a task of locating the upper lower and right and left cornet of a blob like this image where i have marked the points as red points
now i can plot centroid like this
s = regionprops(binaryImage, 'centroid');
centroids = cat(1, s.Centroid);
figure,imshow(binaryImage);hold(imgca,'on'); plot(imgca,centroids(:,1), centroids(:,2), 'r*','MarkerSize', 10, 'LineWidth', 3);
is it possible to find the other four points like drawing a line vertically and horizontally and some how find the intersecting points like this image and plot the four points
please help me any one ...i am not much good in math so code example will be helpful..

댓글 수: 1

This is works only for 1 dimensional matrix. how it is suitable for binary image because it consists of only two values such as 0 and 1. if it is possible, please put up the code.

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

답변 (2개)

Round the centroid to the nearest integer row and column, then extract that and use find
centroidColumn = round(xCentroid);
centroidRow = round(yCentroid);
% Extract
oneColumn = binaryImage(:, centroidColumn);
% Get top and bottom row
topRow = find(oneColumn, 1, 'first');
bottomRow = find(oneColumn, 1, 'last');
% Extract
oneRow = binaryImage(centroidRow, :);
% Get left and right columns.
leftColumn = find(oneRow, 1, 'first');
rightColumn = find(oneRow, 1, 'last');

댓글 수: 3

sir this is my output
centroidColumn = round(xCentroid);
centroidRow = round(yCentroid);
% Extract
oneColumn = binaryImage(:, centroidColumn);
% Get top and bottom row
topRow = find(oneColumn, 1, 'first');
bottomRow = find(oneColumn, 1, 'last');
% Extract
oneRow = binaryImage(centroidRow, :);
% Get left and right columns.
leftColumn = find(oneRow, 1, 'first');
rightColumn = find(oneRow, 1, 'last');
imshow(binaryImage);
hold(imgca,'on');
plot(imgca,centroids(:,1), centroids(:,2), 'r*','MarkerSize', 10, 'LineWidth', 3);
plot(topRow, bottomRow, 'b*', 'MarkerSize', 10, 'LineWidth', 3);
plot(leftColumn, rightColumn, 'b*', 'MarkerSize', 10, 'LineWidth', 3);
hold(imgca,'off');
title('Perimeter on the original mouth');
and the output i got is
sir am i doing it wrong i.e the plotting because i am a newbie pls help
Does your image have a white boundary around it? It looks like it might. What are the values of topRow, etc.? I think you need to review this link first http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Anandkumar: See the answer I gave in http://www.mathworks.com/matlabcentral/answers/118197#answer_125775, which is a more complete program. It should help you. Also, don't forget to see Jos's answer (scroll below).

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

Here is one approach:
s = regionprops(binaryImage, 'centroid');
centroids = cat(1, s.Centroid);
columndata = binaryImage(:,centroids(:,1)) ;
ix = 1:numel(columndata)-1 ;
Ypos = find(columndata(ix) ~= columndata(ix+1))
Ypos = Ypos + [1 0] % correct for offset?
figure,
imshow(binaryImage);
hold on(imgca,'on');
plot(imgca,centroids(:,1), centroids(:,2), 'r*','MarkerSize', 10, 'LineWidth', 3);
plot(imgca, centroids(:,1),Ypos,'rs','markersize',10,'markerfacecolor','r') ;

질문:

2013년 12월 7일

댓글:

2014년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by