-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Hi @tlambert03,
While testing my code, I noticed that sometimes the image (in this case, ndarrays loaded from .nrrd files) would change shape seemingly randomly. I am unsure about the cause of this and believe it is some sort of bug present in the library. I would appreciate it if you are able to give some pointers on how I can work around this issue.
Additionally, I noticed that the edges of the image are not being deconvolved. Correct me if I am wrong, but I think this is due to the nature of the algorithm, hence the padding before applying the deconvolution.
I have provided a snippet of my code, as well as some sample data in case you want to reproduce the error. You will have to extract the zip folder and provide the file paths as displayed in the main function.
Thank you!
import nrrd
from pathlib import Path
from numpy import pad
from pycudadecon import decon, make_otf
def process_cube(
input_file: Path, # path to nrrd file
temp_folder: Path, # path to a temporary folder (folder must exist before function runs)
psf: str, # string representing path to psf file
pad_amount: int, # amount to pad to each side of image before applying deconvolution
n_iters: int = 9,
dz_data: float = 0.7,
dx_data: float = 0.7,
dz_psf: float = 1.8,
dxy_psf: float = 0.2,
background: int = 0,
wavelength_em: int = 525,
na: float = 0.4,
nimm: float = 1.42
):
# read input file
img, header = nrrd.read(input_file.__str__())
# generate otf file from psf file
otf_file = make_otf(
psf,
outpath=(temp_folder / 'otf.tif').__str__(),
dzpsf=dz_psf,
dxpsf=dxy_psf,
wavelength=wavelength_em,
na=na,
nimm=nimm,
fixorigin=0,
)
print("Image shape before pad: ", img.shape)
# pad to ensure edges of image are deconvolved
img = pad(img, pad_amount, 'reflect')
print("Image shape (after pad), before deconvolution: ", img.shape)
# run deconvolution
img = decon(
img,
otf_file,
fpattern=None,
n_iters=n_iters,
dzdata=dz_data,
dxdata=dx_data,
dzpsf=dz_psf,
dxpsf=dxy_psf,
background=background,
wavelength=wavelength_em,
na=na,
nimm=nimm
)
print("Image shape after deconvolution: ", img.shape)
# ... rest of code is irrelevant
if __name__ == '__main__':
# change pad_amount to different integers. sometimes the deconvolution causes image to change size.
# .nrrd file along with psf.tif are provided as sample data.
process_cube(
Path("C:/path/to/file/y00006400.x00019200.nrrd"),
Path("C:/path/to/temp/folder"),
"C:/path/to/psf.tif",
pad_amount=1
)