question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird behaviour of `Volume(img)`

See original GitHub issue

Using Volume to render data from a numpy array seems to mess up the axes order (see screenshot below). At the same time building a vtkImageData manually works fine.

I’m getting this behaviour only after reinstalling my python environment and updating vtkplotter. Unfortunately I can’t find the configuration in which things would work as they did before, so here’s code illustrating the problem:

import vtk
import numpy as np
from vtkplotter import show, embedWindow, Volume

embedWindow('itkwidgets') # backends are: itkwidgets, k3d or False

import skimage.io as io
f = 'embryo.tif' # from the vtkplotter examples
raw = io.imread(f, plugin='simpleitk')

arr = vtk.util.numpy_support.numpy_to_vtk(raw.transpose(2,1,0).ravel(), array_type=vtk.VTK_FLOAT)
img = vtk.vtkImageData()
img.SetDimensions(raw.shape)
img.GetPointData().SetScalars(arr)

# doesn't work
# show(Volume(raw.transpose(2,1,0)))
show(Volume(raw))
# show(Volume(raw)._image)
# show(Volume(raw.transpose(2,1,0))._image)

# works
# show(img)

This is the output: image

Thanks! Cheers, Marvin

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
m-albertcommented, Dec 2, 2019

This works for me as well. Thanks so much for looking into this so quickly and fixing! Cheers, Marvin

1reaction
marcomusycommented, Dec 2, 2019

Actually I said something completely wrong… the trasnpose thing doesn’t fix the spacing order… so in the end I believe the order=‘F’ would simplify the operation, so the above becomes:

from vtkplotter import *
from skimage.io import imread

f = datadir+'embryo.tif'

voriginal = load(f)
printc('voxel size is', voriginal.spacing(), c='cyan')

raw = imread(f)

vraw = Volume(raw, spacing=(104,104,104))
# Need to change axes and mirror
# NOTE: spacing specified above is now inverted: (z,y,x)
vraw.permuteAxes(2,1,0).mirror("y")

# Compare loading the volume directly with the numpy volume:
# they should be the same
show(voriginal, vraw, N=2, axes=1)

I committed the new version… sorry for the confusion and thanks a lot for the help! Let me know if this does the job… M.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Weird behaviour of `Volume(img)` · Issue #78 · marcomusy/vedo ...
Using Volume to render data from a numpy array seems to mess up the axes order (see screenshot below). ... Weird behaviour of...
Read more >
Volume with negative spacing turns in strange behaviour (bug?)
When I try to add volume with negative spacing in X direction to Slicer I get strange behavior. Then I go to the...
Read more >
Strange behaviour on Office 2019 Volume Licensed on a ...
We are experiencing this strange behaviour: opening an Office application (Excel, Word, etc) and closing it, the relative process is released ...
Read more >
Weird behaviour of "Allow Over-Amplification" Switch in Sound ...
Issue: The Over Amplification Key has slightly weird behavior. If the switch is on, and volume is set to > 100%, and the...
Read more >
Weird behaviour when snipping content from the audio track ...
Weird behaviour when snipping content from the audio track ... the remaining parts, the audio volume immediately prior to the snip greatly decreases....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found