LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

IMAQ Particle Analysis Reports VI

Hello,

 

I have written a programme that can take an image, resize it, theshold it and generate an array of particle locations using the IMAQ particle analysis VI. The programme works fine but I was wondering if anyone can answer some questions I have regarding some of the details of how this VI works:

 

  1. How does the IMAQ Particle Analysis Reports VI calculate the centre of mass of the particles? Naively I would assume it would be the same as the IMAQ Centroid VI which uses the formula x=Sum(x*PixelValue)/Sum(PixelValue), y=Sum(y*PixelValue)/Sum(PixelValue), however in this case it finds the centre of mass of the entire image and not of the individual particles. Does it therefore apply these formulas to automated regions of interest to generate the list of centroided coodinates for each particle or does it use an altogether different method?
  2. Is this the fastest and most computationally efficient way to generate these list of centroided coodinates given that it also calculates several other parameters that I do not need?

 

Thanks so much! Any help would be greatly appreciated!

 

Justin     

0 Kudos
Message 1 of 4
(3,472 Views)

Hi Justin,

 

I haven't been able to obtain the formula / algorithm that the VI uses but I found that the particle analysis example in CVI offers some insight into what the function is performing. I've copied the C code for your convience but I found it on this white paper http://www.ni.com/example/26517/en/   - 

Particle Analysis Examples. 

 

 

****

int CVICALLBACK ParticleAnalysis (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:

/* Make sure the user has thresholded the image */
if(!thresholdFlag) {
MessagePopup ("Image must be thresholded",
"You must threshold an image before performing the particle analysis.");
return 0;
}

/* This section of our code shows how to run a basic particle analysis.
imaqGetParticleInfo is used with the parameter IMAQ_BASIC_INFO to get
basic information on each particle in the image. It returns a pointer
to a structure array which contains all of the information for each
particle. Passing IMAQ_ALL_INFO instead of IMAQ_BASIC_INFO will run
a more detailed report on the particles, but will take longer to execute.
For more information on the report structure, see vision.h or the function
panel for imaqGetParticleInfo. */

/* Reset the max value for the control to (2^32)-1 so that consecutive runs
are not limited by the number of objects found in previous runs */
SetCtrlAttribute (panelHandle, PANEL_CURRENT_PARTICLE, ATTR_MAX_VALUE,
4294967295);

/* If we have already called imaqGetParticleInfo and thus created a particle report
we should dispose that report before creating a new one. */
if (particleRptExists)
imaqDispose (particleRpt_Ptr);

particleRpt_Ptr = imaqGetParticleInfo (thresholdImage, FALSE, IMAQ_BASIC_INFO, &particleCount);

particleRptExists = TRUE;
/* Simple user interface management - activate the particle report controls */

SetCtrlAttribute (panelHandle, PANEL_PARTICLE_COUNT, ATTR_DIMMED,
FALSE);
SetCtrlAttribute (panelHandle, PANEL_CURRENT_PARTICLE, ATTR_DIMMED,
FALSE);
SetCtrlAttribute (panelHandle, PANEL_AREA, ATTR_DIMMED,
FALSE);
SetCtrlAttribute (panelHandle, PANEL_CAL_AREA, ATTR_DIMMED,
FALSE);
SetCtrlAttribute (panelHandle, PANEL_TOP, ATTR_DIMMED,
FALSE);
SetCtrlAttribute (panelHandle, PANEL_HEIGHT, ATTR_DIMMED,
FALSE);
SetCtrlAttribute (panelHandle, PANEL_LEFT, ATTR_DIMMED,
FALSE);
SetCtrlAttribute (panelHandle, PANEL_WIDTH, ATTR_DIMMED,
FALSE);

SetCtrlVal (panelHandle, PANEL_PARTICLE_COUNT, particleCount);

/* Set the max value on the index control so that the user does
not try to access particle info for particles that do not exist */
SetCtrlAttribute (panelHandle, PANEL_CURRENT_PARTICLE, ATTR_MAX_VALUE,
particleCount - 1);

/* Simulate an event to immediately update report controls and reset the
report index to zero */
ViewReport (panelHandle, 0,EVENT_COMMIT,NULL,0,0);

SetCtrlVal (panelHandle, PANEL_CURRENT_PARTICLE, 0);
break;
}
return 0;
}

***

Kind Regards,
Lucas
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,432 Views)

@Lucas. wrote:

I've copied the C code for your convience but I found it on this white paper http://www.ni.com/example/26517/en/ 


 Hi Lucas,

 

Thanks so much for your reply and providing the C code, I really appreciate it. Its a shame that the algorithm the VI uses to calculate the centre of mass still appears to be hidden behind prewritten functions and finding documentation explaining the method is very hard to come by, although I find it very hard to believe that this information doesn't exist...after all someone had to code these functions in the first place. The examples in the link you provided did prove helpful also, as the IMAQ ComplexMeasure function appears to be able to be configured to calculate only the parameters you need, which I assume at this stage will help speed up the computation, however I am yet to give it a go and really test it. Another limiting factor in this however is that it looks like it needs to be used in conjuction with the IMAQ ComplexParticle function which still makes a number of calculations that I dont really need. To me, it still definitely looks like its worth a try though.

 

If anyone else has any other suggestions or can point in a direction to find the information I would be very grateful. My earlier questions now extends to the IMAQ ComplexMeasure function as well. Between my colleagues and I, we have speculated that the centre of mass is calculated using a three-point centroiding algorithm, or possibly by using a hybrid of the three-point and gaussian centroiding algorithms, however others obviously exist as well. I would prefer to know which it is so that I am aware of the limitations associated with the calculations and the functions I am using.

 

Best wishes to all,

 

Justin  

0 Kudos
Message 3 of 4
(3,424 Views)

Hi all,

 

Further to my previous posts, if anyone has any ideas, please let me know. It would help me massively.

 

Justin

0 Kudos
Message 4 of 4
(3,391 Views)