def test_li_arbitrary_start_point(): cell = data.cell() max_stationary_point = threshold_li(cell) low_stationary_point = threshold_li(cell, initial_guess=np.percentile(cell, 5)) optimum = threshold_li(cell, initial_guess=np.percentile(cell, 95)) assert 67 < max_stationary_point < 68 assert 48 < low_stationary_point < 49 assert 111 < optimum < 112
from cucim.skimage.filters.thresholding import _cross_entropy # _mean_std, from cucim.skimage.filters.thresholding import (threshold_isodata, threshold_li, threshold_local, threshold_mean, threshold_minimum, threshold_multiotsu, threshold_niblack, threshold_otsu, threshold_sauvola, threshold_triangle, threshold_yen, try_all_threshold) # transfer images to GPU astronautd = cp.array(data.astronaut()) camerad = cp.array(data.camera()) celld = cp.array(data.cell()) coinsd = cp.array(data.coins()) moond = cp.array(data.moon()) class TestSimpleImage: def setup(self): # fmt: off self.image = cp.array([[0, 0, 1, 3, 5], [0, 1, 4, 3, 4], [1, 2, 5, 4, 1], [2, 4, 5, 2, 1], [4, 5, 1, 0, 0]], dtype=int) # fmt: on def test_minimum(self):
def test_cell(): """ Test that "cell" image can be loaded.""" data.cell()
.. [1] Li C.H. and Lee C.K. (1993) "Minimum Cross Entropy Thresholding" Pattern Recognition, 26(4): 617-625 :DOI:`10.1016/0031-3203(93)90115-D` .. [2] Li C.H. and Tam P.K.S. (1998) "An Iterative Algorithm for Minimum Cross Entropy Thresholding" Pattern Recognition Letters, 18(8): 771-776 :DOI:`10.1016/S0167-8655(98)00057-9` """ import numpy as np import matplotlib.pyplot as plt from skimage import data from skimage import filters from skimage.filters.thresholding import _cross_entropy cell = data.cell() camera = data.camera() ############################################################################### # First, we let's plot the cross entropy for the :func:`skimage.data.camera` # image at all possible thresholds. thresholds = np.arange(np.min(camera) + 1.5, np.max(camera) - 1.5) entropies = [_cross_entropy(camera, t) for t in thresholds] optimal_camera_threshold = thresholds[np.argmin(entropies)] fig, ax = plt.subplots(1, 3, figsize=(8, 3)) ax[0].imshow(camera, cmap='gray') ax[0].set_title('image')