import os import glob import dask import pandas as pd import numpy as np import imageio import dask.array as da import matplotlib.pyplot as plt import cv2 from PIL import Image import napari import numpy as np import matplotlib.pyplot as plt from skimage import exposure from scipy import ndimage, signal from flowdec import data as fd_data from flowdec import psf as fd_psf from flowdec import restoration as fd_restoration from czifile import CziFile from dask.diagnostics import ProgressBar #%% path_to_folder = 'CZI_FIles' channel_id = 'thy_1_488.czi' path_to_image = os.path.join(path_to_folder, channel_id) path_to_save = os.path.join(path_to_folder, 'processed') if not os.path.exists(path_to_save): os.mkdir(path_to_save) metadata = CziFile(path_to_image).metadata() dapi = CziFile(path_to_image).asarray() dapi = dapi[0, 0, 0, 0, 0, 0, 0, :, :, :, 0] #%% args = dict( # Set psf dimensions to match volumes size_x=480, size_y=480, size_z=178, # Magnification factor m=20, # Numerical aperture na=0.75, # Axial resolution in microns (nm in akoya config) res_axial= 7867.299999999999/1000, # Lateral resolution in microns (nm in akoya config) res_lateral= 2287.3925606171746/1000, # Immersion refractive index ni0=1.45, # Set "particle position" in Gibson-Lannie to 0 which gives a # Born & Wolf kernel as a degenerate case pz=0. ) psf_single = fd_psf.GibsonLanni(**{**args, **{'wavelength': 498/1000.}}).generate() #%% algo = fd_restoration.RichardsonLucyDeconvolver(3).initialize() res = algo.run(fd_data.Acquisition(data=dapi[:, 0:480, 0:480], kernel=psf_single), niter=50) #%% with napari.gui_qt(): viewer = napari.Viewer() viewer.add_image(res.data, name='DAPI', scale=(1, 1, 1, 3, 1, 1), blending='additive', gamma=0.85) #%% data = [] total_data = [] algo = fd_restoration.RichardsonLucyDeconvolver(3).initialize() # for n in range(4): for k in range(4): datao = dapi[:, n*480:(n+1)*480, k*480:(k+1)*480] # datao = datao[np.newaxis, :, :] res = algo.run(fd_data.Acquisition(data=datao, kernel=psf_single), niter=70) data_deconvolved = res.data data.append(data_deconvolved) total_data.append(data) data = [] combined_image = da.block(total_data) combined_image.shape