@@ -478,9 +478,7 @@ def measure_root_mass(filename, sigma=1.0):
478
478
479
479
# determine root mass ratio
480
480
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
484
482
485
483
return density
486
484
```
@@ -499,11 +497,8 @@ Recall that in the `binary_mask`, every pixel has either a value of
499
497
zero (black/background) or one (white/foreground).
500
498
We want to count the number of white pixels,
501
499
which 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).
505
500
Finally, 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.
507
502
The function returns then root density of the image.
508
503
509
504
We can call this function with any filename and
@@ -650,9 +645,7 @@ def enhanced_root_mass(filename, sigma):
650
645
651
646
# determine root mass ratio
652
647
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
656
649
657
650
return density
658
651
0 commit comments