Improve visualization of labelling

This commit is contained in:
Johannes Schönberger
2012-08-31 22:25:10 +02:00
parent da3f2b5f4d
commit 6e9d6e2857
+8 -6
View File
@@ -7,13 +7,14 @@ This example shows how to segment an image with image labelling.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from skimage import data
from skimage.filter import threshold_otsu
from skimage.segmentation import clear_border
from skimage.morphology import label
from skimage.morphology import label, closing, square
from skimage.measure import regionprops
@@ -21,11 +22,7 @@ image = data.coins()[50:-50, 50:-50]
# apply threshold
thresh = threshold_otsu(image)
bw = image > thresh
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
plt.gray()
ax.imshow(bw)
bw = closing(image > thresh, square(3))
# remove artifacts connected to image border
cleared = bw.copy()
@@ -33,6 +30,11 @@ clear_border(cleared)
# label image regions
label_image = label(cleared)
borders = np.logical_xor(bw, cleared)
label_image[borders] = -1
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
ax.imshow(label_image)
for region in regionprops(label_image, ['Area', 'BoundingBox']):