Skip to content

Commit 099d229

Browse files
committed
markdown source builds
Auto-generated via {sandpaper} Source : 7065592 Branch : main Author : Toby Hodges <tobyhodges@carpentries.org> Time : 2023-12-15 14:35:17 +0000 Message : Merge pull request #317 from bear-rsg/capstone-suggestions Optional capstone exercise
1 parent 4557fa2 commit 099d229

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

09-challenges.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,48 @@ This could be fixed with more complicated segmentation methods
193193
(outside of the scope of this lesson) like
194194
[watershed](https://scikit-image.org/docs/dev/auto_examples/segmentation/plot_watershed.html).
195195

196+
:::::::::::::::::::::::::
197+
198+
::::::::::::::::::::::::::::::::::::::::::::::::::
199+
200+
::::::::::::::::::::::::::::::::::::::: challenge
196201

202+
## Colony counting with minimum size and automated threshold (optional, not included in timing)
203+
204+
Modify your function from the previous exercise for colony counting to (i) exclude objects smaller
205+
than a specified size and (ii) use an automated thresholding approach, e.g. Otsu, to mask the
206+
colonies.
207+
208+
::::::::::::::::::::::::::::::::::::::: solution
209+
210+
Here is a modified function with the requested features. Note when calculating the Otsu threshold we
211+
don't include the very bright pixels outside the dish.
212+
213+
```python
214+
def count_colonies_enhanced(image_filename, sigma=1.0, min_colony_size=10, connectivity=2):
215+
216+
bacteria_image = iio.imread(image_filename)
217+
gray_bacteria = ski.color.rgb2gray(bacteria_image)
218+
blurred_image = ski.filters.gaussian(gray_bacteria, sigma=sigma)
219+
220+
# create mask excluding the very bright pixels outside the dish
221+
# we dont want to include these when calculating the automated threshold
222+
mask = blurred_image < 0.90
223+
# calculate an automated threshold value within the dish using the Otsu method
224+
t = ski.filters.threshold_otsu(blurred_image[mask])
225+
# update mask to select pixels both within the dish and less than t
226+
mask = np.logical_and(mask, blurred_image < t)
227+
# remove objects smaller than specified area
228+
mask = ski.morphology.remove_small_objects(mask, min_size=min_colony_size)
229+
230+
labeled_image, count = ski.measure.label(mask, return_num=True)
231+
print(f"There are {count} colonies in {image_filename}")
232+
colored_label_image = ski.color.label2rgb(labeled_image, bg_label=0)
233+
summary_image = ski.color.gray2rgb(gray_bacteria)
234+
summary_image[mask] = colored_label_image[mask]
235+
fig, ax = plt.subplots()
236+
plt.imshow(summary_image)
237+
```
197238

198239
:::::::::::::::::::::::::
199240

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"episodes/06-blurring.md" "8d109bb4c49f27f54857f6d35b4c6b9a" "site/built/06-blurring.md" "2023-12-08"
1212
"episodes/07-thresholding.md" "bc0b3a64255ef9dd359d4cf3188aba83" "site/built/07-thresholding.md" "2023-12-15"
1313
"episodes/08-connected-components.md" "59d42797208c5bf569da2fa2e4dd05df" "site/built/08-connected-components.md" "2023-09-09"
14-
"episodes/09-challenges.md" "a3ace24af8f5cb0bda1e9379a688ad4c" "site/built/09-challenges.md" "2023-09-05"
14+
"episodes/09-challenges.md" "655bdca8cab5d28dc6b2c2e9275aaecc" "site/built/09-challenges.md" "2023-12-15"
1515
"instructors/instructor-notes.md" "b1c166a544eb4b9b91f3ac8f2dafd549" "site/built/instructor-notes.md" "2023-05-12"
1616
"learners/discuss.md" "ad762c335f99400dc2cd1a8aad36bdbd" "site/built/discuss.md" "2023-07-26"
1717
"learners/edge-detection.md" "fdbcee7436e104e6587e1cb40cd37d18" "site/built/edge-detection.md" "2023-08-16"

0 commit comments

Comments
 (0)