當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。