當前位置: 首頁>>代碼示例>>Python>>正文


Python filters.sobel方法代碼示例

本文整理匯總了Python中skimage.filters.sobel方法的典型用法代碼示例。如果您正苦於以下問題:Python filters.sobel方法的具體用法?Python filters.sobel怎麽用?Python filters.sobel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在skimage.filters的用法示例。


在下文中一共展示了filters.sobel方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _Tenengrad

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def _Tenengrad(self,imgName):
        """
                       灰度方差乘積
                       :param imgName:
                       :return:
                       """
        # step 1 圖像的預處理
        img2gray, reImg = self.preImgOps(imgName)
        f = self._imageToMatrix(img2gray)

        tmp = filters.sobel(f)
        source=np.sum(tmp**2)
        source=np.sqrt(source)
        # strp3: 繪製圖片並保存  不應該寫在這裏  抽象出來   這是共有的部分

        newImg = self._drawImgFonts(reImg, str(source))
        newDir = self.strDir + "/_Tenengrad_/"
        if not os.path.exists(newDir):
            os.makedirs(newDir)
        newPath = newDir + imgName
        cv2.imwrite(newPath, newImg)  # 保存圖片
        cv2.imshow(imgName, newImg)
        cv2.waitKey(0)
        return source 
開發者ID:Leezhen2014,項目名稱:python--,代碼行數:26,代碼來源:BlurDetection.py

示例2: get_resized_image

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def get_resized_image(file, ratio):
    img = util.img_as_float(io.imread(file))
    if len(img.shape) >= 3 and img.shape[2] == 4:
        img = color.rgba2rgb(img)
    if len(img.shape) == 2:
        img = color.gray2rgb(img)

    eimg = filters.sobel(color.rgb2gray(img))
    width = img.shape[1]
    height = img.shape[0]

    mode, rm_paths = get_lines_to_remove((width, height), ratio)
    if mode:
        logger.debug("Carving %s %s paths ", rm_paths, mode)
        outh = transform.seam_carve(img, eimg, mode, rm_paths)
        return outh
    else:
        return img 
開發者ID:ftramer,項目名稱:ad-versarial,代碼行數:20,代碼來源:generator.py

示例3: image2edge

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def image2edge(img, mode = None):
	'''_image2edge(img)

	convert image to edge map
	img: 2D_numpy_array 
	Return 2D_numpy_array '''
        if mode == 'canny':
                img = image_norm(img)
                edgeim = numpy.uint8(canny(img))*255
                return edgeim 
        if mode == 'sobel':
                img = image_norm(img)
                edgeim = sobel(img)*255
                return edgeim 
	img = numpy.float32(img)
	im1 = scipy.ndimage.filters.sobel(img,axis=0,mode='constant',cval =0.0)
	im2 = scipy.ndimage.filters.sobel(img,axis=1,mode='constant',cval =0.0)
	return (abs(im1) + abs(im2))/2 
開發者ID:zchengquan,項目名稱:TextDetector,代碼行數:20,代碼來源:imgOp.py

示例4: skimage_sobel

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def skimage_sobel(image):
    return filters.sobel(image) 
開發者ID:prideout,項目名稱:snowy,代碼行數:4,代碼來源:test_color.py

示例5: get_edges

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def get_edges(self, detector='sobel'):
        if detector == 'sobel':
            img = filters.sobel(self.img_gray)
        elif detector == 'canny1':
            img = feature.canny(self.img_gray, sigma=1)
        elif detector == 'canny3':
            img = feature.canny(self.img_gray, sigma=3)
        elif detector == 'scharr':
            img = filters.scharr(self.img_gray)
        elif detector == 'prewitt':
            img = filters.prewitt(self.img_gray)
        elif detector == 'roberts':
            img = filters.roberts(self.img_gray)
        return img 
開發者ID:OnionDoctor,項目名稱:FCN_for_crack_recognition,代碼行數:16,代碼來源:FCN_CrackAnalysis.py

示例6: test_filter

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def test_filter(self):
        image = data.coins()
        filters.sobel(image) 
開發者ID:Kaggle,項目名稱:docker-python,代碼行數:5,代碼來源:test_skimage.py

示例7: genSmartPoints

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def genSmartPoints(image):
	width = image.shape[1]
	height = image.shape[0]

	edges = sobel(image)

	# convert to RGB compatible image
	with warnings.catch_warnings():
		warnings.simplefilter('ignore')
		rgb_img = img_as_ubyte(color.gray2rgb(edges))

	# convert to PIL image
	pimg = Image.fromarray(rgb_img)
	idata = pimg.load()

	edges_data = []

	# get image pixel data and pass through a filter to get only prominent edges

	for x in range(pimg.width):
		for y in range(pimg.height):
			if sum(idata[x,y])/3 > 10:
				edges_data.append((x,y))

	# print(len(edges_data))
	
	# sometimes edges detected wont pass ^ this required case
	if len(edges_data) < 1:
		raise Exception("EdgeDetectionError")
		sys.exit(1)

	# get a n/5 number of points rather than all of the points
	sample = np.random.choice(len(edges_data), len(edges_data)//5 if len(edges_data)/5 < 50000 else 50000)
	edges_data = [edges_data[x] for x in sample]

	# print(len(edges_data))

	points = []
	radius = int(0.1 * (width+height)/2)

	# print(radius)
		
	points = edges_data

	ws = width//50
	hs = height//50

	for x in range(0, width+ws, ws):
		points.append((x,0))
		points.append((x,height))

	for y in range(0, height+hs, hs):
		points.append((0,y))
		points.append((width,y))

	tri = Delaunay(points) # calculate D triangulation of points
	delaunay_points = tri.points[tri.simplices] # find all groups of points

	return delaunay_points 
開發者ID:SubhrajitPrusty,項目名稱:wallgen,代碼行數:61,代碼來源:points.py

示例8: getContrast

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import sobel [as 別名]
def getContrast(s, params):
    logging.info(f"{s['filename']} - \tgetContrast")
    limit_to_mask = strtobool(params.get("limit_to_mask", True))
    img = s.getImgThumb(s["image_work_size"])
    img = rgb2gray(img)

    sobel_img = sobel(img) ** 2

    if limit_to_mask:
        sobel_img = sobel_img[s["img_mask_use"]]
        img = img[s["img_mask_use"]]

    if img.size == 0: # need a check to ensure that mask wasn't empty AND limit_to_mask is true, still want to
                      # produce metrics for completeness with warning

        s.addToPrintList("tenenGrad_contrast", str(-100))
        s.addToPrintList("michelson_contrast", str(-100))
        s.addToPrintList("rms_contrast", str(-100))


        logging.warning(f"{s['filename']} - After BrightContrastModule.getContrast: NO tissue "
                        f"detected, statistics are impossible to compute, defaulting to -100 !")
        s["warnings"].append(f"After BrightContrastModule.getContrast: NO tissue remains "
                             f"detected, statistics are impossible to compute, defaulting to -100 !")

        return


    # tenenGrad - Note this must be performed on full image and then subsetted if limiting to mask
    tenenGrad_contrast = np.sqrt(np.sum(sobel_img)) / img.size
    s.addToPrintList("tenenGrad_contrast", str(tenenGrad_contrast))

    # Michelson contrast
    max_img = img.max()
    min_img = img.min()
    contrast = (max_img - min_img) / (max_img + min_img)
    s.addToPrintList("michelson_contrast", str(contrast))

    # RMS contrast
    rms_contrast = np.sqrt(pow(img - img.mean(), 2).sum() / img.size)
    s.addToPrintList("rms_contrast", str(rms_contrast))

    return 
開發者ID:choosehappy,項目名稱:HistoQC,代碼行數:45,代碼來源:BrightContrastModule.py


注:本文中的skimage.filters.sobel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。