PolarizedLightFieldMicroscopy / BirTomo

Geometrical Birefringence Tomography
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

Store valid rays specific to each microlens #73

Closed gschlafly closed 10 months ago

gschlafly commented 11 months ago

Currently the images are formed by filling the image in with retardance and azimuth values for the indices with valid rays. This process should also work if the set of valid rays is specific to a particular microlens. https://github.com/PolarizedLightFieldMicroscopy/forward-model/blob/d644468ab8e5adcc215b19ba1a72918e6cef2f53/VolumeRaytraceLFM/birefringence_implementations.py#L1332-L1348

The valid ray indices is calculated in the _compute_raygeometry method: https://github.com/PolarizedLightFieldMicroscopy/forward-model/blob/d644468ab8e5adcc215b19ba1a72918e6cef2f53/VolumeRaytraceLFM/abstract_classes.py#L479-L525

Solution Ideas The _compute_raygeometry method can be modularized. A map from the valid ray to the pixel positions can be created. This may be done with ray_valid_indices. Another attribute of the class can store this information for each microlens.

gschlafly commented 11 months ago

Created a new attribute called ray_valid_indices_by_ray_num to distinguish from ray_valid_indices. They contain the same information, but stored differently. The previous description of the variables was incorrect. The updated version is

'''
self.ray_valid_indices_by_ray_num (list of tuples n_rays*[(i,j),]):
    Store the 2D ray index of a valid ray (without nan in entry/exit)
self.ray_valid_indices: array of shape (2, n_valid_rays):
    Stores the 2D indices of the valid rays
'''
gschlafly commented 11 months ago

I saved the unrounded lateral length as an attribute too: https://github.com/PolarizedLightFieldMicroscopy/forward-model/blob/8558a1f571e6c6feac0818add643d636ac0f6d57/VolumeRaytraceLFM/abstract_classes.py#L531-L565

gschlafly commented 11 months ago

Note that to calculate the ray entrance and exit positions, the restricted volume shape is used: https://github.com/PolarizedLightFieldMicroscopy/forward-model/blob/2cdf0cc69b120ec6264aa9d8277b56829012689e/VolumeRaytraceLFM/abstract_classes.py#L501-L559

gschlafly commented 10 months ago

When only a $1\times 1$ microlens array is used, the rays leading to zero retardance pixels are filtered out. This was implemented in f211f7e3f2a497991726f3bea3bd11995df4030c.

gschlafly commented 10 months ago

When looping through the lenslets of the microlens array, rays specific to the lenslet should be accessed. https://github.com/PolarizedLightFieldMicroscopy/GeoBirT/blob/4210aeb748015fbd514c19a46458592b2244975e/VolumeRaytraceLFM/birefringence_implementations.py#L956-L1028 This may mean that the microlens index needs to be passed into _generate_images(). https://github.com/PolarizedLightFieldMicroscopy/GeoBirT/blob/4210aeb748015fbd514c19a46458592b2244975e/VolumeRaytraceLFM/birefringence_implementations.py#L1066-L1070

gschlafly commented 10 months ago

In 53103332b0336dcaaa1d9907e9aad509b74ff686, I excluded the Jones matrix calculations for lenslets that had not rays that let to nonzero pixels. For a volume of shape [11, 7, 7] with only a single birefringent voxel in the center, the execution time to ray trace through the volume 100 times is the following: image This shows that the ray tracing time was reduced by a factor of 10 for the lenslets without retardance.

gschlafly commented 10 months ago

The class RayTraceLFM now has two attributes, use_lenslet_based_filtering and nonzero_pixels_dict, that are used to identify and filter out the rays that lead to zero retardance in the image being used to reconstruct a volume.