lear-gist-python
lear-gist-python copied to clipboard
A python wrapper for Lear's GIST implementation working with numpy
lear-gist-python
Python library to extract A. Torralba's GIST descriptor.
This is just a wrapper for Lear's GIST implementation written in C. It supports both Python 2 and Python 3 and was tested under Python 2.7.15 and Python 3.6.6 on Linux.
How to build and install
Pre-requirements
Following packages must be installed before building and installing lear-gist-python.
numpy
$ pip install numpy
FFTW
FFTW is required to build lear_gist.
Please download the source, then build and install like following. (Install guide is here. Please refer for defail.)
Make sure --enable-single and --enable-shared options are set to ./configure.
$ ./configure --enable-single --enable-shared
$ make
$ make install
Because:
- lear-gist requires float version FFTW to work with (
--enable-single). - lear-gist-python requires FFTW to be compiled with
-fPICoption (--enable-shared).
Build and install
Download lear_gist
$ ./download-lear.sh
Build and install
$ python setup.py build_ext
$ python setup.py install
If fftw3f is installed in non-standard path (for example, $HOME/local),
use -I and -L options:
$ python setup.py build_ext -I $HOME/local/include -L $HOME/local/lib
Usage
import gist
import numpy as np
img = ... # numpy array containing an image
descriptor = gist.extract(img)
Scene classification sample
This sample uses 8 Scene Categories Dataset.
scikit-learn and scikit-image are required.
$ pip install scikit-learn scikit-image
cd sample
sh download-8scene.sh
# Extract GIST features from images in "spatial_envelope_256x256_static_8outdoorcategories" directory and save them into "features" directory
python feature_extraction.py spatial_envelope_256x256_static_8outdoorcategories features
# Train and test a multi-class linear classifier by features in "features" directory
python scene_classification.py features
API
gist.extract(img, nblocks=4, orientations_per_scale=(8, 8, 4))
img: A numpy array (an instance ofnumpy.ndarray) which contains an image and whose shape is(height, width, 3).nblocks: Use a grid ofnblocks * nblockscells.orientations_per_scale: Uselen(orientations_per_scale)scales and computeorientations_per_scale[i]orientations for i-th scale.
