Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to save image with transparent background? #41

Open
JohannesWiesner opened this issue Sep 5, 2024 · 6 comments
Open

Possible to save image with transparent background? #41

JohannesWiesner opened this issue Sep 5, 2024 · 6 comments

Comments

@JohannesWiesner
Copy link

Feature Request

Hi! Thanks for much for this wonderful visualization toolbox! I wonder if it's also possible to save my image with a transparent background?

Right now I am using python scripting and my script ends with gl.savebmp('filename.png'). This will generate .png file that contains my brain image with a white square background. Would be nice to set the white background to transparent :)

Version

Surf Ice 1.0.20211006+ 64-bit x86-64GTK2 Linux LLVM StaticPythonBridge 
 www.mricro.com :: BSD 2-Clause License (opensource.org/licenses/BSD-2-Clause)
PythonBridge
 Scale 87.1677
 Origin 0.0000x-17.6963x15.8235
 Mesh Vertices 81924 Faces 163840 Colors 0
    -68.5030..68.5030  -104.8640..69.4714 -48.3929..80.0398
 Track Vertices 0 Faces 0 Count 0
 Node Vertices 0 Faces 0
 GPU Mesa :: OpenGL  4.5 (Core Profile) Mesa 23.0.4-0ubuntu1~22.04.1 :: GLSL 4.50
``
@neurolabusc
Copy link
Owner

The Background transparent in bitmaps check box in the preferences controls whether an image is saved with opaque or transparent background.

Screenshot 2024-09-05 at 9 35 01 AM

@JohannesWiesner
Copy link
Author

Nice! Didn't now that :) Unfortunately I am using a python script to generate my plots, is there also a way to implement this in my script?

@neurolabusc
Copy link
Owner

Your preferences are stored between sessions, so you can set it once with the user interface and the scripts should use the current setting.

@JohannesWiesner
Copy link
Author

Interesting, this is actually the case for me. Still the image get's generated with the white background when I run my python script within the script editor of Surf Ice:

import gl
gl.resetdefaults()

# load default brain
gl.meshload('BrainMesh_ICBM152.mz3')

# make brain look pinkish
gl.meshcolor(210, 148, 148)

# overlay roi image
gl.overlayload('input/to/rois.nii.gz')

# choose color for ROIS by playing around with the name of
# the colorscale, and the second and third argument of overlayminmax
gl.overlaycolorname(1,'electric-blue')
gl.overlayminmax(1,0.01,1.8)

# show left or right side of the brain
gl.viewsagittal(0)

# To get the left hemisphere only:
gl.clipazimuthelevation(0.5,90,0)

# save plot
gl.bmpzoom(1)
gl.savebmp('/output/path/rois.png')

@neurolabusc
Copy link
Owner

I am unable to replicate. I notice that your are running Surfice with software emulation (Mesa 23.0.4). Why don't you try this with a computer that has hardware accelerated graphics.

import gl
gl.resetdefaults()
gl.azimuthelevation(70, 15)
gl.meshload('BrainMesh_ICBM152.rh.mz3')
gl.overlayload('motor_4t95vol.nii.gz')
gl.overlayminmax(1,2,12)
gl.overlayload('motor_4t95vol.nii.gz')
gl.overlayminmax(2,-1,-2)
gl.colorbarvisible(1)
gl.overlaytransparencyonbackground(25)
gl.meshcurv()
gl.backcolor(255,0,0)
gl.savebmp('rois.png')

roisx

rois

@JohannesWiesner
Copy link
Author

@neurolabusc :

I can recreate your working example on a local machine with an Nvidia GPU. I am using surfice on a virtual machine that does not have a graphics card. Also, surfice is used here as an environment module (https://modules.readthedocs.io/en/latest/index.html). I wonder what is causing the problem here, the fact that the VM has no GPU or because of the deployment. I'm currently guessing the former, because even with environment modules my settings should be stored in my local home directory on my virtual machine (you can also see this in the stdout):

Loading preferences: /zi/home/johannes.wiesner/.surfice/surfice.ini

Can you replicate the "bug" (missing transparency although it is turned on) when using a machine without a GPU?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants