From 4283d5195217c0d6768d4091e8fcdebe086142ca Mon Sep 17 00:00:00 2001 From: Haibao Tang Date: Mon, 13 May 2024 23:59:42 -0700 Subject: [PATCH] Add otsu --- jcvi/graphics/grabseeds.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jcvi/graphics/grabseeds.py b/jcvi/graphics/grabseeds.py index 80c4211d..e70c1cde 100644 --- a/jcvi/graphics/grabseeds.py +++ b/jcvi/graphics/grabseeds.py @@ -27,7 +27,7 @@ from scipy.optimize import fmin_bfgs as fmin from skimage.color import gray2rgb, rgb2gray from skimage.feature import canny, peak_local_max -from skimage.filters import roberts, sobel +from skimage.filters import roberts, sobel, threshold_otsu from skimage.measure import find_contours, regionprops, label from skimage.morphology import disk, closing from skimage.segmentation import clear_border, watershed @@ -313,7 +313,7 @@ def add_seeds_options(p, args): ) g3 = p.add_argument_group("De-noise") - valid_filters = ("canny", "roberts", "sobel") + valid_filters = ("canny", "roberts", "sobel", "otsu") g3.add_argument( "--filter", default="canny", @@ -654,6 +654,9 @@ def seeds(args): edges = roberts(img_gray) elif ff == "sobel": edges = sobel(img_gray) + elif ff == "otsu": + thresh = threshold_otsu(img_gray) + edges = img_gray > thresh edges = clear_border(edges, buffer_size=opts.border) selem = disk(kernel) closed = closing(edges, selem) if kernel else edges @@ -722,6 +725,9 @@ def seeds(args): contour = find_contours(labels == props.label, 0.5)[0] efds = efd_feature(contour) y0, x0 = props.centroid + # perimeter = props.perimeter + # area = props.area + # print(perimeter, area) orientation = props.orientation major, minor = props.major_axis_length, props.minor_axis_length major_dx = sin(orientation) * major / 2