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!