mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-10 07:48:36 +08:00
Added example
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from skimage import graph
|
||||
from skimage import segmentation
|
||||
from skimage import data, io
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
|
||||
def label_mask_img(img, label):
|
||||
|
||||
out = np.zeros_like(img)
|
||||
|
||||
red = img[:, :, 0]
|
||||
green = img[:, :, 1]
|
||||
blue = img[:, :, 2]
|
||||
|
||||
for i in range(label.max()):
|
||||
mask = label == i
|
||||
|
||||
r = np.average(red[mask])
|
||||
g = np.average(green[mask])
|
||||
b = np.average(blue[mask])
|
||||
|
||||
# print r,g,b
|
||||
out[mask] = r, g, b
|
||||
|
||||
return out
|
||||
|
||||
img = data.coffee()
|
||||
|
||||
labels1 = segmentation.slic(img, compactness=30, n_segments=400)
|
||||
out1 = label_mask_img(img, labels1)
|
||||
|
||||
g = graph.rag_meancolor(img, labels1)
|
||||
labels2 = graph.threshold_cut(labels1, g, 30)
|
||||
out2 = label_mask_img(img, labels2)
|
||||
|
||||
plt.figure()
|
||||
io.imshow(out1)
|
||||
plt.figure()
|
||||
io.imshow(out2)
|
||||
io.show()
|
||||
Reference in New Issue
Block a user