%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from skimage import (filters, io, color, exposure, feature,
segmentation, morphology, img_as_float)
(Based on StackOverflow http://stackoverflow.com/questions/28281742/fitting-a-circle-to-a-binary-image)
Consider a pill from the [NLM Pill Image Recognition Pilot](http://pir.nlm.nih.gov/pilot/instructions.html) (``../images/round_pill.jpg``). Fit a circle to the pill outline and compute its area.Hints:
exposure.equalize_*
)filter.canny
or feature.canny
--depending on your version)CircleModel
using measure.ransac
.NOTE: this is expensive to compute, so may take a while to execute
# Initial level set
pill = color.rgb2gray(image)
pill = restoration.denoise_nl_means(pill, multichannel=False)
level_set = segmentation.circle_level_set(pill.shape, radius=200)
ls = segmentation.morphological_chan_vese(pill, 80, init_level_set=level_set, smoothing=3)
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
ax.imshow(pill, cmap="gray")
ax.set_axis_off()
ax.contour(ls, [0.5], colors='r');
Based on StackOverflow http://stackoverflow.com/questions/28242274/count-number-of-objects-using-watershed-algorithm-scikit-image
Consider the coins image from the scikit-image example dataset, shown below. Write a function to count the number of coins.
The procedure outlined here is a bit simpler than in the notebook lecture (and works just fine!)
Hint:
filters.threshold_otsu
)segmentation.clear_border
)morphology.closing
)measure.regionprops
)color.label2rgb
)from skimage import data
fig, ax = plt.subplots()
ax.imshow(data.coins(), cmap='gray');
Based on https://stackoverflow.com/q/8686926/214686
Consider the zig-zaggy snakes on the left (../images/snakes.png
).
Write some code to find the begin- and end-points of each.
Hints:
morphology.skeletonize
)scipy.signal.convolve2d
[find all points with only one neighbor], and np.logical_and
[which of those points lie on the snake?] to do that, but there are many other ways).How many blue M&Ms are there in this image (../images/mm.jpg
)?
Steps:
restoration.denoise_nl_means
)scipy.ndimage.binary_fill_holes
Alternative approach:
Based on StackOverflow: http://stackoverflow.com/questions/23121416/long-boundary-detection-in-a-noisy-image
Consider the fluid experiment on the right (../images/fingers.png
). Determine any kind of meaningful boundary in this noisy image.
Hints:
feature.canny
)restoration.denoise_tv_bregman
)feature.canny
)