center of mass of pixels in grayscale image
Asked Answered
C

2

7

I'm working on a program that lets the user draw a digit in a "scribbling area" and with the press of a button the application will predict the digit that he entered, using a neural net classifier.

Now, to train the neural net, I used MNIST database which specifies the following: "images from NIST were size normalized to fit in a 20x20 pixel box while preserving their aspect ratio [...] the images were centered in a 28 x 28 image by computing the center of mass of the pixels".

The problem that I'm facing is that after resizing the digit that the user drew in the scribbling area to a size of 20 x 20, I need to compute the center of mass of the pixels so I can center it in the middle of the 28 x 28 image.

How can I compute that ?

Chetnik answered 25/5, 2016 at 22:47 Comment(0)
Z
8

"Center of mass" (for binary images) is a bit convoluted way of saying "mean value across each dimension". In other words - take all x coordinates and average them - and you got x coordinate of your "center of mass", the same for y.

In python, for data in X it would be

center_of_mass = X.mean(axis=0)

If you have pixels' intensities you can use them as "weights" thus leading to weighted averages, that's all.

Zelikow answered 25/5, 2016 at 22:50 Comment(0)
R
-3

Here, let me search that for you ...

You multiply the distance from the mean by the weight of each pixel -- almost certainly 1.0 for your work. In short, take the mean of all x coordinates and the mean of all y coordinates; that gives you the center of mass.

Rules answered 25/5, 2016 at 22:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.