mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-05 15:35:55 +08:00
24 lines
546 B
Python
24 lines
546 B
Python
import numpy as np
|
|
from skimage import graph
|
|
|
|
|
|
def test_threshold_cut():
|
|
|
|
img = np.zeros((100, 100, 3), dtype='uint8')
|
|
img[:50, :50] = 255, 255, 255
|
|
img[:50, 50:] = 254, 254, 254
|
|
img[50:, :50] = 2, 2, 2
|
|
img[50:, 50:] = 1, 1, 1
|
|
|
|
labels = np.zeros((100, 100), dtype='uint8')
|
|
labels[:50, :50] = 0
|
|
labels[:50, 50:] = 1
|
|
labels[50:, :50] = 2
|
|
labels[50:, 50:] = 3
|
|
|
|
rag = graph.rag_meancolor(img, labels)
|
|
new_labels = graph.threshold_cut(labels, rag, 10)
|
|
|
|
# Two labels
|
|
assert new_labels.max() == 1
|