def get_shape_of_filtered_image(image_file_path): image = imread(image_file_path) lg = LogGabor('default_param.py') lg.set_size(image) i_level = 0 theta = 0 params = { 'sf_0': 1. / (2**i_level), 'B_sf': lg.pe.B_sf, 'theta': theta, 'B_theta': lg.pe.B_theta } FT_lg = lg.loggabor(0, 0, **params) filtered_img_mat = lg.FTfilter(image, FT_lg, full=True) return filtered_img_mat.shape
def get_gabor_features(image_file_path, num_levels, num_orientations): image = imread(image_file_path) opts = { 'vmin': 0., 'vmax': 1., 'interpolation': 'nearest', 'origin': 'upper' } # image = skimage.io.imread lg = LogGabor('default_param.py') lg.set_size(image) # num_features = num_levels*num_orientations*2 # feature_vec = np.zeros((num_features,1)) # phi = (np.sqrt(5) +1.)/2. # golden number # fig = plt.figure(figsize=(fig_width, fig_width/phi)) # xmin, ymin, size = 0, 0, 1. i = 0 for i_level in range(num_levels): # for theta in np.linspace(0, np.pi, num_orientations, endpoint=False): for theta in np.linspace(0, np.pi, num_orientations, endpoint=False): params = { 'sf_0': 1. / (2**i_level), 'B_sf': lg.pe.B_sf, 'theta': theta, 'B_theta': lg.pe.B_theta } # loggabor takes as args: u, v, sf_0, B_sf, theta, B_theta) FT_lg = lg.loggabor(0, 0, **params) filtered_img_mat = lg.FTfilter(image, FT_lg, full=True) # print "SHAPE OF FILTERED IMAGE IS (%s, %s)" % filtered_img_mat.shape im_abs_feature = np.absolute(filtered_img_mat).flatten() # im_abs_feature = np.sum(np.absolute(filtered_img_mat)) # im_sqr_feature = np.sum(np.square(np.real(filtered_img_mat))) # im_sqr_feature = np.sum(np.square(filtered_img_mat)) if i == 0: feature_vec = im_abs_feature else: feature_vec = np.hstack((feature_vec, im_abs_feature)) i += 1 print return feature_vec
if whoswho: return dictx_fit, dictx_fit_param, idx_unfitted, names else: return dictx_fit, dictx_fit_param, idx_unfitted else: if whoswho: return dictx_fit, dictx_fit_param, names else: return dictx_fit, dictx_fit_param def _test(): import doctest doctest.testmod() ##################################### # if __name__ == '__main__': _test() #### Main """ Some examples of use for the class """ lg = LogGabor('./lg_para.py') from SLIP import imread image = imread('database/lena512.png')[:, :, 0] lg.set_size(image)
self.trans(u*1., v*1.) if preprocess : env *= self.f_mask # normalizing energy: env /= np.sqrt((np.abs(env)**2).mean()) # in the case a a single bump (see ``orientation``), we should compensate the fact that the distribution gets complex: env *= np.sqrt(2.) return env def show_loggabor(self, u, v, sf_0, B_sf, theta, B_theta, title='', phase=0.): FT_lg = self.loggabor(u, v, sf_0, B_sf, theta, B_theta) fig, a1, a2 = self.show_FT(FT_lg * np.exp(-1j*phase)) return fig, a1, a2 def _test(): import doctest doctest.testmod() ##################################### # if __name__ == '__main__': _test() #### Main """ Some examples of use for the class """ lg = LogGabor('default_param.py') image = imread('database/lena512.png')[:,:,0] lg.set_size(image)