MATLAB: How to get the coordinates of the center of gravity of various triangles and rectangles on the image

center of gravityImage Processing Toolbox

I would like to get the center of gravity of various (size / gradient) triangles and rectangles drawn on one image. Is there any useful toolbox or functions to get it in MATLAB? In some triangles are partially out of image, only one or two angles are drawn on the image. I'd installed MATLAB last month and am a beginner, so if possible, could you please let me which toolbox/function I should use, with a sample code?

Best Answer

See my Image Segmentation Tutorial in my File Exchange. It does exactly that.