Python skimage.filters.sobel() Examples

The following are 8 code examples of skimage.filters.sobel(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module skimage.filters , or try the search function .
Example #1
Source File: BlurDetection.py    From python-- with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: generator.py    From ad-versarial with MIT License 6 votes vote down vote up
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 
Example #3
Source File: imgOp.py    From TextDetector with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #4
Source File: test_color.py    From snowy with MIT License 5 votes vote down vote up
def skimage_sobel(image):
    return filters.sobel(image) 
Example #5
Source File: FCN_CrackAnalysis.py    From FCN_for_crack_recognition with MIT License 5 votes vote down vote up
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 
Example #6
Source File: test_skimage.py    From docker-python with Apache License 2.0 5 votes vote down vote up
def test_filter(self):
        image = data.coins()
        filters.sobel(image) 
Example #7
Source File: points.py    From wallgen with MIT License 4 votes vote down vote up
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 
Example #8
Source File: BrightContrastModule.py    From HistoQC with BSD 3-Clause Clear License 4 votes vote down vote up
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