This worked.

(a bit too much and defeating the purpose, but as I called each “v.add_layer” it was adding it as I was coding.

It’s handy while developing before setting the whole code and functions.

```
import napari
sys.path.insert(0,'/home/jmamede/scripts')
from nd2reader import ND2Reader
# from support_pla import othercolor, cell_mask, multiply, rebin
from support_pla import detect_masks
%gui qt
v = napari.Viewer(show=False)
v.show()
# layer = viewer.add_image(np.random.random((512, 512)))
def updating(result):
[v.layers.pop(0) for la in range(len(v.layers))]
v.add_image(
result[0],
blending='additive',
contrast_limits=[np.min(result[1]),np.max(result[1])],
# ndisplay=2,
colormap='blue',
name='nuclei'
)
v.add_labels(
result[1],
opacity=0.4,
blending='additive',
# contrast_limits=[np.min(result[2]),np.max(result[2])],
name='nuclei'
)
@thread_worker(connect={'yielded': updating})
def poseri(filelist,chan_cells,chan_nuclei,model,model_nuc):
for ficheiro in filelist:
reader = ND2Reader(ficheiro)
reader.bundle_axes = 'cyx'
reader.iter_axes = 'z'
#there is a bug, it reads each visit point as a Z.
reader.default_coords['v'] = 0
ncells = 0
nnuclei = 0
#there's a bug in my reader, here's the 'Z' is actually visit points ('v').
for i in range(reader.sizes['z']):
cells_masks = detect_masks(reader[i][chan_cells],model
# ,size=2500
,threshold=0.8,size=0,diam=50
)
nuclei_masks = detect_masks(reader[i][chan_nuclei],model_nuc
# ,size=2500
,threshold=1.2,size=0,diam=25
)
cell_outlines = make_outlines(cells_masks)
text = "Image#: {0} Number of Nuclei: {1} Number of positive cells: {2} Percentage: {3}".format(i,nuclei_masks.max(),cells_masks.max(),cells_masks.max()/nuclei_masks.max())
print(ficheiro,text)
yield [reader[i][chan_cells],reader[i][chan_nuclei],cells_masks,nuclei_masks]
model = initializesomestuff(GPU=True,model='cells')
model_nuc = initializesomestuff(GPU=True,model='nuclei')
poseri(filelist,0,1,model,model_nuc)
```