how to find centroid?
조회 수: 4 (최근 30일)
이전 댓글 표시
hi, i've an image having three objects. i was able to detect one of the object. now i need to find the centroid of the detected object. i used s=regionprops(bw,'centroid'); centroid=cat(1,s.centroid);
it give me an error : Reference to non-existent field 'majoraxislength'. please help. mail me at aliz.inam@gmail.com
댓글 수: 0
채택된 답변
Guillaume
2014년 9월 22일
Welcome to matlab absurd handling of case sensitivity.
While the arguments you pass to regionprops are not case sensitive, accessing the fields of a structure is. The fields of the structure returned by your regionprops are 'Area', 'Centroid' and 'BoundingBox', thus you need to access the fields with:
s(x).Centroid
s(x).Area
s(x).BoundingBox
I'm not sure what you're doing with your plot commands though, plot(s(x).Centroid, s(x).Area, s(x).BoundingBox); wouldn't have worked anyway, so you may have to ask another question for that.
댓글 수: 0
추가 답변 (1개)
Image Analyst
2014년 9월 21일
You forgot to include the error message! You just snipped out a small part of it and told us that, but the crucial part - the line of code that caused the error - you forgot to include. Please include all the red text . Don't snip out any of it. Somewhere you are trying to reference s(index).majoraxislength. MATLAB is case sensitive so there could be a field called MajorAxisLength on s if you asked for it. But you did not, you just asked for 'Centroid'. Perhaps you want:
s = regionprops(bw, 'centroid', 'MajorAxisLength');
And if you post it here, we'll solve it here. No one is going to email you, and just leave this thread hanging unfinished.
댓글 수: 2
Image Analyst
2014년 9월 22일
As I said above, MATLAB is case sensitive - note how I changed the case of MajorAxisLength vs. what you had. Anyway, I don't see you asking for that in your code above. Did you see my suggestions in my answer above? You must have asked tried to reference majoraxislength (with wrong capitalization) but failed to ask for it in regionprops like I suggested. Also, when trying to reference the Centroid, Area, and BoundingBox fields, you didn't pay any attention to the case of the letters like I suggested. Please read my answer again, as well as Guillaume's, and you should be able to fix the problem. And like he said, we have no idea what you're trying to plot or display - maybe you want fprintf('%f ', s(x).centroid, s(x).area, s(x).boundingbox); instead of plot.
참고 항목
카테고리
Help Center 및 File Exchange에서 Geographic Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!