Skip to content

Commit

Permalink
'updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrss committed Feb 5, 2017
1 parent 83eef78 commit a43f7c1
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 7,976 deletions.
23 changes: 17 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

"""
To build .tar.gz:
1. Setup directory structure
Expand Down Expand Up @@ -43,15 +45,23 @@
with open('AUTHORS.txt') as f:
author_file = f.read()

required_packages = ['numpy>=1.12.0', 'scipy>=0.18.1', 'scikit-learn>=0.18.1', 'scikit-image>=0.12.3',
'numexpr>=2.6.2', 'tables>=3.3', 'pandas>=0.19.2', 'matplotlib>=1.5.1', 'psutil>=4.3.1',
'joblib>=0.10.3', 'BeautifulSoup4>=4.5.1', 'PyYAML>=3.12', 'colorama>=0.3.7',
'cython>=0.25.2', 'bottleneck>=1.2.0', 'xmltodict', 'retrying',
'opencv-python>=3.1.0', 'PySAL>=1.11.2', 'six>=1.10.0', 'pyFFTW>=0.10.4']
required_packages = ['matplotlib>=1.5.1', 'psutil>=4.3.1',
'joblib>=0.10.3', 'BeautifulSoup4>=4.5.1',
'PyYAML>=3.12', 'colorama>=0.3.7',
'xmltodict', 'retrying',
'PySAL>=1.11.2', 'six>=1.10.0']

if platform.system() == 'Darwin':

for pkg in ['Rtree>=0.8.2', 'gdal>=2.1']:
for pkg in ['numpy>=1.12.0', 'scipy>=0.18.1',
'scikit-image>=0.12.3',
'Rtree>=0.8.2', 'gdal>=2.1',
'numexpr>=2.6.2', 'tables>=3.3',
'bottleneck>=1.2.0', 'statsmodels>=0.8.0',
'opencv-python>=3.1.0', 'cython>=0.25.2',
'scikit-learn>=0.18.1', 'pandas>=0.19.2',
'pyFFTW>=0.10.4']:

required_packages.append(pkg)


Expand Down Expand Up @@ -98,6 +108,7 @@ def setup_package():
zip_safe=False,
download_url=git_url,
install_requires=required_packages,
include_package_data=True,
entry_points=get_console_dict())

setup(**metadata)
Expand Down
68 changes: 30 additions & 38 deletions spfeas/notebooks/INSTALLATION.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## <span style=\"color:#0B3B2E;float:right;font-family:Calibri\">Jordan Graesser</span>\n",
"\n",
Expand All @@ -12,7 +15,10 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## <span style=\"color:blue\">Python</span>\n",
"---\n",
Expand All @@ -34,7 +40,10 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## <span style=\"color:blue\">Installing SpFeas on OSX</span>\n",
"---\n",
Expand All @@ -60,7 +69,10 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"## <span style=\"color:blue\">Installing SpFeas on Windows</span>\n",
"---\n",
Expand All @@ -75,44 +87,24 @@
"### <span style=\"color:green\">Installing SpFeas from the Windows Command Prompt</span>\n",
"> The command prompt can be found under the Start menu. Open it by typing 'cmd' in the **search box**. \n",
"\n",
"1. Download the following wheel files from [Gohlke's site](http://www.lfd.uci.edu/~gohlke/pythonlibs/) and save them to C:\\Downloads.\n",
"1. Download **SpFeas-0.1.0-MpGlue-0.1.0-cp27-cp27m-win_amd64.zip** from the [SpFeas Releases](https://github.com/jgrss/spfeas/releases) page and save in **\\Downloads**.\n",
"\n",
" > numpy‑1.12.0rc2+mkl‑cp27‑cp27m‑win32.whl or numpy‑1.12.0rc2+mkl‑cp27‑cp27m‑win_amd64.whl \n",
" \n",
" > Bottleneck-1.2.0-cp27-cp27m-win32.whl or Bottleneck‑1.2.0‑cp27‑cp27m‑win_amd64.whl\n",
" \n",
" > numexpr-2.6.1-cp27-cp27m-win32.whl or numexpr‑2.6.1‑cp27‑cp27m‑win_amd64.whl\n",
" \n",
" > scikit_image-0.12.3-cp27-cp27m-win32.whl or scikit_image‑0.12.3‑cp27‑cp27m‑win_amd64.whl\n",
" \n",
" > scipy-0.18.1-cp27-cp27m-win32.whl or scipy‑0.18.1‑cp27‑cp27m‑win_amd64.whl\n",
" \n",
" > tables-3.3.0-cp27-cp27m-win32.whl or tables‑3.3.0‑cp27‑cp27m‑win_amd64.whl \n",
" \n",
" > statsmodels-0.8.0rc1-cp27-cp27m-win32.whl or statsmodels‑0.8.0rc1‑cp27‑cp27m‑win_amd64.whl\n",
" \n",
" > GDAL‑2.1.2‑cp27‑cp27m‑win32.whl or GDAL‑2.1.2‑cp27‑cp27m‑win_amd64.whl\n",
" \n",
"2. Either download [git for Windows](https://www.atlassian.com/git/tutorials/install-git/mac-os-x) **OR** download the [MpGlue](https://github.com/jgrss/mpglue/releases) and [SpFeas](https://github.com/jgrss/spfeas/releases) tarballs. \n",
" * If you choose to download and configure **git**, then you DO NOT need to download the MpGlue and SpFeas tarballs.\n",
" * Without **git**, you need to have the MpGlue and SpFeas tarballs downloaded for the installer to find them.\n",
" * Save the SpFeas and MpGlue tarballs to C:\\Downloads.\n",
"2. Unzip **\\Downloads\\SpFeas-0.1.0-MpGlue-0.1.0-cp27-cp27m-win_amd64.zip**\n",
"\n",
"3. Open a command prompt window and move to the **C:\\Downloads\\SpFeas-0.1.0-MpGlue-0.1.0-cp27-cp27m-win_amd64** directory by typing or copying the command below into the window (hit **return** to execute).\n",
" > `cd \\Downloads\\SpFeas-0.1.0-MpGlue-0.1.0-cp27-cp27m-win_amd64`\n",
" \n",
"3. Download [the INSTALL_Windows.sh](https://github.com/jgrss/spfeas/blob/master/spfeas/files/INSTALL_Windows.cmd). \n",
" * To save, click **Raw**, then **File>Save Page As** and choose _All Files_.\n",
" * Save to the **C:\\Downloads** folder on your local machine.\n",
"4. Open a command prompt window and move to the **C:\\Downloads** directory by typing or copying the command below into the window (hit **return** to execute).\n",
" > `cd C:\\Downloads`\n",
"5. Run the INSTALL_Windows.cmd installer by typing or copying the command below into the terminal window (hit **return** to execute).\n",
" > `INSTALL_Windows.cmd`\n",
"6. Command line prompts\n",
" * When prompted, hit **enter**, type **y**, or type your **computer password** or **GitHub username and password** to continue the installation process.\n",
" * Note that your password will not be shown on the screen when you type."
"4. Run the INSTALL_Windows.cmd installer by typing or copying the command below into the terminal window (hit **return** to execute).\n",
" > `INSTALL_Windows_x64.cmd`\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"---\n",
"### <span style=\"color:blue\">The installation is complete when the screen has stopped printing and it says 'The installation has finished!'</span>\n",
Expand All @@ -129,7 +121,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2.0
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand All @@ -141,4 +133,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
48 changes: 25 additions & 23 deletions spfeas/spfeas.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def set_defaults(self, **kwargs):

# Set the features dictionary.
self.features_dict = dict(mean=2, pantex=1, ctr=1,
lsr=3, hough=4, hog=7,
lsr=3, grad=2, hough=4, hog=7,
lbp=62, lbpm=7, gabor=2*8,
surf=4, seg=1, fourier=2,
sfs=6, evi2=2, ndvi=2,
Expand All @@ -42,27 +42,28 @@ def set_defaults(self, **kwargs):
sfsorf=6)

# Set the output bands based on the trigger.
self.out_bands_dict = dict(ctr=len(self.scales) * self.features_dict['ctr'],
dmp=len(self.scales) * self.features_dict['dmp'],
evi2=len(self.scales) * self.features_dict['evi2'],
fourier=len(self.scales) * self.features_dict['fourier'],
gabor=len(self.scales) * self.features_dict['gabor'],
hog=len(self.scales) * self.features_dict['hog'],
hough=len(self.scales) * self.features_dict['hough'],
lac=len(self.scales) * self.features_dict['lac'],
lbp=len(self.scales) * self.features_dict['lbp'],
lbpm=len(self.scales) * self.features_dict['lbpm'],
lsr=len(self.scales) * self.features_dict['lsr'],
mean=len(self.scales) * self.features_dict['mean'],
ndvi=len(self.scales) * self.features_dict['ndvi'],
orb=len(self.scales) * self.features_dict['orb'],
pantex=len(self.scales) * self.features_dict['pantex'],
saliency=len(self.scales) * self.features_dict['saliency'],
seg=len(self.scales) * self.features_dict['seg'],
sfs=len(self.scales) * self.features_dict['sfs'],
sfsorf=len(self.scales) * self.features_dict['sfsorf'],
surf=len(self.scales) * self.features_dict['surf'],
xy=len(self.scales) * self.features_dict['xy'])
self.out_bands_dict = dict(ctr=len(self.scales)*self.features_dict['ctr'],
dmp=len(self.scales)*self.features_dict['dmp'],
evi2=len(self.scales)*self.features_dict['evi2'],
fourier=len(self.scales)*self.features_dict['fourier'],
gabor=len(self.scales)*self.features_dict['gabor'],
grad=len(self.scales)*self.features_dict['grad'],
hog=len(self.scales)*self.features_dict['hog'],
hough=len(self.scales)*self.features_dict['hough'],
lac=len(self.scales)*self.features_dict['lac'],
lbp=len(self.scales)*self.features_dict['lbp'],
lbpm=len(self.scales)*self.features_dict['lbpm'],
lsr=len(self.scales)*self.features_dict['lsr'],
mean=len(self.scales)*self.features_dict['mean'],
ndvi=len(self.scales)*self.features_dict['ndvi'],
orb=len(self.scales)*self.features_dict['orb'],
pantex=len(self.scales)*self.features_dict['pantex'],
saliency=len(self.scales)*self.features_dict['saliency'],
seg=len(self.scales)*self.features_dict['seg'],
sfs=len(self.scales)*self.features_dict['sfs'],
sfsorf=len(self.scales)*self.features_dict['sfsorf'],
surf=len(self.scales)*self.features_dict['surf'],
xy=len(self.scales)*self.features_dict['xy'])

# Update the feature dictionary for feature neighbors.
if self.neighbors:
Expand Down Expand Up @@ -148,6 +149,7 @@ def _options():
Fore.GREEN + Style.BRIGHT + 'evi2' + Style.RESET_ALL + ' -- EVI2 mean (2 x n scales)',
Fore.GREEN + Style.BRIGHT + 'fourier' + Style.RESET_ALL + ' -- Fourier transform (2 x n scales)',
Fore.GREEN + Style.BRIGHT + 'gabor' + Style.RESET_ALL + ' -- Gabor filter bank (n scales x 2 x kernels(Default=24))',
Fore.GREEN + Style.BRIGHT + 'grad' + Style.RESET_ALL + ' -- Edge gradient magnitude (2 x n scales)',
Fore.GREEN + Style.BRIGHT + 'hog' + Style.RESET_ALL + ' -- Histogram of Oriented Gradients (7 (max,m1,m2,m3,m4,skew,kurtosis) x n scales)',
Fore.RED + Style.BRIGHT + 'hough' + Style.RESET_ALL + ' -- Local line statistics from Probabilistic Hough Transform (4 x n scales)' + Fore.RED + ' **Currently out of order**',
Fore.GREEN + Style.BRIGHT + 'lac' + Style.RESET_ALL + ' -- Lacunarity (n scales)',
Expand Down Expand Up @@ -189,7 +191,7 @@ def main():
parser.add_argument('--block', dest='block', help='The block size', default=2, type=int)
parser.add_argument('--scales', dest='scales', help='The scales', default=[8], type=int, nargs='+')
parser.add_argument('-tr', '--triggers', dest='triggers', help='The feature triggers', default=['mean'],
nargs='+', choices=['dmp', 'evi2', 'fourier', 'gabor', 'hog', 'lac',
nargs='+', choices=['dmp', 'evi2', 'fourier', 'gabor', 'grad', 'hog', 'lac',
'lbp', 'lbpm', 'lsr', 'mean', 'ndvi',
'pantex', 'saliency', 'sfs'])
parser.add_argument('-lth', '--hline-threshold', dest='hline_threshold', help='The Hough line threshold',
Expand Down
38 changes: 22 additions & 16 deletions spfeas/spfunctions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .sphelpers import lsr

from skimage.exposure import rescale_intensity

try:
from skimage.feature import hog as HOG
from skimage.feature import local_binary_pattern as LBP
Expand Down Expand Up @@ -55,6 +57,26 @@ def get_kernels():
[roberts_filter_y_3, roberts_filter_x_3], [roberts_filter_y_4, roberts_filter_x_4]]


def get_mag_avg(img):

img = np.sqrt(img)

kernels = get_kernels()

mag = np.zeros(img.shape, dtype='float32')

for kernel_filter in kernels:

gx = cv2.filter2D(np.float32(img), cv2.CV_32F, kernel_filter[1], borderType=cv2.BORDER_CONSTANT)
gy = cv2.filter2D(np.float32(img), cv2.CV_32F, kernel_filter[0], borderType=cv2.BORDER_CONSTANT)

mag += cv2.magnitude(gx, gy)

mag /= len(kernels)

return np.uint8(rescale_intensity(mag, out_range=(0, 255)))


def get_mag_ang(img):

"""
Expand All @@ -69,27 +91,11 @@ def get_mag_ang(img):

img = np.sqrt(img)

# kernels = get_kernels()
#
# mag = np.zeros(img.shape, dtype='float32')
# ang = np.zeros(img.shape, dtype='float32')
#
# for kernel_filter in kernels:
#
# gx = cv2.filter2D(np.float32(img), cv2.CV_32F, kernel_filter[1], borderType=cv2.BORDER_CONSTANT)
# gy = cv2.filter2D(np.float32(img), cv2.CV_32F, kernel_filter[0], borderType=cv2.BORDER_CONSTANT)

gx = cv2.Sobel(np.float32(img), cv2.CV_32F, 1, 0)
gy = cv2.Sobel(np.float32(img), cv2.CV_32F, 0, 1)

mag, ang = cv2.cartToPolar(gx, gy)

# mag += mag_
# ang += ang_

# mag /= len(kernels)
# ang /= len(kernels)

return mag, ang, gx, gy


Expand Down
Loading

0 comments on commit a43f7c1

Please sign in to comment.