Skip to content

Commit af5fd5c

Browse files
committed
Merge branch 'gh-pages' into pr/jupyterChapter03
2 parents f9f765b + 7f4fff1 commit af5fd5c

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

episodes/03-skimage-images.md

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -303,51 +303,6 @@ extraneous background detail has been removed.
303303
304304
![Thresholded root image](../fig/maize-root-cluster-threshold.jpg)
305305
306-
> ## Keeping only low intensity pixels (10 min)
307-
>
308-
> In the previous example, we showed how we could use Python and skimage to turn
309-
> on only the high intensity pixels from an image, while turning all the low
310-
> intensity pixels off. Now, you can practice doing the opposite -- keeping all
311-
> the low intensity pixels while changing the high intensity ones. Consider
312-
> this image of a Su-Do-Ku puzzle, named `data/sudoku.png`:
313-
>
314-
> ![Su-Do-Ku puzzle](../data/sudoku.png)
315-
>
316-
> Replicate the ignore low intensity script above as a starting. Then, edit the script
317-
> so that it turns all of the white pixels in the sudoku image to a light gray color,
318-
> say with all three color channel values for each formerly white pixel set to 64. Your
319-
> results should look like this:
320-
>
321-
> ![Modified Su-Do-Ku puzzle](../fig/sudoku-gray.png)
322-
>
323-
> > ## Solution
324-
> >
325-
> > After modification, your program should look like this:
326-
> >
327-
> > ~~~
328-
> > """
329-
> > * Python script to modify high intensity pixels in an image.
330-
> > """
331-
> > import skimage.io
332-
> >
333-
> > # read input image
334-
> > image = skimage.io.imread('data/sudoku.png')
335-
> >
336-
> > # display original image
337-
> > fig, ax = plt.subplots()
338-
> > plt.imshow(image)
339-
> >
340-
> > # change high intensity pixels to gray
341-
> > image[image > 200] = 64
342-
> >
343-
> > # display modified image
344-
> > fig, ax = plt.subplots()
345-
> > plt.imshow(image)
346-
> > ~~~
347-
> > {: .language-python}
348-
> {: .solution}
349-
{: .challenge}
350-
351306
352307
## Converting color images to grayscale
353308
@@ -402,6 +357,54 @@ plt.imshow(image)
402357
~~~
403358
{: .language-python}
404359
360+
> ## Keeping only low intensity pixels (10 min)
361+
>
362+
> A little earlier, we showed how we could use Python and skimage to turn
363+
> on only the high intensity pixels from an image, while turning all the low
364+
> intensity pixels off.
365+
> Now, you can practice doing the opposite -- keeping all
366+
> the low intensity pixels while changing the high intensity ones.
367+
>
368+
> The file `data/sudoku.png` is an RGB image of a sudoku puzzle:
369+
>
370+
> ![Su-Do-Ku puzzle](../data/sudoku.png)
371+
>
372+
> Your task is to turn all of the white pixels in the image to a light gray color,
373+
> say with the intensity of each formerly white pixel set to 64.
374+
> The results should look like this:
375+
>
376+
> ![Modified Su-Do-Ku puzzle](../fig/sudoku-gray.png)
377+
>
378+
> _Hint: this is an instance where it is helpful to convert the image from RGB to grayscale._
379+
>
380+
> > ## Solution
381+
> >
382+
> > First, load the image file in and convert it to grayscale:
383+
> >
384+
> > ~~~
385+
> > import skimage.io
386+
> >
387+
> > image = skimage.io.imread(fname='data/sudoku.png', as_gray=True)
388+
> > ~~~
389+
> > {: .language-python }
390+
> >
391+
> > Then, change all high intensity pixel values to 64:
392+
> >
393+
> > ~~~
394+
> > image[image > 200] = 64
395+
> > ~~~
396+
> > {: .language-python }
397+
> >
398+
> > Finally, display modified image:
399+
> >
400+
> > ~~~
401+
> > fig, ax = plt.subplots()
402+
> > plt.imshow(image)
403+
> > ~~~
404+
> > {: .language-python}
405+
> {: .solution}
406+
{: .challenge}
407+
405408
406409
## Access via slicing
407410

0 commit comments

Comments
 (0)