Example #1
0
def adaptive_histogram_equalize(src):
    is_color = face_detect.is_color(src)
    if is_color:
        ycrcb = cv2.cvtColor(src, cv2.COLOR_BGR2YCR_CB)
        y, cr, cb = cv2.split(ycrcb)
    else:
        y = src
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(4, 4))
    dst = clahe.apply(y)
    # dst = cv2.equalizeHist(y)
    if is_color:
        ycrcb = cv2.merge((dst, cr, cb))
        dst = cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR)
    return dst
Example #2
0
def adaptive_histogram_equalize(src):
    is_color = face_detect.is_color(src)
    if is_color:
        ycrcb = cv2.cvtColor(src, cv2.COLOR_BGR2YCR_CB)
        y, cr, cb = cv2.split(ycrcb)
    else:
        y = src
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(4, 4))
    dst = clahe.apply(y)
    # dst = cv2.equalizeHist(y)
    if is_color:
        ycrcb = cv2.merge((dst, cr, cb))
        dst = cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR)
    return dst
Example #3
0
def auto_crop_hsv(src, crop_white=False):
    try:
        if face_detect.is_color(src):
            hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
            h, s, v = cv2.split(hsv)
        else:
            v = src
        if crop_white:
            v = abs(255-v)  # invert light to dark
        threshval, thresh = cv2.threshold(v, 20, 255, cv2.THRESH_BINARY)  # simple global thresh to get anything "blackish"
        projx = [sum(col) for col in thresh.transpose()]
        projy = [sum(row) for row in thresh]
        nonzero = lambda value: value > 0
        x1 = first_index_of(projx, nonzero)
        x2 = last_index_of(projx, nonzero)
        y1 = first_index_of(projy, nonzero)
        y2 = last_index_of(projy, nonzero)
        cropped = src[y1:y2+1, x1:x2+1]
        return cropped
    except:
        return src
Example #4
0
def auto_crop_hsv(src, crop_white=False):
    try:
        if face_detect.is_color(src):
            hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
            h, s, v = cv2.split(hsv)
        else:
            v = src
        if crop_white:
            v = abs(255 - v)  # invert light to dark
        threshval, thresh = cv2.threshold(
            v, 20, 255, cv2.THRESH_BINARY
        )  # simple global thresh to get anything "blackish"
        projx = [sum(col) for col in thresh.transpose()]
        projy = [sum(row) for row in thresh]
        nonzero = lambda value: value > 0
        x1 = first_index_of(projx, nonzero)
        x2 = last_index_of(projx, nonzero)
        y1 = first_index_of(projy, nonzero)
        y2 = last_index_of(projy, nonzero)
        cropped = src[y1:y2 + 1, x1:x2 + 1]
        return cropped
    except:
        return src
Example #5
0
def lightness_score(im):
    if face_detect.is_color(im):
        hls = cv2.cvtColor(im, cv2.cv.CV_BGR2HLS)
        return hls[:, :, 1].mean() / 255.0
    return im.mean() / 255.0
Example #6
0
def lightness_score(im):
    if face_detect.is_color(im):
        hls = cv2.cvtColor(im, cv2.cv.CV_BGR2HLS)
        return hls[:, :, 1].mean()/255.0
    return im.mean()/255.0