<jupyter_start><jupyter_text>7. Images solutions 1. Import the numpy and skimage packages<jupyter_code>import numpy as np
import skimage
import skimage.io<jupyter_output><empty_output><jupyter_text>2. Using the skimage import function, load the image visible at this link: http://wiki.cmci.info/sampleimages/cells_Actin.tifand put it in a variable called image<jupyter_code>image = skimage.io.imread('http://wiki.cmci.info/sampleimages/cells_Actin.tif')<jupyter_output><empty_output><jupyter_text>3. Check what are the dimensions of the image<jupyter_code>image.shape<jupyter_output><empty_output><jupyter_text>4. Check what is the image type. Is it an 8 or 16 bit image ?<jupyter_code>image.dtype<jupyter_output><empty_output><jupyter_text>5. Plot the image using Matplotlib (that you have to import). Change the color map to 'gray' and make the image larger<jupyter_code>import matplotlib.pyplot as plt
plt.subplots(figsize = (10,10))
plt.imshow(image, cmap = 'gray')
plt.show()<jupyter_output><empty_output><jupyter_text>6. Plot a histogram of the pixel values. Change the bin size to better see the distribution<jupyter_code>plt.hist(np.ravel(image), bins = np.arange(0,255,1))
plt.show()<jupyter_output><empty_output><jupyter_text>8. Slicing and indexing 1. Make a cropped version of the image by selecting 100 rows for which you want all columns and plot it.<jupyter_code>cropped = image[200:300,:]
plt.imshow(cropped, cmap = 'gray')
plt.show()<jupyter_output><empty_output><jupyter_text>2. Select a region in the image of 100x100 pixesl and create a cropped image. Plot it.<jupyter_code>cropped2 = image[200:300,600:700]
plt.imshow(cropped2, cmap = 'gray')
plt.show()<jupyter_output><empty_output><jupyter_text>3. Using this second cropped image, create a boolean mask by finding all pixels above some reasonable threshold (use the histogram above to find a value)<jupyter_code>mask = cropped2 > 20<jupyter_output><empty_output><jupyter_text>4. Plot your mask<jupyter_code>plt.imshow(mask)
plt.show()<jupyter_output><empty_output><jupyter_text>5. Get all the values of all the pixels which are selected in the mask and store in a variable<jupyter_code>values = cropped2[mask]<jupyter_output><empty_output><jupyter_text>6. Plot a histogram of all the values<jupyter_code>plt.hist(values)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10154241645244216, 'fraction_numerical': 0.025278491859468722, 'mean_word_length': 7.192982456140351, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '291042', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 863, 'n_tokens_neox': 806, 'n_words': 219, 'path': 's0708-Images.ipynb', 'repo_name': 'guiwitz/PyImageCourse_beginner', 'size': '2334'}