scikit-image
is a pretty awesome all-purpose lightweight image analysis package for Python. In this question, you'll work with its data
submodule.
Scikit-image comes prepackaged with a great deal of sample data for you to experiment with. In the skimage.data
submodule, you'll find quite a few functions that return this sample data. Go the documentation page (linked in the previous paragraph), pick a sample function, call it, and display it using matplotlib's imshow()
function.
In [ ]:
import matplotlib.pyplot as plt
import numpy as np
import skimage.data
### BEGIN SOLUTION
### END SOLUTION
Now, we'll measure some properties of the image you chose. This will require use of the measure
submodule.
You'll need to call two functions from this module. First, you'll need to label discrete regions of your image--effectively, identify "objects" in it. This will use the skimage.measure.label()
function, which takes two arguments: your image, and the pixel value to be considered background. You'll need to experiment a little with this second argument to find the "right" value for your image!
(IMPORTANT: If your image is RGB, you'll need to convert it to grayscale before calling label()
; you can do this with the skimage.color.rgb2gray()
function)
Second, you'll need to give the labels you get from the label()
function to skimage.measure.regionprops
. This will return a dictionary with a bunch of useful information about your image. You'll use that information to answer some questions in part C below.
In [ ]:
import skimage.measure
import skimage.color
### BEGIN SOLUTION
### END SOLUTION
Go to scikit-image's documentation for the regionprops
function to see the properties of the dictionary that the function returns; pay special attention to the fact that these properties are computed for every object identified by the label()
function.
Which object (by index) has the largest area? Which has the smallest? What are the respective perimeters of the objects with the largest and smallest areas? What are their centroid coordinates? What are their eccentricities?