brainrender icon indicating copy to clipboard operation
brainrender copied to clipboard

smooth brain outline[Feature]

Open chongtianyifa opened this issue 1 year ago • 3 comments

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: image 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?

chongtianyifa avatar Feb 03 '24 05:02 chongtianyifa

Hey @chongtianyifa

Thanks for raising this. Can you explain how you generate the videos here, please?

alessandrofelder avatar Feb 05 '24 11:02 alessandrofelder

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.

adamltyson avatar Feb 05 '24 11:02 adamltyson

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.

chongtianyifa avatar Feb 06 '24 04:02 chongtianyifa

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

adamltyson avatar May 14 '24 09:05 adamltyson

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

imagesc-bot avatar May 14 '24 09:05 imagesc-bot

@alessandrofelder shall we make plastic the default style again?

adamltyson avatar May 14 '24 09:05 adamltyson

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)

alessandrofelder avatar May 14 '24 11:05 alessandrofelder

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.

marcomusy avatar May 14 '24 12:05 marcomusy

The default has been changed (temporarily) to plastic in #350

adamltyson avatar May 14 '24 15:05 adamltyson

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

Screenshot from 2024-05-14 21-14-17

it seems to me that render() does more stuff than simply rendering the scene.

marcomusy avatar May 14 '24 19:05 marcomusy

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()?

adamltyson avatar May 15 '24 08:05 adamltyson

Totally safe :)

marcomusy avatar May 15 '24 10:05 marcomusy

@marcomusy thanks! I've raised https://github.com/brainglobe/brainrender/pull/352 to fix this.

adamltyson avatar May 15 '24 11:05 adamltyson

Hi @chongtianyifa this issue has now been fixed. If you update brainrender ( pip install brainrender -U) it should work fine.

adamltyson avatar May 16 '24 11:05 adamltyson