Help with regionprops and centroid parts of an image

1 回表示 (過去 30 日間)
Jason
Jason 2016 年 3 月 10 日
コメント済み: Jason 2016 年 3 月 10 日
Hi. I have an image called ROI. I also have the location of the maximum intensity values on a line across the image (shown by red dots)
I wanted to then use these x,y locations to seed a centroid based calculation using region props. I have attempted this, but the values i get are shown by the blue crosses. I can't see my error.
I call my centroid funcion via:
[cenX,cenY,val]=getCentroid(handles,cx(xxx),cy(xxx),ROI);
where cx(xxx) and cy(xxx) are the coordinates of the red dots. My function is:
function [cenX,cenY,val]=getCentroid(handles,xguess,yguess,img)
%Calculates the centroid by creating a matrix around the guess values
%on the image img. Also returns intensity at that location
%n must be odd. Then applies regionprops to calc centroid
xc=xguess
yc=yguess
n=1; %number of pixels surounding current location (xguess,yguess) to calc centroid
ROI = img(yc-n:yc+n, xc-n:xc+n) % This is the ROI (indexing is (ymin:ymax, xmin:xmax)
C=regionprops(true(size(ROI)), ROI, 'WeightedCentroid');
CN=C.WeightedCentroid
cenX=CN(1)+xc
cenY=CN(2)+yc
val=ROI(round(CN(1)),round(CN(2)))
(I then want to pass the first and last values of these centroided locations to improfile to obtain a linescan thru the image.)

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 3 月 10 日
val=ROI(round(CN(2)),round(CN(1)))
It slipped your mind that x is columns not rows.
  1 件のコメント
Jason
Jason 2016 年 3 月 10 日
Thankyou, but also the actual locations seem to be wrong. I have changed them:
CN=C.WeightedCentroid
cenX=CN(2)+xc-1
cenY=CN(1)+yc-1
..but still apear way off.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by