%load_ext autoreload
%autoreload 2
import os
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
fopts = {'fontsize':18}
from SLIP import Image, imread
help(Image)
Help on class Image in module SLIP.SLIP: class Image(builtins.object) | Image(pe='https://raw.githubusercontent.com/bicv/SLIP/master/default_param.py') | | This library collects different Image Processing tools. | | Fork me on https://github.com/bicv/SLIP ! | | This library is used in other projects, in particular for use with the ``LogGabor`` and ``SparseEdges`` libraries | For more information check respective pages @ | - http://pythonhosted.org/LogGabor and | - http://pythonhosted.org/SparseEdges | | Collects image processing routines for one given image size: | - Some classical related to pure Fourier number crunching: | - creating masks | - normalize, | - fourier_grid : defines a useful grid for generating filters in FFT | - show_FT : displays the envelope and impulse response of a filter | - invert : go to the other of the fourier transform | - Some usual application of Fourier filtering: | - trans : translation filter in Fourier space | - whitening procedures | - Some related to handling experiments: | - load_in_database : loads a random image in a folder and | - patch : takes a random patch of the correct size | | Methods defined here: | | FTfilter(self, image, FT_filter, full=False) | Using the ``FTfilter`` function, it is easy to filter an image with a filter defined in Fourier space. | | __init__(self, pe='https://raw.githubusercontent.com/bicv/SLIP/master/default_param.py') | Initializes the Image class | | May take as input: | | - a dictionary containing parameters | - a ``ndarray`` (dimensions ``N_X`` and ``N_Y`` are guessed from this array) | - a string representing a file or URL pointing to an image file | - a string pointing to a file or URL containing a dictionary of parameters (or simply the name of the file) | - a ``NeuroTools.parameters.ParameterSet`` object containing parameters | | Parameters are | | - N_X and N_Y which are respectively the number of pixels in the vertical and horizontal dimensions respectively (MANDATORY) | - optional parameters which are used in the various functions such as N_image when handling a database or the whitening parameters. | | dewhitening(self, white, preprocess=True, center=True, use_max=True, f_0=None) | Returns the dewhitened image | | enveloppe_color(self, alpha) | | extract_patches_2d(self, image, patch_size, N_patches) | Reshape a 2D image into a collection of patches | | redundant with self.patch, but similar call as | https://github.com/scikit-learn/scikit-learn/blob/14031f6/sklearn/feature_extraction/image.py#L300 | | fourier(self, image, full=True) | Using the ``fourierr`` function, it is easy to retieve its Fourier transformation. | | fourier_grid(self) | use that function to define a reference frame for envelopes in Fourier space. | In general, it is more efficient to define dimensions as powers of 2. | | frequency_angle(self) | | frequency_radius(self) | | full_url(self, name_database) | | get_imagelist(self, exp, name_database='natural') | returns an imagelist from a pickled database. | | If the stored imagelist does not exist, creates it. | The ``exp`` string allows to tag the list for a particular experiment. | | get_pe(self, pe) | Guesses the parameters from the init variable | | We perform a duck-typing to guess parameters from different possible sources. | outputs a ParameterSet | | get_size(self, im) | | hist_radial_frequency(self, FT, N_f=20) | A simple function to compute a radial histogram in different spatial frequency bands. | | imread(self, URL, resize=True) | | imshow(self, image, fig=None, ax=None, cmap=<matplotlib.colors.LinearSegmentedColormap object at 0x11a03e250>, axis=False, norm=True, center=True, xlabel='Y axis', ylabel='X axis', figsize=None, mask=False, vmin=-1, vmax=1) | Plotting routine to show an image | | Place the [0,0] index of the array in the upper left corner of the axes. | Data limits for the axes. The default assigns zero-based row, column | indices to the x, y centers of the pixels. | Note that the convention for coordinates follows that of matrices: the | origin is at the top left of the image, and coordinates are first the | rows (vertical axis, going down) then the columns (horizontal axis, | going right). | | init(self, mask_exponent=3.0) | Initializes different convenient matrices for image processing. | | To be called when keeping the same Image object but changing the size of the image. | | init_logging(self, filename='debug.log', name='SLIP') | | invert(self, FT_image, full=False) | # Fourier number crunching | | list_database(self, name_database) | Returns a list of the files in a folder | | load_in_database(self, name_database, i_image=None, filename=None, verbose=True) | Loads a random image from the database ``name_database``. | | The strategy is to pick one image in the folder using the list provided by the ``list_database``function. | | TODO: it would be useful to be able to load from standard databases such as http://www.cps.utexas.edu/natural_scenes/db.shtml | | low_pass(self, f_0, steepness) | Returns the low_pass filter used by (Olshausen, 98) | | parameters from Atick (p.240) | f_0 = 22 c/deg in primates: the full image is approx 45 deg | alpha makes the aspect change (1=diamond on the vert and hor, 2 = anisotropic) | | from Olshausen 98 (p.11): | f_0 = 200 cycles / image (512 x 512 images) | in absolute coordinates : f_0 = 200 / 512 / 2 | | steepness is to produce a "fairly sharp cutoff" | | make_imagelist(self, name_database, verbose=False) | Makes a list of images with no repetition. | | Takes as an input the name of a database (the name of a folder in the ``datapath``), | returns a list of the filenames along with the crop area. | | mkdir(self) | Initializes two folders for storing intermediate matrices and images. | | To be called before any operation to store or retrieve a result or figure. | | normalize(self, image, center=True, use_max=True) | | olshausen_whitening_filt(self, f_0) | Returns the whitening filter used by (Olshausen, 98) | | patch(self, name_database, i_image=None, filename=None, croparea=None, threshold=0.2, verbose=True, preprocess=True, center=True, use_max=True, do_whitening=False) | takes a subimage of size s (a tuple) | | does not accept if energy is relatively below a threshold (flat image) | | pipeline(self, image, preprocess=True, center=True, use_max=True, do_whitening=False) | pre-processing pipeline | | power_spectrum(self, image) | | preprocess(self, image) | Returns the pre-processed image | | From raw pixelized images, we want to keep information that is relevent to the content of | the objects in the image. In particular, we want to avoid: | | - information that would not be uniformly distributed when rotating the image. In | particular, we discard information outside the unit disk in Fourier space, in particular | above the Nyquist frequency, | - information that relates to information of the order the size of the image. This | involves discarding information at low-level frequencies. | | See https://laurentperrinet.github.io/sciblog/posts/2015-05-21-a-simple-pre-processing-filter-for-image-processing.html | for more information. | | retina(self, df=0.07, sigma=0.5) | A parametric description of the envelope of retinal processsing. | See https://laurentperrinet.github.io/sciblog/posts/2015-05-21-a-simple-pre-processing-filter-for-image-processing.html | for more information. | | In digital images, some of the energy in Fourier space is concentrated outside the | disk corresponding to the Nyquist frequency. Let's design a filter with: | | - a sharp cut-off for radial frequencies higher than the Nyquist frequency, | - times a smooth but sharp transition (implemented with a decaying exponential), | - times a high-pass filter designed by one minus a gaussian blur. | | This filter is rotation invariant. | | Note that this filter is defined by two parameters: | - one for scaling the smoothness of the transition in the high-frequency range, | - one for the characteristic length of the high-pass filter. | | The first is defined relative to the Nyquist frequency (in absolute values) while the second | is relative to the size of the image in pixels and is given in number of pixels. | | savefig(self, fig, fname, figpath='', formats=None, display=True) | | set_size(self, im) | Re-initializes the Image class with the size given in ``im`` | | May take as input: | | - a numpy array, | - a string representing a file or URL pointing to an image file | - a tuple | | Updated parameters are | | - N_X and N_Y which are respectively the number of pixels in the vertical and horizontal dimensions respectively (MANDATORY) | | show_FT(self, FT_image, fig=None, figsize=None, a1=None, a2=None, axis=False, title=True, FT_title='Spectrum', im_title='Image', norm=True, vmin=-1.0, vmax=1.0) | | show_image_FT(self, image, FT_image, fig=None, figsize=None, a1=None, a2=None, axis=False, title=True, FT_title='Spectrum', im_title='Image', norm=True, vmin=-1.0, vmax=1.0) | | show_spectrum(self, image, fig=None, figsize=None, a1=None, a2=None, axis=False, title=True, FT_title='Spectrum', im_title='Image', norm=True, vmin=-1.0, vmax=1.0) | | trans(self, u, v) | | translate(self, image, vec, preshift=True) | Translate image by vec (in pixels) | | Note that the convention for coordinates follows that of matrices: the origin is at the top left of the image, and coordinates are first the rows (vertical axis, going down) then the columns (horizontal axis, going right). | | whitening(self, image, f_0=None) | Returns the whitened image | | whitening_filt(self, recompute=False, f_0=None) | Returns the envelope of the whitening filter. | | if we chose one based on structural assumptions (``struct=True``) | then we return a 1/f spectrum based on the assumption that the structure of images | is self-similar and thus that the Fourier spectrum scales a priori in 1/f. | | elif we chose to learn, | returns theaverage correlation filter in FT space. | | Computes the average power spectrum = FT of cross-correlation, the mean decorrelation | is given for instance by (Attick, 92). | | else | we return the parametrization based on Olshausen, 1996 | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined)
The SLIP object may be initialized by giving some parameters. These could be given using
im = Image() # default is 'https://raw.githubusercontent.com/bicv/SLIP/master/default_param.py'
print(im.pe)
{'N_X': 256, 'N_Y': 256, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
N_X
and N_Y
and mask_exponent
are mandatory)im = Image({'N_X':32, 'N_Y':64})
print(im.pe)
{'N_X': 32, 'N_Y': 64, 'verbose': 10, 'mask_exponent': 3.0}
ndarray
(dimensions N_X
and N_Y
are guessed from this array)im = Image(np.empty((32, 64)))
print(im.pe)
{'N_X': 32, 'N_Y': 64, 'verbose': 10, 'mask_exponent': 3.0}
im = Image('database/lena64.png')
print(im.pe)
{'N_X': 64, 'N_Y': 64, 'verbose': 10, 'mask_exponent': 3.0}
im = Image('http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png')
print(im.pe)
{'N_X': 1058, 'N_Y': 1058, 'verbose': 10, 'mask_exponent': 3.0}
im = Image('file://default_param.py')
im = Image('default_param.py')
print(im.pe.keys())
dict_keys(['N_X', 'N_Y', 'do_mask', 'mask_exponent', 'use_cache', 'verbose', 'figpath', 'matpath', 'datapath', 'figsize', 'formats', 'dpi', 'seed', 'N_image', 'white_name_database', 'white_n_learning', 'white_N', 'white_f_0', 'white_alpha', 'white_steepness', 'white_recompute'])
im = Image('https://raw.githubusercontent.com/bicv/SLIP/master/default_param.py')
print(im.pe.keys())
dict_keys(['N_X', 'N_Y', 'do_mask', 'mask_exponent', 'use_cache', 'verbose', 'figpath', 'matpath', 'datapath', 'figsize', 'formats', 'dpi', 'seed', 'N_image', 'white_name_database', 'white_n_learning', 'white_N', 'white_f_0', 'white_alpha', 'white_steepness', 'white_recompute'])
from NeuroTools.parameters import ParameterSet
from SLIP import Image
im = Image(ParameterSet({'N_X':128, 'N_Y':256}))
The parameters may be handled using the properties of the ParameterSet
object.
help(im.set_size)
Help on method set_size in module SLIP.SLIP: set_size(im) method of SLIP.SLIP.Image instance Re-initializes the Image class with the size given in ``im`` May take as input: - a numpy array, - a string representing a file or URL pointing to an image file - a tuple Updated parameters are - N_X and N_Y which are respectively the number of pixels in the vertical and horizontal dimensions respectively (MANDATORY)
im = Image() # default is {'N_X':128, 'N_Y':128}
print(im.pe)
{'N_X': 256, 'N_Y': 256, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
im.set_size((512, 234))
print(im.pe)
{'N_X': 512, 'N_Y': 234, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
im.set_size(np.ones((512, 234)))
print(im.pe)
{'N_X': 512, 'N_Y': 234, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
im.set_size('http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png')
print(im.pe)
{'N_X': 1058, 'N_Y': 1058, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
we use https://docs.python.org/3.4/library/logging.html to handle logging of events
im = Image()
print('Verbosity level=', im.pe.verbose)
Verbosity level= 0
im.log.debug(' > this should not appear')
im.log.info(' > this should not appear')
im.log.error(' > this *should* appear')
im.pe.verbose = 15
im.init_logging()
im.log.debug(' > this should not appear')
im.log.info(' > this *should* appear')
im.log.error(' > this *should* appear')
TODO
try:
Image({'N_X':128, 'N_Y':-12, 'mask_exponent':3})
except Exception as e:
print(e)
negative dimensions are not allowed
Note that if the image is of a different size, the size of the Image
object is adapted:
im = Image()
print(im.pe)
image = im.imread('database/lena64.png')
print(im.pe)
{'N_X': 256, 'N_Y': 256, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False} {'N_X': 64, 'N_Y': 64, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
image = im.imread('http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png')
print(im.pe)
{'N_X': 1058, 'N_Y': 1058, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
'N_X' in im.pe.keys()
True
im = Image()
print(im.pe)
image = im.imread('database/lena64.png')
_ = im.imshow(image)
{'N_X': 256, 'N_Y': 256, 'do_mask': True, 'mask_exponent': 3.0, 'use_cache': True, 'verbose': 0, 'figpath': 'results', 'matpath': 'cache_dir', 'datapath': 'database', 'figsize': 14.0, 'formats': ['pdf', 'png', 'jpg'], 'dpi': 450, 'seed': None, 'N_image': None, 'white_name_database': 'kodakdb', 'white_n_learning': 0, 'white_N': 0.07, 'white_f_0': 0.38, 'white_alpha': 1.4, 'white_steepness': 4.0, 'white_recompute': False}
image = im.imread('http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png')
_ = im.imshow(image)
_ = im.show_spectrum(image)
axs = []
im = Image({'N_X':32, 'N_Y':128, 'seed':None, 'do_mask':False})
im.pe.datapath = 'database/'
for name_database in ['serre07_targets', 'serre07_distractors']:
fig = plt.figure(figsize=(14, 3.5))
for _ in range(4):
image, filename, croparea = im.patch(name_database, )
ax = fig.add_subplot(1, 4, _+1)
im.imshow(image, fig=fig, ax=ax)
fig.show()
Using image F_land93.jpg Cropping @ [top, bottom, left, right]: [199, 231, 98, 226] Using image M_N136020.jpg Cropping @ [top, bottom, left, right]: [162, 194, 70, 198] Using image B_N289052.jpg Cropping @ [top, bottom, left, right]: [151, 183, 28, 156] Using image F_N253078.jpg Cropping @ [top, bottom, left, right]: [185, 217, 64, 192] Using image Bda_art682.jpg Cropping @ [top, bottom, left, right]: [166, 198, 59, 187] Using image Mdn_land760.jpg Cropping @ [top, bottom, left, right]: [105, 137, 71, 199] Using image Fdn_nat1238.jpg Cropping @ [top, bottom, left, right]: [148, 180, 38, 166] Using image Hda_obj81.jpg Cropping @ [top, bottom, left, right]: [104, 136, 31, 159]
im = Image({'N_X':64, 'N_Y':128, 'seed':None, 'do_mask':False, 'N_image':10})
im.pe.datapath = 'database/'
help(im.make_imagelist)
# extract one image list from a database
imagelist = im.make_imagelist('serre07_targets')
print('Number of images:', len(imagelist))
print('First image:', imagelist[0])
Help on method make_imagelist in module SLIP.SLIP: make_imagelist(name_database, verbose=False) method of SLIP.SLIP.Image instance Makes a list of images with no repetition. Takes as an input the name of a database (the name of a folder in the ``datapath``), returns a list of the filenames along with the crop area. Number of images: 10 First image: ['H_N104093.jpg', [60, 124, 110, 238]]
help(im.get_imagelist)
im.pe.figpath, im.pe.matpath = '/tmp/fig', '/tmp/mat'
# store one image list from a database
imagelist = im.get_imagelist('classifier', 'serre07_targets')
!ls -l /tmp/mat
print('Number of images:', len(imagelist))
print('First image:', imagelist[0])
Help on method get_imagelist in module SLIP.SLIP: get_imagelist(exp, name_database='natural') method of SLIP.SLIP.Image instance returns an imagelist from a pickled database. If the stored imagelist does not exist, creates it. The ``exp`` string allows to tag the list for a particular experiment. total 8 -rw-r--r-- 1 laurentperrinet wheel 333 Sep 8 16:50 classifier_serre07_targets_images.pickle Number of images: 10 First image: ['M_N314057.jpg', [91, 155, 59, 187]]
im = Image({'N_X':128, 'N_Y':128, 'seed':None, 'do_mask':False, 'N_image':10})
im.pe.figpath, im.pe.matpath = '/tmp/fig', '/tmp/mat'
# now we can access again this stored list
!ls -l /tmp/mat
imagelist = im.get_imagelist('classifier', 'serre07_targets')
print('Number of images:', len(imagelist))
print('First image:', imagelist[0])
total 8 -rw-r--r-- 1 laurentperrinet wheel 333 Sep 8 16:50 classifier_serre07_targets_images.pickle Number of images: 10 First image: ['M_N314057.jpg', [91, 155, 59, 187]]
defining a reference test image; check the axis labels for a (x,y) translation
im = Image({'N_X':128, 'N_Y':256})
image = np.zeros((im.pe.N_X, im.pe.N_Y))
image[im.pe.N_X//2:im.pe.N_X//2+im.pe.N_X//4, im.pe.N_X//2:im.pe.N_X//2+im.pe.N_X//4] = 1 # white square on the right
image[im.pe.N_X//2:im.pe.N_X//2+im.pe.N_X//4, im.pe.N_X//4:im.pe.N_X//2] = -1 # black square on its left
_ = im.imshow(image, axis=True)
translating the image by an integer by rolling indices
print(im.pe.N_X//8., im.pe.N_Y//4.)
_ = im.imshow(np.roll(np.roll(image, np.int(im.pe.N_X//8.), axis=0), np.int(im.pe.N_X//4.), axis=1))
16.0 64.0
<ipython-input-32-f4f3cc419ed4>:2: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. Use `int` by itself, which is identical in behavior, to silence this warning. If you specifically wanted the numpy scalar type, use `np.int_` here. _ = im.imshow(np.roll(np.roll(image, np.int(im.pe.N_X//8.), axis=0), np.int(im.pe.N_X//4.), axis=1))
remember axis conventions are: x going down, y going right with the origin on top
translating the image down
_ = im.imshow(im.translate(image, [im.pe.N_X//8., 0.]))
translating the image right
_ = im.imshow(im.translate(image, [0., im.pe.N_Y//4.]))
translating the image on both axis
_ = im.imshow(im.translate(image, [im.pe.N_X//8., im.pe.N_Y//4.]))
translating the image over the torus
_ = im.imshow(im.translate(image, [im.pe.N_X//2., im.pe.N_Y//4.]))
null translation gives the same image
_ = im.imshow(image - im.translate(image, [0., 0.]), norm=False)
the lg.translate function is invertible
_ = im.imshow(image - im.translate(im.translate(image, [1.64, -2.233]), [-1.64, 2.233]), norm=False)
also true for bigger translations (we separate integer part from fractional part in the translation)
_ = im.imshow(image - im.translate(im.translate(image, [182.64, -286.233]), [-182.64, 286.233], preshift=True), norm=False)
but not always true when we don't separate
_ = im.imshow(image - im.translate(im.translate(image, [182.64, -286.233]), [-182.64, 286.233], preshift=False), norm=False)
the lg.translate function is periodic
_ = im.imshow(image - im.translate(image, [-45*im.pe.N_X, 5*im.pe.N_Y]), norm=False)
lg.translate function is associative
_ = im.imshow(im.translate(image, [1., .0]) - im.translate(im.translate(image, [.5, .0]), [.5, .0]), norm=False)
_ = im.imshow(im.translate(image, [2., .0]) - im.translate(im.translate(image, [1.5, -1.0]), [.5, 1.0]), norm=False)
Check out the discussion @ https://laurentperrinet.github.io/sciblog/posts/2017-09-20-the-fastest-2d-convolution-in-the-world.html
Here, we test the whitening on different images.
axs = []
im = Image('default_param.py')
im.pe.datapath = 'database/'
for name_database in ['serre07_targets', 'serre07_distractors']:
for _ in range(4):
fig = plt.figure(figsize=(14, 7))
image, filename, croparea = im.patch(name_database, do_whitening=False)
ax = fig.add_subplot(1, 2, 1)
fig , ax = im.imshow(image, fig=fig, ax=ax)
ax = fig.add_subplot(1, 2, 2)
image, filename, croparea = im.patch(name_database, filename=filename, croparea=croparea, do_whitening=True)
fig , ax = im.imshow(image, fig=fig, ax=ax)
plt.show()
Using image F_ani22.jpg
Using image B_N815065.jpg
Using image H_N130002.jpg
Using image H_N408065.jpg
Using image Hda_obj93.jpg
Using image Bdn_for23.jpg
Using image Fda_art1015.jpg
Using image Bda_room141.jpg
%load_ext watermark
%watermark -i -h -m -v -p numpy,matplotlib,scipy,imageio,SLIP -r -g -b
The watermark extension is already loaded. To reload it, use: %reload_ext watermark 2020-09-08T16:55:13+02:00 CPython 3.8.5 IPython 7.16.1 numpy 1.20.0.dev0+7d04e22 matplotlib 3.2.2 scipy 1.5.2 imageio 2.9.0 SLIP 20191113 compiler : Clang 11.0.3 (clang-1103.0.32.62) system : Darwin release : 19.6.0 machine : x86_64 processor : i386 CPU cores : 36 interpreter: 64bit host name : fortytwo Git hash : 2451fce2503e4e422db56dee38d5680ada3ac7a2 Git repo : https://github.com/bicv/SLIP Git branch : master