src/store/modules/segmentationModule/getLabelmapStats.js
/**
 * Returns an array of voxel values masked by the segment for each frame,
 * as well as the real world volume of a voxel on that frame.
 *
 * @param {Labelmap3D} labelmap3D The `Labelmap3D` object.
 * @param {Object[]} images An array of cornerstone images.
 * @param {Object[]} imagePlanes An array of the per-frame imagePlane metadata.
 * @param {number} segmentIndex The index of the segment to check.
 *
 * @returns {Object[]} An array of voxel values and voxel volumes per frame.
 */
Returns an array of voxel values masked by the segment for each frame,
as well as the real world volume of a voxel on that frame.



@returns {Object[]} An array of voxel values and voxel volumes per frame.
Returns an array of voxel values masked by the segment for each frame as well as the real world volume of a voxel on that frame . @returns { Object [] } An array of voxel values and voxel volumes per frame .
function _getVoxelsPerFrameForSegment(
  labelmap3D,
  images,
  imagePlanes,
  segmentIndex
) {
  const { rowPixelSpacing, columnPixelSpacing } = images[0];
  const labelmaps2D = labelmap3D.labelmaps2D;
  const voxelsPerFrame = [];
  for (let i = 0; i < labelmaps2D.length; i++) {
    const labelmap2D = labelmaps2D[i];
    if (labelmap2D && labelmap2D.segmentsOnLabelmap.includes(segmentIndex)) {
      const sliceThickness = _getSliceThickness(images, imagePlanes, i);
      const voxelInMM3 = sliceThickness * rowPixelSpacing * columnPixelSpacing;
      const segmentationPixelData = labelmap2D.pixelData;
      const imagePixelData = images[i].getPixelData();
      const values = [];
      for (let p = 0; p < segmentationPixelData.length; p++) {
        if (segmentationPixelData[p] === segmentIndex) {
          values.push(imagePixelData[p]);
        }
      }
      voxelsPerFrame.push({
        voxelInMM3,
        values,
      });
    }
  }
  return voxelsPerFrame;
}
function _getVoxelsPerFrameForSegment ( labelmap3D , images , imagePlanes , segmentIndex ) { const { rowPixelSpacing , columnPixelSpacing } = images [ 0 ] ; const labelmaps2D = labelmap3D . labelmaps2D ; const voxelsPerFrame = [ ] ; for ( let i = 0 ; i < labelmaps2D . length ; i ++ ) { const labelmap2D = labelmaps2D [ i ] ; if ( labelmap2D && labelmap2D . segmentsOnLabelmap . includes ( segmentIndex ) ) { const sliceThickness = _getSliceThickness ( images , imagePlanes , i ) ; const voxelInMM3 = sliceThickness * rowPixelSpacing * columnPixelSpacing ; const segmentationPixelData = labelmap2D . pixelData ; const imagePixelData = images [ i ] . getPixelData ( ) ; const values = [ ] ; for ( let p = 0 ; p < segmentationPixelData . length ; p ++ ) { if ( segmentationPixelData [ p ] === segmentIndex ) { values . push ( imagePixelData [ p ] ) ; } } voxelsPerFrame . push ( { voxelInMM3 , values , } ) ; } } return voxelsPerFrame ; }
Returns an array of voxel values masked by the segment for each frame,
 as well as the real world volume of a voxel on that frame.
Returns an array of voxel values masked by the segment for each frame as well as the real world volume of a voxel on that frame .
// Iterate over segmentationPixelData and count voxels.