-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Summary
I'm using this repo to deconvolve brightfield images, however there is a mistake in waveorder.filter that prevents the code from working.
Code for reproduction
Deconvolution Parameters
transfer_function_arguments = {
'wavelength_illumination': 0.532,
'z_padding': 0,
'numerical_aperture_detection': 1.25,
'numerical_aperture_illumination': 0.5,
}
simulation_arguments = {
"zyx_shape": (128, 256, 256),
"yx_pixel_size": 0.1625,
"z_pixel_size": 0.5,
"index_of_refraction_media": 1.33,
}
Input images have a dimension of 245x2048x2048
Error Traceback
Traceback (most recent call last):
File ".../CytoLand/data/far-red/hcs.py", line 157, in <module>
main()
File ".../CytoLand/data/far-red/hcs.py", line 91, in main
img_phase = phase_thick_3d.apply_inverse_transfer_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../miniconda3/envs/viscy/lib/python3.11/site-packages/waveorder/models/phase_thick_3d.py", line 264, in apply_inverse_transfer_function
f_real = apply_filter_bank(inverse_filter[None, None], zyx[None])[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../miniconda3/envs/viscy/lib/python3.11/site-packages/waveorder/filter.py", line 114, in apply_filter_bank
padded_output_spectrum[output_channel_idx] += stretched_multiply(
RuntimeError: The size of tensor a (256) must match the size of tensor b (2048) at non-singleton dimension 2
Error Cause
The reason for this error is found here https://github.com/mehta-lab/waveorder/blob/aa7050f973f36dc204ea495e105b5432223dc68d/waveorder/filter.py#L77
The spatial dimensions for padded_output_spectrum is being determined by the shape of the filter, not the padded_input_spectrum. This means that when the result of streched_multipy() is added to the output array at line 114 there is a dimension missmatch.
Fix
Remove line 77 and add spatial_dims = padded_input_spectrum.shape[1:] after line 91. This allows the deconvolution to run successfully
Environment:
Operating system: Ubuntu 24.04
Python version: 3.11
Repo Version: 2.2.1