Python skimage.feature.local_binary_pattern() Examples

The following are 5 code examples of skimage.feature.local_binary_pattern(). 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.feature , or try the search function .
Example #1
Source File: skimage_lbp_simple.py    From optuna with MIT License 6 votes vote down vote up
def objective(trial):
    # Get Olivetti faces dataset.
    x_ref, x_valid, y_ref, y_valid = load_data()

    # We optimize parameters of local_binary_pattern function in skimage
    # and the choice of distance metric classes.
    P = trial.suggest_int("P", 1, 15)
    R = trial.suggest_uniform("R", 1, 10)
    method = trial.suggest_categorical("method", ["default", "uniform"])
    metric = trial.suggest_categorical("metric", ["kl", "cos", "euc"])

    x_ref_hist = img2hist(x_ref, P, R, method)
    x_valid_hist = img2hist(x_valid, P, R, method)
    dist = calc_dist(x_ref_hist, x_valid_hist, metric)

    y_pred = np.argmin(dist, axis=1)
    accuracy = sklearn.metrics.accuracy_score(y_valid, y_pred)
    return accuracy 
Example #2
Source File: toolbox.py    From stagesepx with MIT License 5 votes vote down vote up
def turn_lbp_desc(old: np.ndarray, radius: int = None) -> np.ndarray:
    if not radius:
        radius = 3
    n_points = 8 * radius

    grey = turn_grey(old)
    lbp = local_binary_pattern(grey, n_points, radius, method="default")
    return lbp 
Example #3
Source File: Demo_localBinaryPattern.py    From pyimagevideo with GNU General Public License v3.0 5 votes vote down vote up
def demoLBP(fn):
    fn = Path(fn).expanduser()
    vid = cv2.VideoCapture(str(fn))
#    vidparam = getaviprop(vid)

    while True:
        ret, img = vid.read()
        if not ret:
            break
        if img.ndim == 3:
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        lbp = local_binary_pattern(img, 8, 3, 'default')
        cv2.imshow('lbp', lbp)
        cv2.waitKey(delay=1) 
Example #4
Source File: skimage_lbp_simple.py    From optuna with MIT License 5 votes vote down vote up
def get_lbp_hist(img, P, R, method):
    lbp = ft.local_binary_pattern(img, P, R, method)
    if method == "uniform":
        bin_max = P + 3
        range_max = P + 2
    elif method == "default":
        bin_max = 2 ** P
        range_max = 2 ** P - 1
    hist, _ = np.histogram(
        lbp.ravel(), density=True, bins=np.arange(0, bin_max), range=(0, range_max)
    )
    return hist 
Example #5
Source File: ClassificationModule.py    From HistoQC with BSD 3-Clause Clear License 5 votes vote down vote up
def compute_lbp(img, params):
    lbp_radius = float(params.get("lbp_radius", 3))
    lbp_points = int(params.get("lbp_points", 24))  # example sets radius * 8
    lbp_method = params.get("lbp_method", "default")

    return local_binary_pattern(rgb2gray(img), P=lbp_points, R=lbp_radius, method=lbp_method)[:, :, None]