# Getting Started

Getting Started

In [35]:
x
 
# check scikit image version
import skimage
skimage.__version__
Out[35]:
'0.12.3'
In [36]:
 
from skimage import data, io, filters
image = data.coins()
io.imshow(image)
io.show()
 
## Edge detection 

Edge detection

In [3]:
 
edges = filters.sobel(image)
io.imshow(edges)
io.show()
 
## Module: data 
web: http://scikit-image.org/docs/dev/api/skimage.data.html
 
skimage.data.astronaut()    Color image of the astronaut Eileen Collins.
skimage.data.camera()   Gray-level “camera” image.
skimage.data.checkerboard()     Checkerboard image.
skimage.data.chelsea()  Chelsea the cat.
skimage.data.clock()    Motion blurred clock.
skimage.data.coffee()   Coffee cup.
skimage.data.coins()    Greek coins from Pompeii.
skimage.data.horse()    Black and white silhouette of a horse.
skimage.data.hubble_deep_field()    Hubble eXtreme Deep Field.
skimage.data.immunohistochemistry()     Immunohistochemical (IHC) staining with hematoxylin counterstaining.
skimage.data.logo()     Scikit-image logo, a RGBA image.
skimage.data.moon()     Surface of the moon.
skimage.data.page()     Scanned page.
skimage.data.text()     Gray-level “text” image used for corner detection.
skimage.data.rocket()   Launch photo of DSCOVR on Falcon 9 by SpaceX.
skimage.data.stereo_motorcycle()    Rectified stereo image pair with ground-truth disparities.
In [4]:
 
image = data.camera()
io.imshow(image)
io.show()
In [5]:
 
image = data.coffee()
io.imshow(image)
io.show()
In [7]:
 
image = data.hubble_deep_field()
io.imshow(image)
io.show()
In [34]:
 
import numpy as np
import matplotlib.pyplot as plt
# load a small section of the image
image = data.coins()[0:95, 70:370]
# plot graph
fig, axes = plt.subplots(ncols=2, nrows=3, figsize=(8,4))      
ax0, ax1, ax2, ax3, ax4, ax5  = axes.flat
ax0.imshow(image, cmap=plt.cm.gray)
ax0.set_title('Original', fontsize=15)
ax0.axis('off')   
# Histogram
values, bins = np.histogram(image, bins=np.arange(256))
ax1.plot(bins[:-1], values, lw=2, c='k')
ax1.set_xlim(xmax=256)
ax2.set_yticks([0, 400])
ax1.set_aspect(.2)
ax1.set_title('Histogram', fontsize=15)
# Apply threshold.
from skimage.filters import threshold_adaptive
bw = threshold_adaptive(image, 95, offset=-15)
ax2.imshow(bw, cmap=plt.cm.gray)
ax2.set_title('Adaptive threshold', fontsize=15)
ax2.axis('off')
# Detect edges.
from skimage import feature
edges = feature.canny(image, sigma=3,
                     low_threshold=10,
                     high_threshold=80)
ax3.imshow(edges, cmap=plt.cm.gray)
ax3.set_title('Edges', fontsize=15)
ax3.axis('off')
# Label image regions.
from skimage.measure import regionprops
import matplotlib.patches as mpatches
from skimage.morphology import label
label_image = label(edges)
ax4.imshow(image, cmap=plt.cm.gray)
ax4.set_title('Labeled items', fontsize=15)
ax4.axis('off')
for region in regionprops(label_image):
    # Draw rectangle around segmented coins.
    minr, minc, maxr, maxc = region.bbox
    rect = mpatches.Rectangle((minc, minr),
                              maxc - minc,
                              maxr - minr,
                              fill=False,
                              edgecolor='red',
                              linewidth=2)
    ax4.add_patch(rect)
plt.tight_layout()
plt.show()
In [ ]: