Skip to content

Commit

Permalink
Improve image preprocessing prints
Browse files Browse the repository at this point in the history
  • Loading branch information
msorelli committed May 15, 2024
1 parent b84e604 commit 8b1c598
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
1 change: 0 additions & 1 deletion foa3d/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def create_save_dirs(img_path, img_name, cli_args, is_fiber=False):
base_out_dir = path.join(out_path, time_stamp + '_' + img_name)
save_dir_lst = list()
if not path.isdir(base_out_dir):
print("Creating directory")
makedirs(base_out_dir)

# create Frangi filter output subdirectory
Expand Down
46 changes: 26 additions & 20 deletions foa3d/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,41 @@ def config_anisotropy_correction(px_sz, psf_fwhm):
new isotropic pixel size [μm]
"""

# print preprocessing heading
print_prepro_heading()

# set the isotropic pixel resolution equal to the z-sampling step
px_sz_iso = px_sz[0] * np.ones(shape=(3,))

# adjust PSF anisotropy via lateral Gaussian blurring
if not np.all(psf_fwhm == psf_fwhm[0]):
# detect preprocessing requirement
cndt_1 = not np.all(psf_fwhm == psf_fwhm[0])
cndt_2 = np.any(px_sz != 1.0)
smooth_sigma = None
if cndt_1 or cndt_2:

# estimate the PSF variance from input FWHM values [μm^2]
psf_var = np.square(fwhm_to_sigma(psf_fwhm))
# print preprocessing heading
print_prepro_heading()

# estimate the in-plane filter variance [μm^2]
gauss_var = np.array([0, psf_var[0] - psf_var[1], psf_var[0] - psf_var[2]])
# adjust PSF anisotropy via lateral Gaussian blurring
if cndt_1:

# ...and the corresponding standard deviation [px]
smooth_sigma = np.divide(np.sqrt(gauss_var), px_sz)
# estimate the PSF variance from input FWHM values [μm^2]
psf_var = np.square(fwhm_to_sigma(psf_fwhm))

# print preprocessing info
smooth_sigma_um = np.multiply(smooth_sigma, px_sz)
print_blur(smooth_sigma_um)
# estimate the in-plane filter variance [μm^2]
gauss_var = np.array([0, psf_var[0] - psf_var[1], psf_var[0] - psf_var[2]])

# (no blurring)
else:
print("\n")
smooth_sigma = None
# ...and the corresponding standard deviation [px]
smooth_sigma = np.divide(np.sqrt(gauss_var), px_sz)

# print preprocessing info
smooth_sigma_um = np.multiply(smooth_sigma, px_sz)
print_blur(smooth_sigma_um, psf_fwhm)

# print pixel resize info
print_new_res(px_sz_iso, psf_fwhm)
# print pixel resize info
if cndt_2:
print_new_res(px_sz_iso)

# skip line
else:
print()

return smooth_sigma, px_sz_iso

Expand Down
18 changes: 9 additions & 9 deletions foa3d/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def print_analysis_time(start_time):
print("\nVolume image analyzed in: {0} min {1:3.1f} s\n".format(mins, secs))


def print_blur(smooth_sigma_um):
def print_blur(smooth_sigma_um, psf_fwhm):
"""
Print gaussian lowpass filter standard deviation.
Expand All @@ -126,13 +126,16 @@ def print_blur(smooth_sigma_um):
3D standard deviation of the low-pass Gaussian filter [μm]
(resolution anisotropy correction)
psf_fwhm: numpy.ndarray (shape=(3,), dtype=float)
3D FWHM of the PSF [μm]
Returns
-------
None
"""
print("\n Z Y X")
print("Gaussian blur \u03C3 [μm]: ({0:.3f}, {1:.3f}, {2:.3f})"
.format(smooth_sigma_um[0], smooth_sigma_um[1], smooth_sigma_um[2]), end='\r')
.format(smooth_sigma_um[0], smooth_sigma_um[1], smooth_sigma_um[2]))
print("Adjusted PSF FWHM [μm]: ({0:.3f}, {0:.3f}, {0:.3f})\n".format(psf_fwhm[0]))


def print_import_time(start_time):
Expand Down Expand Up @@ -193,6 +196,7 @@ def print_prepro_heading():
None
"""
print(color_text(0, 191, 255, "\n\nMicroscopy Volume Image Preprocessing"))
print("\n Z Y X")


def print_native_res(px_size, psf_fwhm):
Expand All @@ -215,7 +219,7 @@ def print_native_res(px_size, psf_fwhm):
print("PSF FWHM [μm]: ({0:.3f}, {1:.3f}, {2:.3f})".format(psf_fwhm[0], psf_fwhm[1], psf_fwhm[2]))


def print_new_res(px_sz_iso, psf_fwhm):
def print_new_res(px_sz_iso):
"""
Print adjusted isotropic spatial resolution.
Expand All @@ -224,15 +228,11 @@ def print_new_res(px_sz_iso, psf_fwhm):
px_sz_iso: numpy.ndarray (shape=(3,), dtype=float)
new isotropic pixel size [μm]
psf_fwhm: numpy.ndarray (shape=(3,), dtype=float)
3D FWHM of the PSF [μm]
Returns
-------
None
"""
print("\nAdjusted pixel size [μm]: ({0:.3f}, {1:.3f}, {2:.3f})".format(px_sz_iso[0], px_sz_iso[1], px_sz_iso[2]))
print("Adjusted PSF FWHM [μm]: ({0:.3f}, {0:.3f}, {0:.3f})\n".format(psf_fwhm[0]))
print("Adjusted pixel size [μm]: ({0:.3f}, {1:.3f}, {2:.3f})\n".format(px_sz_iso[0], px_sz_iso[1], px_sz_iso[2]))


def print_slicing_info(image_shape_um, slice_shape_um, tot_slice_num, px_size, image_item_size):
Expand Down

0 comments on commit 8b1c598

Please sign in to comment.