Repository: napari/napari

Issue:
Passing gamma to add_image() and view_image() doesn't properly set gamma
## 🐛 Bug
As noted by @nicost in #1822, passing a gamma value to `viewer.add_image()` and `napari.view_image()` doesn't update the gamma on the vispy node. It does however set the gamma value in the model. The gamma update function in the vispy file works, as slider works as expected. I believe the if statement below in the gamma update method is the culprit. However, removing the if statement causes an error upon instantiation (which is why it was probably provided in the first place). I haven't had a chance to look further into this, but it may be because the parent has been assigned to the node yet.

https://github.com/napari/napari/blob/20f3479321187084a345cef05a9a059a2ad32874/napari/_vispy/vispy_image_layer.py#L162-L163

## To Reproduce

Steps to reproduce the behavior:

```python
data = np.random.random((100, 100))

with napari.gui_qt():
    viewer = napari.view_image(data, gamma=0.1)
```

## Expected behavior

The gamma should be updated in the image node.

## Environment
```
napari: 0.3.9.dev27+g52cc6cd.d20201006
Platform: Linux-5.4.0-53-generic-x86_64-with-debian-bullseye-sid
Python: 3.7.7 (default, May 7 2020, 21:25:33) [GCC 7.3.0]
Qt: 5.14.2
PyQt5: 5.14.2
NumPy: 1.19.1
SciPy: 1.5.2
Dask: 2.24.0
VisPy: 0.6.4

GL version: 4.6.0 NVIDIA 450.66
MAX_TEXTURE_SIZE: 32768

Plugins:
- napari_plugin_engine: 0.1.7
- svg: 0.1.4
```




Discussion:
Hi, is there any update on this bug? 
@karchern Woof, looks like this fell through the cracks. Thanks for bumping it. I can confirm it's still a bug. Will try to get some eyes on it.
Hi, just in case, checked this locally on Windows and removing the validation in the `_on_gamma_change` (now located at [`napari/_vispy/layers/image.py`](https://github.com/napari/napari/blob/49e235ae94e4a3c9d473208a10fa191a22a07c76/napari/_vispy/layers/image.py#L189-L191)) seems like makes things work and seems like now the change doesn't trigger any error 🤔 
Ooof, thanks for bumping this @dalthviz !
Definitely would be good to fix this!
Maybe @brisvag has some thoughts as the resident vispy guru?

I have no clue what that `if` clause is trying to do xD it comes from way back in #1456 ^^'
> Hi, just in case, checked this locally on Windows and removing the validation in the `_on_gamma_change` (now located at [`napari/_vispy/layers/image.py`](https://github.com/napari/napari/blob/49e235ae94e4a3c9d473208a10fa191a22a07c76/napari/_vispy/layers/image.py#L189-L191)) seems like makes things work and seems like now the change doesn't trigger any error 🤔

That works for me too. Good temporary fix, but of course might require a deeper dive to understand what this `if` really is doing.
Reproducer:
```
import numpy as np

img = np.random.random(200, 200)
viewer = napari.Viewer()
viewer.add_image(img, gamma = 0.5)
viewer.add_image(img, gamma = 1.5)
viewer.grid.enabled = True
```
You will see the two layers side by side are identical.
Thumbnail is correct.

Resolving patch:
diff --git a/napari/_vispy/layers/image.py b/napari/_vispy/layers/image.py
--- a/napari/_vispy/layers/image.py
+++ b/napari/_vispy/layers/image.py
@@ -350,8 +350,7 @@ def _on_blending_change(self, event=None) -> None:
         self._update_mip_minip_cutoff()
 
     def _on_gamma_change(self) -> None:
-        if len(self.node.shared_program.frag._set_items) > 0:
-            self.node.gamma = self.layer.gamma
+        self.node.gamma = self.layer.gamma
 
     def _on_iso_threshold_change(self) -> None:
         if isinstance(self.node, VolumeNode):


Test patch: