Skip to content

Commit

Permalink
refactor(registration): Added rigid registration of multimodal images…
Browse files Browse the repository at this point in the history
… based on mean phase images and HOG features. Also added an examplary notebook
  • Loading branch information
Oli4 committed Nov 12, 2019
1 parent 9d883af commit 7ce9ebd
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
minimum_pre_commit_version: 1.20.0
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: requirements-txt-fixer
- id: fix-encoding-pragma
- id: check-added-large-files
- id: check-docstring-first
- repo: https://github.com/asottile/blacken-docs
rev: v1.3.0
hooks:
- id: blacken-docs
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.4.2
hooks:
- id: python-use-type-annotations
- repo: https://github.com/myint/docformatter
rev: v1.3.1
hooks:
- id: docformatter
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
10 changes: 10 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
========
Examples
========

.. toctree::
:maxdepth: 2

examples/rigid_registration


89 changes: 89 additions & 0 deletions docs/examples/rigid_registration.ipynb

Large diffs are not rendered by default.

Empty file added eyepy/register/draw.py
Empty file.
63 changes: 63 additions & 0 deletions eyepy/register/feature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import numpy as np
from skimage.feature import hog


def hog_extract(
img,
orientations=12,
pixels_per_cell=(5, 5),
cells_per_block=(20, 20),
rotate_hist=False,
sub_sample_factor=2,
):
"""
"""

hog_features = hog(
img,
orientations=orientations,
pixels_per_cell=pixels_per_cell,
cells_per_block=cells_per_block,
multichannel=False,
feature_vector=False,
)

ss_hog_features = hog_features[::sub_sample_factor, ::sub_sample_factor, ...]

if rotate_hist:
ss_hog_features = rotate_hog(ss_hog_features)

# flatten blocks
ss_hog_features = ss_hog_features.reshape(ss_hog_features.shape[:-3] + (-1,))
keys = []
features = []
for key in np.ndindex(ss_hog_features.shape[:-1]):
feature = ss_hog_features[key]
keys.append(key)
features.append(feature)

features = np.array(features)
keys = np.array(keys)

# Rescale features to original image positions
N0, N1 = pixels_per_cell
M0, M1 = cells_per_block
keys[:, 0] = keys[:, 0] * sub_sample_factor * N0 + (N0 * M0 / 2)
keys[:, 1] = keys[:, 1] * sub_sample_factor * N1 + (N1 * M1 / 2)

return keys, features


def rotate_hog(hog_features):
"""
"""
orientations = hog_features.shape[-1]
M = hog_features.shape[-2]
rotated_hog = np.zeros(hog_features.shape[:2] + (orientations, M, M, orientations))
for block in np.ndindex(hog_features.shape[:2]):
for rot in range(orientations):
rotated_hog[block][rot] = np.roll(hog_features[block], rot, axis=-1)

return rotated_hog

0 comments on commit 7ce9ebd

Please sign in to comment.