Error for ImageLayer creation for an image with channels, scale, transform
See original GitHub issue🐛 Bug
After upgrading napari, a traceback is now obtained for an ImageLayer created with a channel dimension, scale
, and translate
.
To Reproduce
Test script:
import napari
import numpy as np
data = np.random.rand(20, 20, 2).astype(np.float32)
image_layer = napari.layers.Image(data, scale=[1.0, 1.0], translate=[3.0, 4.0])
Results in the traceback:
Traceback (most recent call last):
File "/tmp/napari_test.py", line 5, in <module>
image_layer = napari.layers.Image(data, scale=[1.0, 1.0], translate=[3.0, 4.0])
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/layers/image/image.py", line 290, in __init__
self._update_dims()
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/layers/base/base.py", line 544, in _update_dims
self.refresh()
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/layers/base/base.py", line 946, in refresh
self.set_view_slice()
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/layers/base/base.py", line 810, in set_view_slice
self._set_view_slice()
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/layers/image/image.py", line 519, in _set_view_slice
indices = np.array(self._slice_indices)
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/layers/base/base.py", line 612, in _slice_indices
inv_transform = self._data_to_world.inverse
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/layers/base/base.py", line 996, in _data_to_world
return self._transforms[1:3].simplified
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/utils/transforms/transforms.py", line 125, in simplified
return tz.pipe(self[0], *[tf.compose for tf in self[1:]])
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/toolz/functoolz.py", line 627, in pipe
data = func(data)
File "/home/matt/bin/miniconda/envs/napari/lib/python3.9/site-packages/napari/utils/transforms/transforms.py", line 460, in compose
affine_matrix = self.affine_matrix @ transform.affine_matrix
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 3 is different from 4)
Expected behavior
No traceback. Identified in CI: https://github.com/InsightSoftwareConsortium/napari-itk-io/pull/3
Environment
- Please copy and paste the information at napari info option in help menubar here:
napari: 0.4.10
Platform: Linux-5.9.8-050908-generic-x86_64-with-glibc2.31
System: Ubuntu 20.04.2 LTS
Python: 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46) [GCC 9.3.0]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.20.2
SciPy: 1.6.2
Dask: 2021.04.0
VisPy: 0.6.6
OpenGL:
- GL version: 4.6.0 NVIDIA 460.80
- MAX_TEXTURE_SIZE: 32768
Screens:
- screen 1: resolution 3840x2160, scale 1.0
- screen 2: resolution 3840x2160, scale 1.0
Plugins:
- console: 0.0.3
- napari-itk-io: 0.1.1.dev4+g2874092
- svg: 0.1.4
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Color and monochrome adjustments using channels
To create high-quality grayscale images, choose the percentage for each color channel in the Channel Mixer adjustment. To convert a color ...
Read more >Image input layer - MATLAB - MathWorks
An image input layer inputs 2-D images to a network and applies data normalization. For 3-D image input, use image3dInputLayer . Creation. Syntax....
Read more >scikit-image scale does not preserve channels - Stack Overflow
I am trying to scale my colorful image as follow. But the number of output channels are 2 instead of 3. I should...
Read more >Image Visualization - Earth Engine - Google Developers
Visualization images. Use the image.visualize() method to convert an image into an 8-bit RGB image for display or export.
Read more >How to use Free Transform in Photoshop
Learn how to scale, rotate, flip, skew and distort images using the Free Transform command in Photoshop. Now updated for CC 2020!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah I hadn’t read the above correctly — indeed @thewtex for that image you will have to provide
channel_axis=-1
as a kwarg toadd_image
. There is otherwise no way for us to know that the last axis is channels. (yes yes, ITK and typing is so good, we know. 😂)@andy-sweet @jni @sofroniewn thank you! 💯