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

JB Poline jbpoline at gmail.com
Fri Sep 16 05:43:00 EDT 2016


That's a cool idea and package - thanks for pointing to this !

On 16 September 2016 at 02:40, Ariel Rokem <arokem at gmail.com> wrote:

>
> On Thu, Sep 15, 2016 at 1:33 PM, Kirstie Whitaker <kw401 at cam.ac.uk> wrote:
>
>> Hi John,
>>
>> I'm travelling at the moment but I've had problems with pysurfer showing
>> beautiful brains on the screen but only saving a black box to file. It
>> happened right after our systems admin updated a few things but I haven't
>> been able to get a clear list from him of what changed except: everything
>> should work.
>>
>> My point with this email is please do share back what you learn.....even
>> if it ends up being not a pysurfer problem. At the moment my workaround is
>> to move everything I do to a different cluster that works!! Non efficient
>> to say the least!
>>
>> Thank you
>> Kirstie
>>
>> Sent from my iPhone, please excuse any typos or excessive brevity
>>
>> On 15 Sep 2016, at 12:44, John Pellman <pellman.john at gmail.com> wrote:
>>
>> 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.
>>
>> A shot in the dark: Could it be something to do with running headless?
> Maybe running this under XVFB (e.g. through xvfbwrapper
> <https://pypi.python.org/pypi/xvfbwrapper>) would help?
>
> Ariel
>
>
>> --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-save
>>> fig-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
>>>>
>>>
>>>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160916/8cde0b88/attachment.html>


More information about the Neuroimaging mailing list