Skip to content

Commit 9bba1a5

Browse files
authored
Merge pull request #215 from datacarpentry/color-range
Color-range expected error
2 parents b2b39d5 + ff86a32 commit 9bba1a5

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

_episodes/08-connected-components.md

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -302,47 +302,51 @@ plt.show()
302302
~~~
303303
{: .language-python}
304304
305-
Here you might get a warning
306-
`UserWarning: Low image data range; displaying image with stretched contrast.`
307-
or just see an all black image
308-
(Note: this behavior might change in future versions or
309-
not occur with a different image viewer).
310-
311-
What went wrong?
312-
When you hover over the black image,
313-
the pixel values are shown as numbers in the lower corner of the viewer.
314-
You can see that some pixels have values different from `0`,
315-
so they are not actually pure black.
316-
Let's find out more by examining `labeled_image`.
317-
Properties that might be interesting in this context are `dtype`,
318-
the minimum and maximum value.
319-
We can print them with the following lines:
320-
321-
~~~
322-
print("dtype:", labeled_image.dtype)
323-
print("min:", np.min(labeled_image))
324-
print("max:", np.max(labeled_image))
325-
~~~
326-
{: .language-python}
327-
328-
Examining the output can give us a clue why the image appears black.
329-
330-
~~~
331-
dtype: int64
332-
min: 0
333-
max: 11
334-
~~~
335-
{: .output}
336-
337-
The `dtype` of `labeled_image` is `int64`.
338-
This means that values in this image range from `-2 ** 63` to `2 ** 63 - 1`.
339-
Those are really big numbers.
340-
From this available space we only use the range from `0` to `11`.
341-
When showing this image in the viewer,
342-
it squeezes the complete range into 256 gray values.
343-
Therefore, the range of our numbers does not produce any visible change.
305+
> ## Color mappings
306+
>
307+
> Here you might get a warning
308+
> `UserWarning: Low image data range; displaying image with stretched contrast.`
309+
> or just see an all black image
310+
> (Note: this behavior might change in future versions or
311+
> not occur with a different image viewer).
312+
>
313+
> What went wrong?
314+
> When you hover over the black image,
315+
> the pixel values are shown as numbers in the lower corner of the viewer.
316+
> You can see that some pixels have values different from `0`,
317+
> so they are not actually pure black.
318+
> Let's find out more by examining `labeled_image`.
319+
> Properties that might be interesting in this context are `dtype`,
320+
> the minimum and maximum value.
321+
> We can print them with the following lines:
322+
>
323+
> ~~~
324+
> print("dtype:", labeled_image.dtype)
325+
> print("min:", np.min(labeled_image))
326+
> print("max:", np.max(labeled_image))
327+
> ~~~
328+
> {: .language-python}
329+
>
330+
> Examining the output can give us a clue why the image appears black.
331+
>
332+
> ~~~
333+
> dtype: int32
334+
> min: 0
335+
> max: 11
336+
> ~~~
337+
> {: .output}
338+
>
339+
> The `dtype` of `labeled_image` is `int64`.
340+
> This means that values in this image range from `-2 ** 63` to `2 ** 63 - 1`.
341+
> Those are really big numbers.
342+
> From this available space we only use the range from `0` to `11`.
343+
> When showing this image in the viewer,
344+
> it squeezes the complete range into 256 gray values.
345+
> Therefore, the range of our numbers does not produce any visible change.
346+
>
347+
> Fortunately, the skimage library has tools to cope with this situation.
348+
{: .solution }
344349
345-
Fortunately, the skimage library has tools to cope with this situation.
346350
We can use the function `skimage.color.label2rgb()`
347351
to convert the colours in the image
348352
(recall that we already used the `skimage.color.rgb2gray()` function

0 commit comments

Comments
 (0)