diff --git a/_episodes/02-data.md b/_episodes/02-data.md index 1de641bde56f2fc2cae4f85647271bf73c5cab11..c81f864dc87a5d01564cd6c95c8573b382d407d9 100644 --- a/_episodes/02-data.md +++ b/_episodes/02-data.md @@ -37,6 +37,36 @@ keypoints: ## Numpy +> ## Working with data types +> +> 1. Increase the brightness of the image by 100 +> 2. Why does the result look so bizarre? What is going wrong here? +> 3. How would you fix this issue? +> +> > ## Solution +> > ~~~ +> > # 1 +> > new_image = raw + 100 +> > plt.imshow(new_image, cmap='gray') +> > ~~~ +> > {: .language-python } +> > +> > ![](/fig/overflow_image.png) +> > ~~~ +> > # 2 +> > print(raw.dtype) +> > print(np.max(raw)) +> > # The data type is 'uint8' i.e. unsigned 8 bit integer (max value 255) +> > # When 100 is added, many values overflow, giving unexpected results +> > +> > # 3 +> > new_raw = raw.astype('uint32') +> > plt.imshow(new_raw + 100, cmap='gray') +> > ~~~ +> > {: .language-python } +> {: .solution } +{: .challenge } + ## Reading data to a numpy array We'll use the popular image analysis package scikit-image, diff --git a/fig/overflow_image.png b/fig/overflow_image.png new file mode 100644 index 0000000000000000000000000000000000000000..15e6948736420fcd2ded3297d9cc243b11e97f7b Binary files /dev/null and b/fig/overflow_image.png differ