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

Silhouettes (in cartoon mode) have a jagged appearance when the scene is rotates #327

Closed
chongtianyifa opened this issue Feb 3, 2024 · 14 comments · Fixed by #352
Closed
Labels
enhancement New feature or request

Comments

@chongtianyifa
Copy link

chongtianyifa commented Feb 3, 2024

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:

media0.mp4

Below is the video created with the same data using an older version (very likely v2.0.0.0)

Media1.mp4

Is there any way to improve the quality?

@chongtianyifa chongtianyifa added the enhancement New feature or request label Feb 3, 2024
@alessandrofelder
Copy link
Member

Hey @chongtianyifa

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

@adamltyson
Copy link
Member

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.

@chongtianyifa
Copy link
Author

chongtianyifa commented Feb 6, 2024

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:

B3M3S17_glossy.mp4

The color of each point is not pure magenta while the outline is smooth now.

@adamltyson
Copy link
Member

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

@imagesc-bot
Copy link

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

@adamltyson
Copy link
Member

@alessandrofelder shall we make plastic the default style again?

@alessandrofelder
Copy link
Member

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)

@marcomusy
Copy link
Contributor

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.

@adamltyson adamltyson changed the title smooth brain outline[Feature] Silhouettes (in cartoon mode) have a jagged appearance when the scene is rotates May 14, 2024
@adamltyson
Copy link
Member

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

@marcomusy
Copy link
Contributor

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.

@adamltyson
Copy link
Member

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

@marcomusy
Copy link
Contributor

Totally safe :)

@adamltyson
Copy link
Member

@marcomusy thanks! I've raised #352 to fix this.

@adamltyson
Copy link
Member

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

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

Successfully merging a pull request may close this issue.

5 participants