python类filters()的实例源码

utils.py 文件源码 项目:histonets-cv 作者: sul-cidr 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def match_template_mask(image, template, mask=None, method=None, sigma=0.33):
    """Match template against image applying mask to template using method.
    Method can be either of (None, 'laplacian', 'sobel', 'scharr', 'prewitt',
    'roberts', 'canny').
    Returns locations to look for max values."""
    if mask is not None:
        if method:
            kernel = np.ones((3, 3), np.uint8)
            mask = cv2.erode(mask, kernel)
            if method == 'laplacian':
                # use CV_64F to not loose edges, convert to uint8 afterwards
                edge_image = np.uint8(np.absolute(
                    cv2.Laplacian(image, cv2.CV_64F)))
                edge_template = np.uint8(np.absolute(
                    cv2.Laplacian(template, cv2.CV_64F)
                ))
            elif method in ('sobel', 'scharr', 'prewitt', 'roberts'):
                filter_func = getattr(skfilters, method)
                edge_image = filter_func(image)
                edge_template = filter_func(template)
                edge_image = convert(edge_image)
                edge_template = convert(edge_template)
            else:  # method == 'canny'
                values = np.hstack([image.ravel(), template.ravel()])
                median = np.median(values)
                lower = int(max(0, (1.0 - sigma) * median))
                upper = int(min(255, (1.0 + sigma) * median))
                edge_image = cv2.Canny(image, lower, upper)
                edge_template = cv2.Canny(template, lower, upper)
            results = cv2.matchTemplate(edge_image, edge_template & mask,
                                        cv2.TM_CCOEFF_NORMED)
        else:
            results = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED,
                                        mask)
    else:
        results = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
    return results
samuroidata.py 文件源码 项目:SamuROI 作者: samuroi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def threshold(self, t):
        self.__threshold = t
        self.threshold_changed()
        elevation_map = skimage.filters.sobel(self.morphology)

        markers = numpy.zeros_like(self.morphology)
        markers[self.morphology < self.threshold] = 1
        markers[self.morphology > self.threshold * 1.1] = 2
        segmentation = skimage.morphology.watershed(elevation_map, markers)

        self.overlay = segmentation == 2


问题


面经


文章

微信
公众号

扫码关注公众号