MATLAB: How to find centroid

centroidImage Processing Toolboxregionprops

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

Best Answer

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.