[Neuroimaging] [PySurfer] Brain's save_image method produces images with only background color

John Pellman pellman.john at gmail.com
Thu Sep 15 12:44:49 EDT 2016


I've had at this a little bit more and my current suspicion is that this
behavior is the result of an interaction between our remote desktop service
(x2go) and Mayavi.

I created a an identical Miniconda environment for Pysurfer on both our
server and my laptop and ran the following code to test this theory:

# The Basic Visualization demo from the Pysurfer gallery.
> from surfer import Brain
>
> print(__doc__)
>
> """
> Define the three important variables.
> Note that these are the first three positional arguments
> in tksurfer (and pysurfer for that matter).
> """
> subject_id = 'fsaverage'
> hemi = 'lh'
> surface = 'inflated'
>
> """
> Call the Brain object constructor with these
> parameters to initialize the visualization session.
> """
> brain = Brain(subject_id, hemi, surface)
>
> # Save an image out to /tmp
> print 'Saving out an image to /tmp using Brain.save_image.'
> brain.save_image('/tmp/brain.png')
>
> # Looking at just the screenshot method of pysurfer's Brain object.
> # This is called by save_image and is fed into scipy.misc.imsave.
> # If the boolean expression evaluated here is true, then only a black
> # background is being fed into scipy's misc.imsave method for evaluation.
> x = brain.screenshot()
> print 'Test pysurfer\'s Brain.screenshot.'
> if sum(x.flatten()==0)!=len(x.flatten()):
>     print 'Pass'
> else:
>     print 'Fail'
>
> # Looking at the Mayavi mlab.screenshot method.
> # This is called by screenshot_single, which is called by Brain's
> screenshot.
> # If the boolean expression evaluated here is true, then only a black
> # background is being fed into Brain.screenshot()
> from mayavi import mlab
> x = mlab.screenshot(brain.brain_matrix[0,0]._f, 'rgb', False)
> print 'Test mayavi\'s mlab.screenshot'
> if sum(x.flatten()==0)!=len(x.flatten()):
>     print 'Pass'
> else:
>     print 'Fail'
>

On the server through an x2go session both Brain.screenshot and
mlab.screenshot failed to produce a non-blank image, while on my laptop's
local environment both of these methods did produce the desired output
(i.e., there were some nonzero outputs).

Since this doesn't seem to be an error with pysurfer in particular, I'm
going to proceed to see if anyone using Mayavi with x2go or nx has
encountered similar issues by querying their forums / issue pages.  I just
wanted to leave this here if someone else encounters the same issue in the
future.

--John

On Tue, Sep 13, 2016 at 1:24 PM, John Pellman <pellman.john at gmail.com>
wrote:

> It looks like it might be related to the following issue described at
> StackOverflow:
>
> http://stackoverflow.com/questions/16543634/mayavi-mlab-
> savefig-gives-an-empty-image
>
> On Mon, Sep 12, 2016 at 2:00 PM, John Pellman <pellman.john at gmail.com>
> wrote:
>
>> Hi all,
>>
>> I'm encountering a peculiar Pysurfer error on our server and I was
>> wondering if anyone has encountered anything similar or might have some
>> insight into how I can tackle it.  Basically, when our researchers try to
>> save a png image using Brain.save_image() or Brain.save_imageset() the
>> images produced only contain the background color (as you may have inferred
>> from the subject line).  I've traced this back to Scipy method
>> (scipy.misc.imsave), but it looks like this would only output an empty png
>> if the image passed in were completely zeroed out.  Our setup uses the
>> following versions of pysurfer/its dependencies:
>>
>> Numpy: 1.10.0.dev0+1fe98ff
>> Scipy: 0.17.0.dev0+f2f6e48
>> Ipython: 3.1.0
>> nibabel: 2.0.0
>> Mayavi: 4.4.2
>> matplotlib: 1.4.3
>> PIL: 1.1.7
>> Pysurfer: 0.5
>>
>> This setup is running within a Miniconda environment using Python
>> 2.7.11.  I'm uncertain if this is related, but running the example code
>> here <http://pysurfer.github.io/examples/plot_basics.html> produces the
>> following warning:
>>
>> *(ipython:20765): Gdk-WARNING **:
>> /build/buildd/gtk+2.0-2.24.27/gdk/x11/gdkdrawable-x11.c:952 drawable is not
>> a pixmap or window*
>>
>> Any insight would be greatly appreciated.
>>
>> Best,
>> John Pellman
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160915/90813552/attachment.html>


More information about the Neuroimaging mailing list