[ITK] Volume of one voxel

Lowekamp, Bradley (NIH/NLM/LHC) [C] blowekamp at mail.nih.gov
Wed Dec 7 08:34:41 EST 2016


Your code looks fine. You just may want to use ImageType::ImageDimension instead of 3 to be more generic.

In C++ some may call this more elegant:

const ImageType::SpacingType &spacing = img->GetSpacing();
double vox_volume = std::accumulate( spacing.Begin(), Spacing.End(), 1.0, std::multiplies<double>() );

However, I think you'll find your initial approach is more common throughout ITK code.

HTH,
Brad

> On Dec 6, 2016, at 4:51 AM, Wood, Tobias <tobias.wood at kcl.ac.uk> wrote:
> 
> Hello,
> 
> Is there a more elegant way to calculate the volume of a single voxel in an image than:
> 
>    double vox_volume = img->GetSpacing()[0];
>    for (int v = 1; v < 3; v++)
>        vox_volume *= img->GetSpacing()[v];
> 
> (With appropriate dimensionality)
> 
> It feels like I’m missing something cleaner.
> 
> Toby
> 
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community



More information about the Community mailing list