brainrender
brainrender copied to clipboard
smooth brain outline[Feature]
Hi,
I recently updated to the newest version and found that the rendered brain outline is very coarse, especially during rotating.
The first frame looks ok:
the outline looks coarse after rotating:
https://github.com/brainglobe/brainrender/assets/46367566/9d2cfc9a-237d-4e65-925b-e3243db9eb6b
Below is the video created with the same data using an older version (very likely v2.0.0.0)
https://github.com/brainglobe/brainrender/assets/46367566/002dbfce-99ae-47ae-a05b-b2917450a8a4
Is there any way to improve the quality?
Hey @chongtianyifa
Thanks for raising this. Can you explain how you generate the videos here, please?
I've also noticed this, I just haven't had the time to look into it. I think it's specific to the default, cartoon
style. Not sure if it's on our side, or on the vedo side.
As an aside, we may want to change the default away from cartoon
. It looks nice for 2D figures, but it's less useful for 3D exploration.
hi @alessandrofelder, Here is the script I used in Jupyter notebook to create this video: `from brainrender import Scene, actors import brainrender from brainrender.actors import Points, PointsDensity import vedo import numpy as np import pandas as pd import random from brainrender.video import VideoMaker
import os #from itkwidgets import view
vedo.settings.default_backend= 'vtk' brainrender.settings.BACKGROUND_COLOR = "white" brainrender.settings.ROOT_ALPHA = 0.1 # transparency of the overall brain model's actor' brainrender.settings.SHOW_AXES = False brainrender.settings.SHADER_STYLE = "cartoon"`
scene = Scene(inset=False, atlas_name='allen_mouse_25um', title=video_title) # make sure this is right scene.add(Points(coordinates, colors="magenta", alpha=0.9, radius=10)) scene.add_brain_region('SSp', alpha=0.25, color="green")
vm = VideoMaker(scene, name=video_name, save_fld=os.path.join(os.path.dirname(ABBA_accum_tranformed_file))) # niters = number of frames vm.make_video( azimuth=1, elevation=0, roll=0 #duration=20 fps=15 ) # specify how the scene rotates at each frame
scene.close()‘
Indeed, it is the issue of SHADER_STYLE as @adamltyson mentioned . After trying metallic, plastic, shiny, glossy options, they gave me the same video:
https://github.com/brainglobe/brainrender/assets/46367566/10044932-a1eb-4986-a847-c49f2eb3d2a4
The color of each point is not pure magenta while the outline is smooth now.
Looking into this further due to https://forum.image.sc/t/brainrender-lines-on-render/96270.
@marcomusy I don't suppose you have any idea why we're seeing these artefacts using one specific style? We didn't see them in previous versions of brainrender, but we had vedo pinned for a long time.
For anyone seeing this, the workaround is to either set the rotation before rendering, or choose another shader style with:
# before creating a scene
from brainrender import settings
settings.SHADER_STYLE = "plastic" # choose from [metallic, plastic, shiny, glossy, cartoon], default is cartoon
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/brainrender-lines-on-render/96270/3
@alessandrofelder shall we make plastic
the default style again?
shall we make
plastic
the default style again?
Sure (I don't have a strong opinion... I didn't know it was the default at some point)
Hi, from a quick look at the code It looks to me that the "cartoon" option of brainrender generates and adds to the scene a "silhouette" object. For some reason I don't quite understand, the link to the camera is lost (that is why it only looks good on the first frame). I need to investigate that further.. I guess at the moment the best option is to disable it while I figure out.
The default has been changed (temporarily) to plastic
in #350
This minimal example actually works..
from brainrender import Scene
from vedo import settings
settings.default_font = "Theemim"
scene = Scene()
brain = scene.plotter.objects[0]
sil = brain.silhouette().c('blue5').lw(2)
# scene.add_silhouette(sil) # not working
scene.plotter.add(sil)
scene.plotter.show()
# scene.render() # not working
it seems to me that render() does more stuff than simply rendering the scene.
Thanks @marcomusy, this line seems to be the culprit.
Leaving camera
as the default (None
) seems to work fine with our examples. brainrender
sets the camera
earlier in the call to scene.render()
here, so it's not clear to me why the camera needs to passed to plotter.show()
.
Is it safe to not pass this parameter to plotter.show()
?
Totally safe :)
@marcomusy thanks! I've raised https://github.com/brainglobe/brainrender/pull/352 to fix this.
Hi @chongtianyifa this issue has now been fixed. If you update brainrender ( pip install brainrender -U
) it should work fine.