Skip to content

Commit f0b23cd

Browse files
committed
markdown source builds
Auto-generated via `{sandpaper}` Source : bfaf89e Branch : main Author : Kimberly Meechan <24316371+K-Meech@users.noreply.github.com> Time : 2025-02-09 16:51:23 +0000 Message : Merge pull request #338 from nanosec/size Use ndarray.size instead of multiplying
1 parent c97f859 commit f0b23cd

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

07-thresholding.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
499497
zero (black/background) or one (white/foreground).
500498
We want to count the number of white pixels,
501499
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).
505500
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.
507502
The function returns then root density of the image.
508503

509504
We 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

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"episodes/04-drawing.md" "48b42ee384b5b907d9f9b93ad0e98ce8" "site/built/04-drawing.md" "2024-06-07"
1010
"episodes/05-creating-histograms.md" "4abbd123ba97d63c795398be6f6b7621" "site/built/05-creating-histograms.md" "2024-03-14"
1111
"episodes/06-blurring.md" "894ff33379584a8ee777f779564d5b01" "site/built/06-blurring.md" "2024-06-18"
12-
"episodes/07-thresholding.md" "4d34b89c8cd33cb6bb54103f805a39b9" "site/built/07-thresholding.md" "2024-03-12"
12+
"episodes/07-thresholding.md" "512a1806b8061dded3a68871e7bcdfe9" "site/built/07-thresholding.md" "2025-02-09"
1313
"episodes/08-connected-components.md" "f599af69b770c7234a4e7d4a06a7f6dd" "site/built/08-connected-components.md" "2024-11-13"
1414
"episodes/09-challenges.md" "3e95485b1bae2c37538830225ea26598" "site/built/09-challenges.md" "2024-03-12"
1515
"instructors/instructor-notes.md" "e8e378a5dfaec7b2873d788be85003ce" "site/built/instructor-notes.md" "2024-06-18"

0 commit comments

Comments
 (0)