-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(registration): Added rigid registration of multimodal images…
… based on mean phase images and HOG features. Also added an examplary notebook
- Loading branch information
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
======== | ||
Examples | ||
======== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
examples/rigid_registration | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |