New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge prep_cmr with image_transform plus tests #123
Changes from 6 commits
c9377e4
f1b813b
84f1967
0915a60
c996a5c
3dfb871
8092475
22fb16a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import numpy as np | ||
import pytest | ||
from numpy import testing | ||
from scipy.io import loadmat | ||
|
||
from kale.prepdata.image_transform import mask_img_stack, reg_img_stack, rescale_img_stack | ||
|
||
gait = loadmat("tests/test_data/gait_gallery_data.mat") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Smart to use gait to test image stacks. Good reuse. |
||
images = gait["fea3D"][..., :10] | ||
SCALES = [4, 8] | ||
|
||
|
||
def test_reg(): | ||
n_samples = images.shape[-1] | ||
coords = np.ones((n_samples, 4)) | ||
coords[:, 2:] += 20 | ||
coords[1:, :] += np.random.random(size=(n_samples - 1, 4)) | ||
with pytest.raises(Exception): | ||
reg_img_stack(images, coords[1:, :]) | ||
images_reg, max_dist = reg_img_stack(images, coords) | ||
testing.assert_allclose(images_reg, images) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not get fully your logic here and can only guess. How did you make the registered images to be close to the original? I though you randomly perturbed the coordinates of the n-1 (9) images. After registration, they are close. Is it because the random noise is of small value compared to the coords? You can explain to me with a voice message in WeChat or Skype. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the poor readability. Yes, the random noise to source coordinates are in (0, 1), which are small values compared to the image size. So the images after registration should be close to the original ones. The values in list There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification. That's helpful! Ready to merge. |
||
testing.assert_equal(max_dist.shape, (n_samples,)) | ||
|
||
|
||
@pytest.mark.parametrize("scale", SCALES) | ||
def test_rescale(scale): | ||
img_rescaled = rescale_img_stack(images, scale) | ||
testing.assert_equal(img_rescaled.shape[0], round(images.shape[0] / scale)) | ||
testing.assert_equal(img_rescaled.shape[1], round(images.shape[1] / scale)) | ||
testing.assert_equal(img_rescaled.shape[-2:], images.shape[-2:]) | ||
|
||
|
||
def test_masking(): | ||
mask = np.random.randint(0, 2, size=(images.shape[0], images.shape[1])) | ||
idx_zeros = np.where(mask == 0) | ||
idx_ones = np.where(mask == 1) | ||
img_masked = mask_img_stack(images, mask) | ||
n_phases, n_samples = images.shape[-2:] | ||
for i in range(n_phases): | ||
for j in range(n_phases): | ||
img = img_masked[..., j, i] | ||
testing.assert_equal(np.sum(img[idx_zeros]), 0) | ||
testing.assert_equal(img_masked[idx_ones], images[idx_ones]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still useful? Otherwise, remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove it