def LBP(img, save=False, parms=None, subtract=False, method='uniform'): """Get the LBP image (reference: http://goo.gl/aeADZd) @param img: image array Keyword arguments: save -- True to save the image parms -- [points, radius] (default: None) subtract -- True to subtract values to pts (default: False) """ from skimage.feature import local_binary_pattern if is_rgb(img): img = conv_gray(img) if parms is None: pts = int(img.shape[0] * img.shape[1] * 0.0003) radius = min(img.shape[0], img.shape[1]) * 0.015 else: pts = parms[0] radius = parms[1] lbp = local_binary_pattern(img, pts, radius, method=method) if subtract: lbp = np.abs(lbp - pts) if save: from dyda_utils import plot plot.Plot().plot_matrix(lbp, fname='lbp_cm.png', show_text=False, show_axis=False, norm=False) return lbp
def overlay_text(img, save=False, T_H=1): """Get D, more details see http://goo.gl/d3GQ3T @param img: image array Keyword arguments: T_H -- threshold used for the transition map save -- True to save the image """ tilde_s = tilde_s(img, save=save) intensity = intensity(img, save=save) diff_tilde_s = np.diff(tilde_s) diff_int = np.absolute(np.diff(intensity)) D_L = cal_d(diff_tilde_s, diff_int) + 1 D_R = cal_d(diff_tilde_s, diff_int, left=False) T = np.where(D_R > D_L, 1, 0) if save: from dyda_utils import plot plot.Plot().plot_matrix(T, fname='T_cm.png', show_text=False, show_axis=False, norm=False) return T
def max_s(img, save=False): """Get maxS, more details see http://goo.gl/d3GQ3T @param img: image array Keyword arguments: save -- True to save the image (default: False) """ intensity = intensity(img, save=save) max_s = np.where(intensity > 0.5, 2 * (0.5 - intensity), 2 * intensity) if save: from dyda_utils import plot plot.Plot().plot_matrix(max_s, fname='max_s_cm.png', show_text=False, show_axis=False, norm=False) return max_s
def morph_dilation(img, rs=0.01, save=False): """Apply Morphological dilation transform @param img: image array Keyword arguments: shape -- width of the kernel save -- True to save the image """ shape = int(min(img.shape[0], img.shape[1]) * rs) kernel = np.ones((shape, shape), np.uint8) dil = cv2.dilate(img, kernel, iterations=1) if save: from dyda_utils import plot plot.Plot().plot_matrix(dil, fname='dil_cm.png', show_text=False, show_axis=False, norm=False) return dil
def morph_closing(img, hr=0.1, wr=0.2, save=False): """Apply Morphological closing transform @param img: image array Keyword arguments: hr -- ratio to the height, for closing window (default: 0.1) wr -- ratio to the width, for closing window (default: 0.2) save -- True to save the image """ h = int(img.shape[0] * hr) w = int(img.shape[1] * wr) kernel = np.ones((h, w), np.uint8) closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel) if save: from dyda_utils import plot plot.Plot().plot_matrix(closing, fname='closing_cm.png', show_text=False, show_axis=False, norm=False) return closing
def satuation(img, save=False): """Get the image satuation @param img: image array Keyword arguments: save -- True to save the image (default: False) """ if not is_rgb(img): print('ERROR: Cannot support grayscale images') sys.exit(0) np.seterr(divide='ignore') sat = 1 - np.divide(3, (img.sum(axis=2) * img.min(axis=2))) sat[np.isneginf(sat)] = 0 if save: from dyda_utils import plot plot.Plot().plot_matrix(sat, fname='sat_cm.png', show_text=False, show_axis=False, norm=False) return sat
def intensity(img, save=False): """Get the pixel intensity @param img: image array Keyword arguments: save -- True to save the image """ if is_rgb(img): intensity = conv_gray(img) else: intensity = img intensity = intensity.astype(float) intensity *= (1.0 / intensity.max()) if save: from dyda_utils import plot plot.Plot().plot_matrix(intensity, fname='intensity_cm.png', show_text=False, show_axis=False, norm=False) return intensity