MayaVi2 - save_png magnification issue

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

MayaVi2 - save_png magnification issue

Arnd Baecker
Hi,

when saving a visualization as png and using the magnification
parameter of mlab.savefig, the resulting
image is slightly off-set from the one without magnification,
see the example below.
To see the difference, it is best to use an image viewer
which scales the two images to the same size.

Is this problem just occuring on my system
(I am using vtk: 5.6.1-6ubuntu3, mayavi2: 4.0.0-1ubuntu1)?
Is there maybe a work-around?

(Background: while this would be not a real problem
for the generated image itself, I am using
the 3D to 2D coordinate transformation, as in
http://github.enthought.com/mayavi/mayavi/auto/example_mlab_3D_to_2D.html
to draw additional lines on top of the scene, which
then end up to be slightly, but visibly wrong).

Best, Arnd

##############################################################################
# Example
import numpy as np
from mayavi import mlab

a = np.random.random((4, 4))

f = mlab.figure(size=(512, 512))
f.scene.background = (1,1,1)
f.scene.foreground = (0,0,0)

mlab.surf(a)
#mlab.axes()  # This does not scale properly.
mlab.outline()

mlab.savefig("tst.png")
mlab.savefig("tst_mag.png", magnification=2)

################## EOF
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: MayaVi2 - save_png magnification issue

Gael Varoquaux
Hi Arnd,

Sorry, I have no answer :$. There might be a reason deep in the bowels of
VTK, but I don't know it.

Gael

On Mon, Apr 09, 2012 at 03:42:34PM +0200, Arnd Baecker wrote:
> Hi,

> when saving a visualization as png and using the magnification
> parameter of mlab.savefig, the resulting
> image is slightly off-set from the one without magnification,
> see the example below.
> To see the difference, it is best to use an image viewer
> which scales the two images to the same size.

> Is this problem just occuring on my system
> (I am using vtk: 5.6.1-6ubuntu3, mayavi2: 4.0.0-1ubuntu1)?
> Is there maybe a work-around?

> (Background: while this would be not a real problem
> for the generated image itself, I am using
> the 3D to 2D coordinate transformation, as in
> http://github.enthought.com/mayavi/mayavi/auto/example_mlab_3D_to_2D.html
> to draw additional lines on top of the scene, which
> then end up to be slightly, but visibly wrong).

> Best, Arnd


> # Example
> import numpy as np
> from mayavi import mlab

> a = np.random.random((4, 4))

> f = mlab.figure(size=(512, 512))
> f.scene.background = (1,1,1)
> f.scene.foreground = (0,0,0)

> mlab.surf(a)
> #mlab.axes()  # This does not scale properly.
> mlab.outline()

> mlab.savefig("tst.png")
> mlab.savefig("tst_mag.png", magnification=2)

> ################## EOF
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev

--
    Gael Varoquaux
    Researcher, INRIA Parietal
    Laboratoire de Neuro-Imagerie Assistee par Ordinateur
    NeuroSpin/CEA Saclay , Bat 145, 91191 Gif-sur-Yvette France
    Phone:  ++ 33-1-69-08-79-68
    http://gael-varoquaux.info
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: MayaVi2 - save_png magnification issue

Arnd Baecker
Hi Gael,

On Tue, 10 Apr 2012, Gael Varoquaux wrote:

> Hi Arnd,
>
> Sorry, I have no answer :$. There might be a reason deep in the bowels of
> VTK, but I don't know it.

Thanks for the reply! It seems that you are right: the pure vtk example
below shows the same problem, that in the magnified image  the objects are
slightly larger (beyond the expected magnification factor).
Just to be sure: you are able to reproduce the problem?
If yes, it presumably makes sense that I ask on the vtk mailing list ...

Best, Arnd

############################################################################
#!/usr/bin/env python

import vtk

cone = vtk.vtkConeSource()
cone.SetHeight(3.0)
cone.SetRadius(1.0)
cone.SetResolution(10)

coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())

coneActor = vtk.vtkActor()
coneActor.SetMapper( coneMapper )

ren1= vtk.vtkRenderer()
ren1.AddActor(coneActor)
ren1.SetBackground(0.1, 0.2, 0.4)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(500, 500)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.Initialize()
renWin.Render()

# --- Export with magnification = 1
w2if = vtk.vtkWindowToImageFilter()
w2if.SetMagnification(1)
w2if.SetInput(renWin)
w2if.Update()

exporter = vtk.vtkPNGWriter()
exporter.SetFileName("cone_mag1.png")
exporter.SetInput(w2if.GetOutput())
exporter.Write()

# --- Export with magnification = 2
w2if = vtk.vtkWindowToImageFilter()
w2if.SetMagnification(2)
w2if.SetInput(renWin)
w2if.Update()

exporter = vtk.vtkPNGWriter()
exporter.SetFileName("cone_mag2.png")
exporter.SetInput(w2if.GetOutput())
exporter.Write()

# Note that the cone in  cone_mag2.png
# is slightly larger than in cone_mag1.png.
# (This is best seen with an image viewer which
#  scales images to the same window size)
# Alternatively, just rescale the second image
# to the same size of the non magnified one:
#    convert -resize %50 cone_mag2.png cone_mag2_.png


#iren.Start()

#### EOF


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev