如何仅选择轮廓内的区域?

时间:2018-11-13 05:33:46

标签: python opencv

我正在Python中实现前景提取算法,该算法可创建图像前景的蒙版和轮廓。

但是,我正在使用SVS文件(属性较少的tif文件),并且在提取前景后,由于我的图像分辨率为千兆像素,因此仍需要对其进行平铺。我正在使用openCV处理这些图像。

这是我的getContours函数:

def getContours(oslIm, level=2):
    """
    Loads the requested level from oslIm and returns identified contours in the slide.
    :param oslIm: openslide image
    :param level: level from which to load the data (usually 2)
    :return: contours
    """

    image_array = np.asarray(oslIm.read_region((1, 1), level, oslIm.level_dimensions[level]), dtype=np.uint8)
    image = image_array[:, :, 0:3]
    mask = segment(image)
    _, contours, _ = cv2.findContours(mask, mode=cv2.RETR_EXTERNAL, method=cv2.CHAIN_APPROX_SIMPLE)

    return contours

我以所需的水平读取图像,提取前景的蒙版,然后提取轮廓。

这是过程:

输入图像:

enter image description here

面具:

enter image description here

最终图像

enter image description here

一切都很好,我有轮廓和最终图像。 但是正如我之前所说,我想裁剪我的图片,以便我可以应用

sample_and_store_patches_by_row(
        file_name,
        pixel_overlap,
        patch_size=512,
        level=17,
)

并将我的图像平铺为512x512图像。为此,我需要进入轮廓并将其内部平铺。

我一直在为此苦苦挣扎,任何帮助将不胜感激。

谢谢

0 个答案:

没有答案