Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Different results with imaqCalcCoeff(IMAQ_CENTER_MASS_X) and my own funcion

Hi,

I have been using imaqCalcCoeff(IMAQ_CENTER_MASS_X and Y), but now I have the need of making my own function for calculating center of mass.

I looked at IMAQ Vision Concepts Manual, and tried to implement this into my own function - getNormalizedCenterOfMass().

But I cannot get the same results as imaqCalcCoeff. These are come typical values:

//---------------------------------------------------

X
imaqCalcCoeff() myOwnFunc()
20.172413 17.172413
17.851978 15.851977
26.271233 23.271233
25.214842 22.214842
23.959467 21.959467
19.882427 15.882427
23.591806 20.591806
18.521740 15.521739
26.080259 22.080259
2
3.031824 21.031824
19.389500 16.389500
20.677216 16.677216
18.910271 15.910272
24.396191 21.396191
20.141012 17.141012
17.860386 15.860386
26.208996 24.208996
25.198561 22.198561
24.015152 22.015152
19.801527 15.801527



Y
imaqCalcCoeff() myOwnFunc()
19.287716 16.287716
19.541243 16.541243
26.837261 23.837261
25.986237 22.986237
26.697519 22.697519
18.362831 15.362832
22.283833 20.283833
17.447958 14.447958
24.282200 21.282200
22.533947 20.533947
18.340660 15.340659
18.593882 16.593882
19.925619 15.925620
25.661587 22.661587
19.379978 16.379978
19.589104 16.589104
26.859571 23.859571
26.061789 23.061789
26.697577 22.697577
16.441475 15.441476


//---------------------------------------------------

I have attached a C++ file containing my function.

Does
anybody know what I am doing wrong? Have I overseen something?

-Thanks!

Torbjørn
0 Kudos
Message 1 of 4
(3,216 Views)
Your current version will only work for binary images. It ignores the magnitude of the pixel intensity. You were more on track with the code you commented out, where you sum the numerator and denominator. Sum (i*pix) / Sum (pix) should give you the correct center of mass weighted by the pixel intensity.

I do find it interesting that the difference between your current results and the IMAQ results is always an integer value. Perhaps IMAQ is just using a different frame of reference than you expect.

Bruce
Bruce Ammons
Ammons Engineering
Message 2 of 4
(3,216 Views)
I looked at your code again. Are you just calculating withing an ROI? If so, you need to include the X and Y offset of the ROI from the original image. I am guessing that your ROI is just a few pixels from the origin, which is why your result is always a small integer value less than the IMAQ result.

Bruce
Bruce Ammons
Ammons Engineering
0 Kudos
Message 3 of 4
(3,216 Views)
Thank you very much, Bruce!

You are right in all your comments! I had forgotten to add the top and left corner of the ROI...
I've also added support for grayscale, as you suggested (I've attached the updated code just for reference).

You'll be rewarded in heaven for all your help 🙂

Cheers,
Torbjørn
0 Kudos
Message 4 of 4
(3,216 Views)