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

Automatically add channels axis at back for init_from_channels_at_back #735

Merged
merged 5 commits into from Sep 19, 2016

Conversation

Projects
None yet
4 participants
@grigorisg9gr
Member

grigorisg9gr commented Aug 30, 2016

Small change in init_from_channels_at_back() in Image class.

Currently if less dimensions are provided it does not raise any error or warning, e.g. :

Image.init_from_channels_at_back(np.random.rand(20, 40)).shape

@jabooth jabooth added the in progress label Aug 30, 2016

@patricksnape

This comment has been minimized.

Contributor

patricksnape commented Sep 3, 2016

The way the image constructor works now is that if you provide a 2D (no channels) image, we just put an 'empty' channel at the front and assume you meant a 2D 1-channel image. Perhaps we should just do the same here? If ndims == 2 then add an empty axis to the back - @jabooth @nontas?

@nontas

This comment has been minimized.

Member

nontas commented Sep 7, 2016

I agree with @patricksnape . We should do exactly what the Image constructor does, i.e.

  1. Add an empty "channels" axis in case the provided array has ndim == 2.
  2. Raise a ValueError in case the provided array has ndim < 2.
init_from_channels_at_back match __init__
If 2D exactly, add empty channel at back. If less than 2D, exception. Also update init_from_rolled_channels to use init_from_channels_at_back.
pixels = np.require(np.rollaxis(pixels, -1), dtype=pixels.dtype,
requirements=['C'])
return pixels
return np.require(np.rollaxis(pixels, -1), dtype=pixels.dtype,

This comment has been minimized.

@patricksnape

patricksnape Sep 11, 2016

Contributor

This was required because that check prevented multi-channel 2D+ conversion.

patricksnape added some commits Sep 11, 2016

Handle overrides correctly
Both BooleanImage and MaskedImage needed to correctly
handle the case of channels at the back.

@patricksnape patricksnape reopened this Sep 11, 2016

@patricksnape patricksnape changed the title from Explicitly ask for minimum dimensions for init image from channels. to Automatically add channels axis at back for init_from_channels_at_back Sep 13, 2016

@patricksnape patricksnape reopened this Sep 13, 2016

@patricksnape

This comment has been minimized.

Contributor

patricksnape commented Sep 14, 2016

@jabooth Ignore menpobot - Windows conda-build is having troubles. Review please?

@patricksnape patricksnape merged commit 1db4813 into menpo:master Sep 19, 2016

1 of 2 checks passed

macOS MenpoBot Jenkins build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@patricksnape patricksnape deleted the grigorisg9gr:init_image_channel_dims branch Sep 19, 2016

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