如何从图像中提取平滑骨架?

2024-04-27 23:41:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试分割包含DNA链的AFM图像。在下图中,您可以看到原始图像、分割图像和骨骼化版本。Left: Original image, middle: segmented image, right: skeletonized image。我想知道如何改进我的分割,以便我右边的图像包含更少的小分支,或者同样地,中间的图像有更清晰的边缘和轮廓。

作为参考,这是我的代码:

from skimage.morphology import remove_small_objects, dilation
from skimage.segmentation import clear_border
from skimage.filters import unsharp_mask, threshold_triangle, difference_of_gaussians
from skimage import exposure
import numpy as np

def preprocess_img(image, rescaling=False, sharpening=False):
    
    if rescaling: # rescale the intensity of the pixel values
        p2, p99 = np.percentile(image, (2, 99))
        image = exposure.rescale_intensity(image, out_range=(p2, p99))
            
    if sharpening and rescaling:
        image = unsharp_mask(image)
    
    thresh = threshold_triangle(image) # apply threshold
    mask = image > thresh
    mask = remove_small_objects(mask > 0)
    mask = dilation(mask)
    mask = clear_border(mask) # remove image border artifacts
    return mask 

Tags: from图像imageimportthresholdobjectsmaskremove