List of my modules...

Module: Count Pixels

Description:

Counts pixels (as well as computing mean, variance, skewness and kurtosis of their greylevel [1]) of the image. The pixels to count can be selected by a threshold, a Region of Interest, a mask, or all of the above. The process can be decomposed plane by plane, producing a spreadsheet with one line per plane.

Example : the image on the left shows part of an input image. Were we to count the number of pixels that had an intensity strictly greater than 128, then all the pixels shown in white on the right image would be counted. Dividing the result by the total number of pixels gives the volume fraction. The module also output the average intensity of the selected pixels.

2D example : the left image shows the binary volume on which the pixels are counted on each plane in the Z direction. From the output spreadsheet, you can plot the volume fraction as a function of the plane direction, on the right.

Example : optional use of a Region Of Interest and a mask. The image is shown with the bounding box and cross-section, the ROI with the green corners, and the mask coloring the cross-section and shown in 3D with the transparent surface.

NOTES:

Connections:

Image

[required]
The input image, defined in a class HxUniformScalarField3.

ROI

[optional]
A Region Of Interest (ROI), defined in a HxSelectRoi. Will only count the pixels in the ROI if one is connected. A pixel is defined as in the ROI if the intersection between the ROI and the unit cube that defines the volume occupied by the pixel is non-empty. Another definition could have been that the pixel center belonged in the ROI.

Mask

[optional]
A mask image, defined in a class HxUniformScalarField3. Will only count the pixels if the corresponding pixel in the mask satisfies the threshold comparison defined in the appropriate ports.

Threshold


Value to compare with the pixel intensity.

Comparison


Defines how the threshold is used to define the pixels to count: should the pixel value be lower, lower or equal, greater, etc. than the threshold ?

Mask_Threshold


If a mask is connected, this is the value to compare with the mask pixel intensity.

Mask_Comparison


If a mask is connected, defines how the mask threshold is used to define the pixels to count: should the pixel value be lower, lower or equal, greater, etc. than the mask threshold ?

Dimension


Whether the module should output a global value, or a set of values for each plane respectively.

Direction


If 2D was chosen previously, then this port gives the direction in which you want to compute, e.g. in the Z direction you compute the numbers for each XY plane.

Count


Push the first button to count the pixels. The console will display the average pixel intensity of the pixels counted.

Stats


Displays statistics for the pixels satisfying the given conditions (threshold, ROI, mask):

Commands:

Additional options can be accessed when typing in the console Count_Pixels COMMAND_NAME. Typing the command again usually reverts back to original settings.

verbose

Displays timing information for the computation. Retype to hide info.

create

Runs the computation. If 3D was chosen, prints in console the same thing as in the Stats port. Command can be used in a script, such as set nbP [lindex [Count_Pixels create] 0].
If 2D was chosen, returns the name of the output spreadsheet. To use in a script, you can write set RESULT [Count_Pixels create].

Scripting:

Typical use in a TCL script would look like so:
	set C [create Count_Pixels]
	$C Image connect $INPUT_IMAGE; $C fire
	$C Threshold setValue 0; $C Comparison setValue 5; $C Dimension setValue 0
	set _res [$C create]
	set NumPix [lindex $_res 0]
	set Variance [lindex $_res 2]

References:

1 Pébay, P. (2008). Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments, Sandia National Laboratories.