当前位置: 首页>>代码示例>>Python>>正文


Python cv2.equalizeHist方法代码示例

本文整理汇总了Python中cv2.equalizeHist方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.equalizeHist方法的具体用法?Python cv2.equalizeHist怎么用?Python cv2.equalizeHist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.equalizeHist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def main():
	imagePath = "img.jpg"
	
	img = cv2.imread(imagePath)
	gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
	
	generate_histogram(gray)
	
	cv2.imwrite("before.jpg", gray)

	gray = cv2.equalizeHist(gray)
	
	generate_histogram(gray)
	
	cv2.imwrite("after.jpg",gray)
	
	return 0 
开发者ID:felipecorrea,项目名称:pedestrian-haar-based-detector,代码行数:19,代码来源:histcomparison.py

示例2: _normalize_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def _normalize_image(self, image: np.ndarray,
                         eye_or_face: FaceParts) -> None:
        camera_matrix_inv = np.linalg.inv(self.camera.camera_matrix)
        normalized_camera_matrix = self.normalized_camera.camera_matrix

        scale = self._get_scale_matrix(eye_or_face.distance)
        conversion_matrix = scale @ eye_or_face.normalizing_rot.as_matrix()

        projection_matrix = normalized_camera_matrix @ conversion_matrix @ camera_matrix_inv

        normalized_image = cv2.warpPerspective(
            image, projection_matrix,
            (self.normalized_camera.width, self.normalized_camera.height))

        if eye_or_face.name in {FacePartsName.REYE, FacePartsName.LEYE}:
            normalized_image = cv2.cvtColor(normalized_image,
                                            cv2.COLOR_BGR2GRAY)
            normalized_image = cv2.equalizeHist(normalized_image)
        eye_or_face.normalized_image = normalized_image 
开发者ID:hysts,项目名称:pytorch_mpiigaze,代码行数:21,代码来源:head_pose_normalizer.py

示例3: _augment_batch_

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def _augment_batch_(self, batch, random_state, parents, hooks):
        if batch.images is None:
            return batch

        images = batch.images

        iadt.allow_only_uint8(images, augmenter=self)

        for i, image in enumerate(images):
            if image.size == 0:
                continue

            image_warped = [
                cv2.equalizeHist(_normalize_cv2_input_arr_(image[..., c]))
                for c in sm.xrange(image.shape[2])]
            image_warped = np.array(image_warped, dtype=image_warped[0].dtype)
            image_warped = image_warped.transpose((1, 2, 0))

            batch.images[i] = image_warped
        return batch 
开发者ID:aleju,项目名称:imgaug,代码行数:22,代码来源:contrast.py

示例4: manipulate_images

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def manipulate_images(sample_image):
    batch = []
    cnt = 0
    dx = 40
    ds = 512
    for i in range(0, sample_image.shape[0] - 3, 3):
        tmp = []
        for j in range(3):
            img = sample_image[i + j]
            img = 255.0 / np.amax(img) * img
            img = cv2.equalizeHist(img.astype(np.uint8))
            img = img[dx: ds - dx, dx: ds - dx]
            img = cv2.resize(img, (224, 224))
            tmp.append(img)

        batch.append(tmp)
    batch = np.array(batch, dtype=np.float32)
    return batch 
开发者ID:Azure,项目名称:sql_python_deep_learning,代码行数:20,代码来源:lung_cancer_utils.py

示例5: getRegions

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def getRegions(img):
    grayImg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    # grayImg = cv2.equalizeHist(np.copy(grayImg))
    edges = cv2.Canny(grayImg,100,200,apertureSize = 3) 
    if DEBUG:
        utils.display([('Canny Edge Detection', edges)])
    kernel = np.ones((3,3),np.uint8)
    edges = cv2.dilate(edges,kernel,iterations = 14)
    # edges = 255-edges
    # utils.display([('', edges)])
    contours, hierarchy = cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    if DEBUG:
        utils.display([('Contours', edges)])
    # Only take contours of a certain size
    regions = []
    for contour in contours:
        imgH, imgW, _ = img.shape
        [x, y, w, h] = cv2.boundingRect(contour)
        if w < 50 or h < 50:
            pass
        elif w > .95*imgW or h > .95*imgH:
            pass
        else:
            regions.append((x, y, x+w, y+h))
    return regions 
开发者ID:agundy,项目名称:BusinessCardReader,代码行数:27,代码来源:process.py

示例6: getFaceCoordinates

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def getFaceCoordinates(image):
    cascade = cv2.CascadeClassifier(CASCADE_PATH)
    
    img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    img_gray = cv2.equalizeHist(img_gray)
    rects = cascade.detectMultiScale(
        img_gray,
        scaleFactor=1.1,
        minNeighbors=3,
        minSize=(48, 48)
        )

    # For now, we only deal with the case that we detect one face.
    if(len(rects) != 1) :
        return None
    
    face = rects[0]
    bounding_box = [face[0], face[1], face[0] + face[2], face[1] + face[3]]

    # return map((lambda x: x), bounding_box)
    return bounding_box 
开发者ID:a514514772,项目名称:Real-Time-Facial-Expression-Recognition-with-DeepLearning,代码行数:23,代码来源:face_detection_utilities.py

示例7: hist_equalization

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def hist_equalization(gray_img):
    """Histogram equalization is a method to normalize the distribution of intensity values. If the image has low
       contrast it will make it easier to threshold.

    Inputs:
    gray_img    = Grayscale image data

    Returns:
    img_eh = normalized image

    :param gray_img: numpy.ndarray
    :return img_eh: numpy.ndarray
    """

    if len(np.shape(gray_img)) == 3:
        fatal_error("Input image must be gray")

    img_eh = cv2.equalizeHist(gray_img)
    params.device += 1
    if params.debug == 'print':
        print_image(img_eh, os.path.join(params.debug_outdir, str(params.device) + '_hist_equal_img.png'))
    elif params.debug == 'plot':
        plot_image(img_eh, cmap='gray')

    return img_eh 
开发者ID:danforthcenter,项目名称:plantcv,代码行数:27,代码来源:hist_equalization.py

示例8: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def main():
    # read an image 
    img = cv2.imread('../figures/_DSC2126.jpg')
    img = cv2.resize(img, (600,400))
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    
    # hist,bins = np.histogram(img[100:400, 100:400].flatten(),256,[0,256])
    # cdf = hist.cumsum()
    # cdf_normalized = cdf * hist.max()/ cdf.max()
    
    # # plot hist normalized 
    # plot_hist_cdf(cdf_normalized, img[100:400, 100:400])
        
    equ = cv2.equalizeHist(gray)
    
    # create a CLAHE object (Arguments are optional).
    clahe = cv2.createCLAHE()
    cl1 = clahe.apply(gray)
    
    plot_gray(gray, equ, cl1) 
开发者ID:PacktPublishing,项目名称:Practical-Computer-Vision,代码行数:23,代码来源:03_hist_equalize.py

示例9: __call__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def __call__(self, image, labels=None):
        image[:,:,2] = cv2.equalizeHist(image[:,:,2])
        if labels is None:
            return image
        else:
            return image, labels 
开发者ID:pierluigiferrari,项目名称:data_generator_object_detection_2d,代码行数:8,代码来源:object_detection_2d_photometric_ops.py

示例10: normalize_grayimage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def normalize_grayimage(image):
	image = cv2.equalizeHist(image)
	#cv2.imshow("Equalized img", image)
	
	return image 
开发者ID:felipecorrea,项目名称:pedestrian-haar-based-detector,代码行数:7,代码来源:evaluation.py

示例11: normalize_grayimage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def normalize_grayimage(image):
	image = cv2.equalizeHist(image)
	cv2.imshow("Equalized img", image)
	
	return image 
开发者ID:felipecorrea,项目名称:pedestrian-haar-based-detector,代码行数:7,代码来源:detect.py

示例12: preprocess

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def preprocess(self, img, equalizeHist):
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        return (cv2.equalizeHist(gray) if equalizeHist else gray) 
开发者ID:xsyann,项目名称:detection,代码行数:5,代码来源:detector.py

示例13: pre_process_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def pre_process_image(image):
    #image = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
    #print(image)
	
    image[:,:,0] = cv2.equalizeHist(image[:,:,0])
    image[:,:,1] = cv2.equalizeHist(image[:,:,1])
    image[:,:,2] = cv2.equalizeHist(image[:,:,2])
    image = image/255. - 0.5
    return image 
开发者ID:evtimovi,项目名称:robust_physical_perturbations,代码行数:11,代码来源:calc_accuracy_yadav.py

示例14: pre_process_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def pre_process_image(image):
    #image = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
    #print(image)
	
    #image[:,:,0] = cv2.equalizeHist(image[:,:,0])
    #image[:,:,1] = cv2.equalizeHist(image[:,:,1])
    #image[:,:,2] = cv2.equalizeHist(image[:,:,2])
    image = image/255.-0.5
    return image 
开发者ID:evtimovi,项目名称:robust_physical_perturbations,代码行数:11,代码来源:train_yadav.py

示例15: preprocess_yadav

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import equalizeHist [as 别名]
def preprocess_yadav(image):
    '''
    Pre-process the image given as a Numpy array
    for the Yadav model.
    :param image: the image as a numpy array
    :return: a preprocessed image
    '''
    image = image.astype(np.uint8)
#    image[:, :, 0] = cv2.equalizeHist(image[:, :, 0])
#    image[:, :, 1] = cv2.equalizeHist(image[:, :, 1])
#    image[:, :, 2] = cv2.equalizeHist(image[:, :, 2])
    image = image/255. - 0.5
    return image.astype(np.float32) 
开发者ID:evtimovi,项目名称:robust_physical_perturbations,代码行数:15,代码来源:dataproc.py


注:本文中的cv2.equalizeHist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。