Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
talonchandler committed Oct 2, 2024
1 parent 902c690 commit 1cb7d53
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/models/inplane_oriented_thick_pol3d_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
wavelength_illumination = 0.532
z_padding = 0
index_of_refraction_media = 1.3
numerical_aperture_illumination = 0.01 # 0.5
numerical_aperture_illumination = 0.5
numerical_aperture_detection = 1.2
fourier_oversample_factor = 1

Expand Down
5 changes: 1 addition & 4 deletions waveorder/models/inplane_oriented_thick_pol3d_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ def _calculate_wrap_unsafe_transfer_function(
G_3D = torch.abs(torch.fft.ifft(G, dim=-3)) * (-1j)
S_3D = torch.fft.ifft(S, dim=-3)

# # Normalize
# P_3D /= torch.amax(torch.abs(P_3D))
# G_3D /= torch.amax(torch.abs(G_3D))
# S_3D /= torch.amax(torch.abs(S_3D))

# Main part
PG_3D = torch.einsum("zyx,ipzyx->ipzyx", P_3D, G_3D)
Expand Down Expand Up @@ -256,6 +252,7 @@ def visualize_transfer_function(viewer, sfZYX_transfer_function, zyx_scale):
zyx_scale=zyx_scale,
layer_name="Transfer Function",
complex_rgb=True,
clim_factor=0.5,
)


Expand Down
3 changes: 2 additions & 1 deletion waveorder/visuals/napari_visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def add_transfer_function_to_viewer(

if complex_rgb:
rgb_transfer_function = complex_tensor_to_rgb(
torch.fft.ifftshift(transfer_function, dim=shift_dims)
torch.fft.ifftshift(transfer_function, dim=shift_dims),
saturate_clim_fraction=clim_factor,
)
viewer.add_image(
rgb_transfer_function,
Expand Down
5 changes: 3 additions & 2 deletions waveorder/visuals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Main function to convert a complex-valued torch tensor to RGB numpy array
# with red at +1, green at +i, blue at -1, and purple at -i
def complex_tensor_to_rgb(tensor):
def complex_tensor_to_rgb(tensor, saturate_clim_fraction=1.0):
# Convert the torch tensor to a numpy array
tensor_np = tensor.numpy()

Expand All @@ -17,7 +17,8 @@ def complex_tensor_to_rgb(tensor):
hue = np.mod(hue + 0.5, 1)

# Normalize magnitude to [0, 1] for saturation
max_abs_val = np.amax(magnitude)
max_abs_val = np.amax(magnitude) * saturate_clim_fraction

sat = magnitude / max_abs_val if max_abs_val != 0 else magnitude

# Create HSV array: hue, saturation, value (value is set to 1)
Expand Down

0 comments on commit 1cb7d53

Please sign in to comment.