@@ -478,9 +478,7 @@ def measure_root_mass(filename, sigma=1.0):
478478
479479 # determine root mass ratio
480480 root_pixels = np.count_nonzero(binary_mask)
481- w = binary_mask.shape[1 ]
482- h = binary_mask.shape[0 ]
483- density = root_pixels / (w * h)
481+ density = root_pixels / binary_mask.size
484482
485483 return density
486484```
@@ -499,11 +497,8 @@ Recall that in the `binary_mask`, every pixel has either a value of
499497zero (black/background) or one (white/foreground).
500498We want to count the number of white pixels,
501499which can be accomplished with a call to the NumPy function ` np.count_nonzero ` .
502- Then we determine the width and height of the image by using
503- the elements of ` binary_mask.shape `
504- (that is, the dimensions of the NumPy array that stores the image).
505500Finally, the density ratio is calculated by dividing the number of white pixels
506- by the total number of pixels ` w*h ` in the image.
501+ by the total number of pixels ` binary_mask.size ` in the image.
507502The function returns then root density of the image.
508503
509504We can call this function with any filename and
@@ -650,9 +645,7 @@ def enhanced_root_mass(filename, sigma):
650645
651646 # determine root mass ratio
652647 root_pixels = np.count_nonzero(binary_mask)
653- w = binary_mask.shape[1 ]
654- h = binary_mask.shape[0 ]
655- density = root_pixels / (w * h)
648+ density = root_pixels / binary_mask.size
656649
657650 return density
658651
0 commit comments