Get startedGet started for free

Measure variance

SciPy measurement functions allow you to tailor measurements to specific sets of pixels:

  • Specifying labels restricts the mask to non-zero pixels.
  • Specifying index value(s) returns a measure for each label value.

For this exercise, calculate the intensity variance of vol with respect to different pixel sets. We have provided the 3D segmented image as labels: label 1 is the left ventricle and label 2 is a circular sample of tissue.

Labeled Volume


After printing the variances, select the true statement from the answers below.

This exercise is part of the course

Biomedical Image Analysis in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Variance for all pixels
var_all = ndi.variance(vol, labels=None, index=None)
print('All pixels:', var_all)

# Variance for labeled pixels
var_labels = ndi.variance(____, _____, ____)
print('Labeled pixels:', ____)

# Variance for each object
var_objects = ____
print('Left ventricle:', var_objects[0])
print('Other tissue:', ____)
Edit and Run Code