mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-15 11:25:53 +08:00
Improve visualization of labelling
This commit is contained in:
@@ -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']):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user