Skip to content
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

Fit output in warp function #2740

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wkentaro
Copy link

@wkentaro wkentaro commented Jul 31, 2017

Because I need to fit the output with using the warp function.

@codecov-io
Copy link

codecov-io commented Jul 31, 2017

Codecov Report

Merging #2740 into master will increase coverage by <.01%.
The diff coverage is 96.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2740      +/-   ##
==========================================
+ Coverage   86.01%   86.02%   +<.01%     
==========================================
  Files         332      332              
  Lines       26627    26643      +16     
==========================================
+ Hits        22904    22919      +15     
- Misses       3723     3724       +1
Impacted Files Coverage Δ
skimage/transform/tests/test_warps.py 100% <100%> (ø) ⬆️
skimage/transform/_warps.py 98.95% <94.73%> (-0.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf8d020...23b6481. Read the comment docs.

Copy link
Contributor

@kne42 kne42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although everything appears to be in order with regards to documentation and PEP8 conventions, it would be helpful if you filled out the template provided in the future.

As with your requested changes, the resizing operation that you added only applies to 2-D images while its parent function can take in 2- or 3-D images. You should also add a test in skimage/transform/tests/test_warps.py for this enhancement, accounting for both 2-D and 3-D images.

@@ -778,6 +760,32 @@ def warp(image, inverse_map, map_args={}, output_shape=None, order=1,

if matrix is not None:
matrix = matrix.astype(np.double)

if resize:
rows, cols = input_shape[:2]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resizing operation appears to only apply to 2-D images whereas the warp function accepts both 2-D and 3-D images. Passing in a 3-D image with the argument resize=True would likely result in an output with the 3rd axis not resized properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct; our previous code was limited this way, and can (should) be extended.

Copy link
Author

@wkentaro wkentaro Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what is 3-D images. It's something like arrays which have shape (512, 512, 512)? If so, how can I detect the input image is 3-D or multichannel? RGB image is (512, 512, 3) but it's not 3-D image, right?

Copy link
Member

@stefanv stefanv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a useful refactor, thanks!

@@ -665,6 +643,10 @@ def warp(image, inverse_map, map_args={}, output_shape=None, order=1,
preserve_range : bool, optional
Whether to keep the original range of values. Otherwise, the input
image is converted according to the conventions of `img_as_float`.
resize : bool, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if resize (the keyword we chose before) is the correct one: it does not include some notion of the translation needed to make the transform fit. Maybe fit_output or extend_to_fit?

@@ -665,6 +643,10 @@ def warp(image, inverse_map, map_args={}, output_shape=None, order=1,
preserve_range : bool, optional
Whether to keep the original range of values. Otherwise, the input
image is converted according to the conventions of `img_as_float`.
resize : bool, optional
Determine whether the shape of the output image will be automatically
calculated, so the complete rotated image exactly fits. Default is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warp does much more than rotation.

@@ -778,6 +760,32 @@ def warp(image, inverse_map, map_args={}, output_shape=None, order=1,

if matrix is not None:
matrix = matrix.astype(np.double)

if resize:
rows, cols = input_shape[:2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct; our previous code was limited this way, and can (should) be extended.

out_cols = maxc - minc + 1
output_shape = np.ceil((out_rows, out_cols))

# fit output image in new shape
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for the new API.

@pep8speaks
Copy link

pep8speaks commented Aug 2, 2017

Hello @wkentaro! Thanks for updating the PR.

Line 125:34: E241 multiple spaces after ','
Line 126:22: E241 multiple spaces after ','
Line 136:34: E241 multiple spaces after ','
Line 137:22: E241 multiple spaces after ','
Line 137:39: E241 multiple spaces after ','

Comment last updated on November 05, 2017 at 09:36 Hours UTC

@stefanv
Copy link
Member

stefanv commented Aug 2, 2017

Take a look at the inverse_map parameter to see the types of images that can be transformed (gray-scale, color, N-dimensional).

You have to handle the following cases:

  • inverse_map is a callable and input is gray-scale. Use currently implemented method.
  • inverse_map is a callable and input is color. Use currently implemented method, but remember to add back third dimension.
  • inverse_map is a set of array coordinates of shape (D, coord_0, coord_1, ..., coord_{D-1}). In this case, take the coordinates, slice off the first dimension, and take the maximum over the coords.

@wkentaro
Copy link
Author

wkentaro commented Aug 6, 2017

I'm not sure how to handle the third case, do you have some suggestions?

x = np.zeros((5, 5), dtype=np.double)
x[1, 1] = 1
theta = -np.pi / 4
M = np.array([[np.cos(theta), - np.sin(theta), 0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sake of uniformity and clarity, please change this to

[[np.cos(theta), - np.sin(theta), 0],
 [np.sin(theta),   np.cos(theta), 4],
 [0,               0,             1]]

as it is in your second test case.

@wkentaro wkentaro changed the title Add resize param to warp function Fit output in warp function Aug 7, 2017
@kevinzakka
Copy link

What's the status on this PR?

@wkentaro
Copy link
Author

I have resolved the conflict. Now I think it is ready to be reviewed. Could someone please review this?

@nsarang
Copy link

nsarang commented May 5, 2020

Is there a problem merging this PR?

Base automatically changed from master to main February 18, 2021 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants