Thanks for your response.
Unfortunately, I do mean the center of gravity.
I have images that I have automatically sort-of removed their BG.
Here's an example -
By finding the center of gravity, I will be able to place the product in the center.
I don't need an exact center. Even the roughest estimation would be great.
In most cases, the BG leftovers are within a very tight color range, while the product is colorful, detailed and in focus, maybe using some color recognition formula can help?
Looking for the center of gravity and moving it to the center of the canvas is a bad idea to begin with. If you did a perfect job removing the background of your sample product above and move its center of gravity to the center of the canvas you would be moving part of your product off canvas.
In most cases it will work just fine, as most product images are will fit in the document if centered. (maybe not the one in the example, but that's ok).
Or have I misunderstood your response?
In all cases if you did a better job removing the background moving the selection to the center of the canvas would center your product. In you poor example it would result in just moving your product yet lower on canvas. However it will never move part of your product off canvas. Moving the center of gravity of a product to the center of the canvas can move part of the product off canvas if the product's center and center of gravity are not near each other.
Think about it its like select all. Then align layer to vertical center and horizontal center your product layer is centered over the canvas. Your product is centered.
I appreciate your time and intention.
Nevertheless, this is a scripting forum, and I am asking a scripting related question.
If I was interested in a design advise, I would have done it somewhere else.
I happen to like the BG leftovers the way they are.
Forgive me please I thought you might want to do something that would work. Will not make the mistake again.