Skip to content

generalize dimensionality of rescale - #2587

Closed
noahstier wants to merge 1 commit into
scikit-image:masterfrom
noahstier:rescale-gt-2-dims
Closed

noahstier wants to merge 1 commit into
scikit-image:masterfrom
noahstier:rescale-gt-2-dims

Conversation

@noahstier

@noahstier noahstier commented Mar 27, 2017 •

Copy link
Copy Markdown
Contributor

Description

Handle n-dimensional arrays in transform.rescale
Previously it only handled 1- and 2-dimensional arrays

Checklist

References

implements enhancement #2568

@pep8speaks

Copy link
Copy Markdown

Hello @noahstier! Thanks for submitting the PR.

Line 11:80: E501 line too long (87 > 79 characters)
Line 27:80: E501 line too long (80 > 79 characters)
Line 575:25: E127 continuation line over-indented for visual indent
Line 594:80: E501 line too long (86 > 79 characters)
Line 760:55: E502 the backslash is redundant between brackets
Line 761:19: E127 continuation line over-indented for visual indent
Line 769:34: E128 continuation line under-indented for visual indent
Line 770:34: E128 continuation line under-indented for visual indent

Line 49:5: E731 do not assign a lambda expression, use a def
Line 267:37: E231 missing whitespace after ','
Line 267:60: E231 missing whitespace after ','
Line 283:29: E127 continuation line over-indented for visual indent
Line 302:28: E201 whitespace after '['
Line 303:28: E201 whitespace after '['
Line 308:28: E201 whitespace after '['
Line 308:32: E203 whitespace before ','
Line 309:28: E201 whitespace after '['
Line 355:1: E303 too many blank lines (3)

@codecov-io

codecov-io commented Mar 27, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #2587 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2587      +/-   ##
==========================================
+ Coverage   90.75%   90.76%   +<.01%     
==========================================
  Files         308      308              
  Lines       21886    21894       +8     
  Branches     1884     1885       +1     
==========================================
+ Hits        19863    19871       +8     
  Misses       1677     1677              
  Partials      346      346
Impacted Files Coverage Δ
skimage/transform/_warps.py 98.26% <100%> (+0.01%) ⬆️
skimage/transform/tests/test_warps.py 99.57% <100%> (+0.01%) ⬆️

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 3419633...d7faf57. Read the comment docs.

new_dims.append(new_dim)

return resize(image, output_shape, order=order, mode=mode, cval=cval,
return resize(image, new_dims, order=order, mode=mode, cval=cval,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

resize doesn't not support arbitrary number of dimension, does it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@soupault Travis seems to think that it does... =P

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indeed.

new_dims = []
for (orig_dim, dim_scale) in zip(orig_dims, scale):
new_dim = np.round(dim_scale * orig_dim)
new_dims.append(new_dim)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, this could be a one-liner:

new_dims = list([np.round(orig_dim * dim_scale)
                 for (orig_dim, dim_scale) in zip(orig_dims, scale)])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't even need the list... ;)

@soupault soupault added this to the 0.14 milestone Mar 27, 2017

@jni jni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, @soupault's style recommendation is good, but it's optional afaic. If anyone wants to merge, go ahead. =) Thanks @noahstier!

@soupault

Copy link
Copy Markdown
Member

I don't like how the multichannel case is handled now. We should probably add multichannel keyword to both resize and rescale before making the functions nD.

@soupault
soupault dismissed their stale review March 29, 2017 10:34

Should be further discussed.

@noahstier

Copy link
Copy Markdown
Contributor Author

It looks like resize supports 2D images with an arbitrary number of channels (in other words, 2 or 3 dimensional arrays). Should both rescale and resize be modified to take arrays of arbitrary dimension?

@soupault is the idea behind a multichannel keyword that you could resize an RGB (NxMx3) image with scale=(2, 2), in other words you don't have to specify 1 as the scale of the last dimension if the last dimension is the number of channels? To me that seems like an unnecessary introduction of a special case, and it would make more sense to resize a 100x100 image with scale=(2, 2), or a 100x100x3 image with scale=(2, 2, 1).

@jni

jni commented Mar 31, 2017

Copy link
Copy Markdown
Member

@noahstier I agree with you that multichannel seems excessive here, even though it is standard in the library. Instead, I would suggest that trailing dimensions, when a tuple argument is given, are considered singletons. @soupault what do you think of that solution? (A slightly safer option would be that at most one dimension is considered a singleton.)

@jni

jni commented Mar 31, 2017

Copy link
Copy Markdown
Member

@noahstier indeed converting both functions to take arbitrary dimensions would be fantastic!

@grlee77

grlee77 commented Mar 31, 2017 •

Copy link
Copy Markdown
Contributor

I had also proposed this long ago in #1522, but it was not reviewed at the time and I neglected to follow up on it recently. I am fine with @noahstier cherry-picking/merging things from that PR as well if there are things there which are helpful.

definitely +1 on getting additional nd support in scikit-image as I think that is one area where it has an advantage over other packages such as opencv.

@soupault

soupault commented Apr 3, 2017

Copy link
Copy Markdown
Member

@jni My opinion is that we should stick to a single design, and the most clear and explicit one is the one with multichannel keyword. I really don't like if img.shape[-1] in [3, 4]: warn('Your image is suspicious') approach.
I've taken a look at #1522, and the solution there looks better to me. @grlee77 thanks for the push. I'll be happy to bring that PR into master if we can reach an agreement with @scikit-image/core .

@jni

jni commented Apr 3, 2017

Copy link
Copy Markdown
Member

@soupault I kind of agree with you with regards to the ambiguity. However, when len(scale) == len(image.shape) - 1, I think it is unambiguous and clear what the user wants. At any rate, I'm not opposed to multichannel=. I just think it's clunky in this case.

@noahstier at any rate, we certainly can't merge this until it does what it intends to do. ;) Would you like to update the PR to rescale nD images correctly?

@noahstier

Copy link
Copy Markdown
Contributor Author

@jni Ok it sounds like the consensus is to use multichannel. Thank you @grlee77, I'll cherry-pick what I need to from your PR

@grlee77

grlee77 commented Apr 12, 2017

Copy link
Copy Markdown
Contributor

I revisited #1522 today to rebase on master after the big pytest merge. This was pretty straightforward, but still took a little while. It made me realize that more work had gone into that PR than I remembered!. I think as @soupault suggested above, that it makes sense to work off of #1522 instead of this one as it is already farther along with tests, deprecation warnings, etc...

@soupault

Copy link
Copy Markdown
Member

I'm closing this PR in advance of #1522. Please, feel free to share your ideas and opinions there. The work of @grlee77 is much more complete and covers severals additional cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⏩ type: Enhancement Improve existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants