# CENTER OF GRAVITY FROM A DIGITAL IMAGE

Hi,
I have an image of a black paper cut in a right angled traingle shape and placed on a sheet of white paper. Size of the image is 100x100
pixels. The triangle looks and has the dimensions as shown below. /| / | / | B b = length of side A / | h = length of side B /__| A
The region inside the trianlge is black (gray value of pixels might not be exactly 0's for all the pixels. It varies from pixels to pixel.) and region outside the triangle has pixels with gray value 255. By physics, i know that the center of gravity of this traingle should lie inside the triangle at a distance of b/3 to the left of side B and at h/3 above side A.
How can I get to this CG point, which will be a function of gray scale value and pixel location, by taking image as input?
My search on internet lead me to this: http://www.roborealm.com/help/Center%20of%20Gravity.php
The link provides me with some hint to my problem except for the fact that brighter pixels will exert more pull on the final COG location than darker pixels. I want the exactly opposite of this i.e( I need more pull from dark pixels). I dont want to thershold the image.
Any idea how I can do this?
Regards, Vishwas
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

Simply average up the position of all the black pixels. Or, as a slight refinement, compute a weighted average using the "blackness" of each pixel as the weight.

You'll find the subtraction operator (-) useful for fixing that.
Best, - Joe
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

Thanks Joe. I was able to get it.
Vish
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>

## Site Timeline

• ### What is meaning of doing calibration of a industrail robot?

• - previous thread in General Robotics Forum
• ### Servo drive signals for HP 7978 tape drive controller

• - last updated thread in General Robotics Forum
• ### OT Nuclear U-Boats; how do they condense the steam?

• - the site's last updated thread. Posted in ⏚ Electrical Engineering

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.