Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master seb #42

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
39cf862
upload final notebooks
sebcrom Apr 7, 2023
621bdc3
Add reconstruction script
nducros May 24, 2023
3b66edc
Spyrit reconstrcution with experimental patterns
nducros Jun 6, 2023
64fa4f9
Add training of pinv-net
nducros Jun 6, 2023
fa050c5
Add recconstruction scripts
nducros Jun 13, 2023
ec65e6c
Proprocess negative and positive patterns independently
nducros Jun 13, 2023
4d1a6d0
Add training script and shell
nducros Jun 13, 2023
f39e3eb
Add training shell
nducros Jun 13, 2023
3a37fca
Add training dcript
nducros Jun 13, 2023
5573009
Plot and save experimental patterns
nducros Jun 13, 2023
aa23859
Includes training of DC-Net and Tikho-Net
nducros Jun 15, 2023
7336040
Estimate photon counts from pinv
nducros Jun 23, 2023
f43cf6f
Evaluate tikhonet and pinvnet in simulations
nducros Jun 23, 2023
839092e
New scripts for systematic reconstructions
nducros Jul 26, 2023
6eaacc1
Updated training
nducros Jul 26, 2023
08b560b
Update covariance computation
nducros Jul 26, 2023
50beb7e
Update reconstruction from experimental data
nducros Jul 26, 2023
2c4163f
Plot sum of pos and neg patterns
nducros Jul 26, 2023
129898d
Add unmixing et visualisation scripts for both zebrafishes
nducros Jul 30, 2023
828b3b7
Canonical vs Hadamard comparison
nducros Oct 13, 2023
05539b4
Unmix without noise + svg + autofluo fig
nducros Oct 19, 2023
5ba80aa
Update unmixing scripts
nducros Jan 11, 2024
7d62c6e
Update visualization scripts
nducros Jan 11, 2024
e8518ca
Add colorization scripts
nducros Jan 11, 2024
d0290ef
Add/update pattern scripts
nducros Jan 11, 2024
b7a1cc1
Functions for colorization
nducros Jan 11, 2024
5e5b0b3
Compensate for spectral shift
nducros Jan 11, 2024
93fc1c6
Update reconstruction script
nducros Jan 11, 2024
f8064ad
Zip result subfolders
nducros Jan 11, 2024
f55fe0f
Add script for comparison with raster scan
nducros Jan 12, 2024
06048c9
Fellgett effect
nducros Sep 17, 2024
542dd71
plot acquisition patterns
nducros Sep 17, 2024
63acf62
numpy compatibility
nducros Sep 17, 2024
8ee5307
rotate recon
nducros Sep 20, 2024
110307a
update plot of spectra
nducros Oct 4, 2024
c5e1992
update plot of spectra
nducros Oct 4, 2024
2329658
Compute PSNRs
nducros Oct 10, 2024
a040790
send data to warehouse
nducros Oct 11, 2024
b19c624
change colors and folder structure
nducros Oct 16, 2024
8088814
Unmixing returns 512x512 images
nducros Oct 22, 2024
a90391f
creation of animated GIF
nducros Oct 23, 2024
fd32118
minor
nducros Oct 23, 2024
23690a0
rename main folder
nducros Oct 23, 2024
12d1435
update documentation
nducros Nov 7, 2024
246dfd2
spyrit 2.3.3
nducros Nov 29, 2024
044cca2
Tiknonet from spyrit master
nducros Nov 30, 2024
100daf0
compatibility with spyrit 2.3.4
nducros Dec 2, 2024
22779ef
cleanup
nducros Dec 2, 2024
674986d
remove call to utility file
nducros Dec 2, 2024
9bf612f
no utility file
nducros Dec 2, 2024
05c0928
final cleanup
nducros Dec 3, 2024
2bfea15
update installation
nducros Dec 3, 2024
4200d23
underscore test scripts
nducros Dec 4, 2024
3b24a51
check paths, names, dependencies
nducros Dec 4, 2024
21c5352
new gif
nducros Dec 10, 2024
90747cb
update warehous
nducros Dec 10, 2024
9a6e633
update file list
nducros Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Functions for colorization
  • Loading branch information
nducros committed Jan 11, 2024
commit b7a1cc146b2bc1c6535afe76c0016c7c514d5fc1
112 changes: 112 additions & 0 deletions 2023_Optica/misc_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import numpy as np
import warnings
from typing import Tuple

#%%
def wavelength_to_rgb(wavelength: float,
gamma: float = 0.8) -> Tuple[float, float, float]:
"""Converts wavelength to RGB.

Based on https://gist.github.com/friendly/67a7df339aa999e2bcfcfec88311abfc.
Itself based on code by Dan Bruton:
http://www.physics.sfasu.edu/astro/color/spectra.html

Args:
wavelength (float):
Single wavelength to be converted to RGB.
gamma (float, optional):
Gamma correction. Defaults to 0.8.

Returns:
Tuple[float, float, float]:
RGB value.
"""

if np.min(wavelength)< 380 or np.max(wavelength) > 750:
warnings.warn(
'Some wavelengths are not in the visible range [380-750] nm')

if (wavelength >= 380 and wavelength <= 440):
attenuation = 0.3 + 0.7 * (wavelength - 380) / (440 - 380)
R = ((-(wavelength - 440) / (440 - 380)) * attenuation) ** gamma
G = 0.0
B = (1.0 * attenuation) ** gamma

elif (wavelength >= 440 and wavelength <= 490):
R = 0.0
G = ((wavelength - 440) / (490 - 440)) ** gamma
B = 1.0

elif (wavelength >= 490 and wavelength <= 510):
R = 0.0
G = 1.0
B = (-(wavelength - 510) / (510 - 490)) ** gamma

elif (wavelength >= 510 and wavelength <= 580):
R = ((wavelength - 510) / (580 - 510)) ** gamma
G = 1.0
B = 0.0

elif (wavelength >= 580 and wavelength <= 645):
R = 1.0
G = (-(wavelength - 645) / (645 - 580)) ** gamma
B = 0.0

elif (wavelength >= 645 and wavelength <= 750):
attenuation = 0.3 + 0.7 * (750 - wavelength) / (750 - 645)
R = (1.0 * attenuation) ** gamma
G = 0.0
B = 0.0

else:
R = 0.0
G = 0.0
B = 0.0

return R,G,B


def wavelength_to_rgb_mat(wav_range, gamma=1):

rgb_mat = np.zeros((len(wav_range),3))

for i, wav in enumerate(wav_range):
rgb_mat[i,:] = wavelength_to_rgb(wav,gamma)

return rgb_mat


def spectral_colorization(M_gray, wav, axis=None):
"""
Colorize the last dimension of an array

Args:
M_gray (np.ndarray): Grayscale array where the last dimension is the
spectral dimension. This is an A-by-C array, where A can indicate multiple
dimensions (e.g., 4-by-3-by-7) and C is the number of spectral channels.

wav (np.ndarray): Wavelenth. This is a 1D array of size C.

axis (None or int or tuple of ints, optional): Axis or axes along which
the grayscale input is normalized. By default, global normalization
across all axes is considered.

Returns:
M_color (np.ndarray): Color array with an extra dimension. This is an A-by-C-by-3 array.

"""

# Normalize to adjust contrast
M_gray_min = M_gray.min(keepdims=True, axis=axis)
M_gray_max = M_gray.max(keepdims=True, axis=axis)
M_gray = (M_gray - M_gray_min)/(M_gray_max - M_gray_min)

#
rgb_mat = wavelength_to_rgb_mat(wav, gamma=1)
M_red = M_gray @ np.diag(rgb_mat[:,0])
M_green = M_gray @ np.diag(rgb_mat[:,1])
M_blue = M_gray @ np.diag(rgb_mat[:,2])

M_color = np.stack((M_red, M_green, M_blue), axis=-1)

return M_color