Function to autoadjust (LUT) programatically?

Hi there,

Amazing job with Napari. When one adds an image layer it automatically adjusts LUT (and I believe size to fit the viewer). However when one updates the layer with other data e.g.

my_image_layer = viewer.add_image(foo)
my_image_layer.data = new_foo

The new image is not adjusted. So in order for this to happen one could delete the old layer and insert the new image in a new image layer. However I was wondering whether there might be any function, that is run when creating the layer, and can be accessed, to autoadjust LUT? I hope I made the question clear if it is not hit me back please !

1 Like

to autoadjust the contrast limits, you can use my_image_layer.reset_contrast_limits()
If you want it to happen automatically, you can connect that function to the data change event:

layer.events.data.connect(lambda e: layer.reset_contrast_limits())

(this sort of “keep autoscale” option might be a good feature for someone to add)

3 Likes

Awesome it worked . Thanks!

1 Like

Could be a good first issue, though I’d want a way to toggle the behaviour on/ off