-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import scipy.signal | ||
|
||
gaussian = scipy.signal.windows.gaussian(250, 25) | ||
gaussian = gaussian[25:-25] | ||
qe_wave = np.arange(350, 750)*1e-9 | ||
|
||
qe_red = np.zeros(qe_wave.size) | ||
qe_green = np.zeros(qe_wave.size) | ||
qe_blue = np.zeros(qe_wave.size) | ||
|
||
qe_blue[10:210] = gaussian | ||
qe_green[90:290] = gaussian | ||
qe_red[170:370] = gaussian | ||
|
||
|
||
plt.plot(qe_wave, qe_blue, '#5E81AC') | ||
plt.fill_between(qe_wave, qe_blue, color='#5E81AC', alpha=0.4) | ||
|
||
plt.plot(qe_wave, qe_green, '#A3BE8C') | ||
plt.fill_between(qe_wave, qe_green, color='#A3BE8C', alpha=0.4) | ||
|
||
plt.plot(qe_wave, qe_red, '#BF616A') | ||
plt.fill_between(qe_wave, qe_red, color='#BF616A', alpha=0.4) | ||
|
||
plt.axis('off') | ||
|
||
plt.savefig('bayer.png', dpi=150, bbox_inches='tight') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
.. _examples.bayer: | ||
|
||
************************* | ||
Modeling a Bayer detector | ||
************************* | ||
|
||
.. plot:: | ||
:context: reset | ||
:include-source: | ||
:scale: 50 | ||
|
||
import lentil | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import scipy.signal | ||
|
||
gaussian = scipy.signal.windows.gaussian(250, 25) | ||
gaussian = gaussian[25:-25] | ||
qe_wave = np.arange(350, 750)*1e-9 | ||
|
||
qe_red = np.zeros(qe_wave.size) | ||
qe_green = np.zeros(qe_wave.size) | ||
qe_blue = np.zeros(qe_wave.size) | ||
|
||
qe_blue[10:210] = gaussian | ||
qe_green[90:290] = gaussian | ||
qe_red[170:370] = gaussian | ||
|
||
|
||
plt.plot(qe_wave, qe_blue, 'b', label='Blue') | ||
plt.plot(qe_wave, qe_green, 'g', label='Green') | ||
plt.plot(qe_wave, qe_red, 'r', label='Red') | ||
plt.legend() | ||
plt.title('Quantum Efficiency') | ||
plt.xlabel('Wavelength [nm]') | ||
plt.grid() | ||
|
||
|
||
.. plot:: | ||
:context: close-figs | ||
:include-source: | ||
:scale: 50 | ||
|
||
amp = lentil.circle((256,256), 120) | ||
amp -= lentil.circle(shape=(256,256), radius=40) | ||
for angle in (0, 90, 180, 270): | ||
amp *= lentil.spider((256,256), 2, angle) | ||
opd = lentil.zernike(amp, 4)*1e-6 | ||
|
||
psf = [] | ||
|
||
p = lentil.Pupil(amplitude=amp, opd=opd, focal_length=10, pixelscale=1/240) | ||
|
||
for wave in np.arange(350, 750): | ||
w = lentil.Wavefront(wave*1e-9) | ||
w *= p | ||
w = lentil.propagate_dft(w, pixelscale=5e-6, shape=(64, 64), | ||
oversample=2) | ||
psf.append(w.intensity) | ||
psf = np.asarray(psf) | ||
psf = lentil.rebin(psf, 2) | ||
|
||
psf_flat = np.sum(psf, axis=0) | ||
|
||
fig, ax = plt.subplots(figsize=(2.5,2.5)) | ||
ax.imshow(psf_flat, cmap='inferno') | ||
ax.set_title('Broadband PSF') | ||
plt.axis('off') | ||
|
||
|
||
.. plot:: | ||
:context: close-figs | ||
:include-source: | ||
:scale: 50 | ||
|
||
img = lentil.detector.collect_charge_bayer(psf, qe_wave, qe_red, qe_green, | ||
qe_blue, 'BGGR') | ||
|
||
red_kernel = np.array([[0,0],[0,1]]) | ||
green_kernel = np.array([[0,1],[1,0]]) | ||
blue_kernel = np.array([[1,0],[0,0]]) | ||
|
||
red_mosaic = np.tile(red_kernel, (img.shape[0]//2, img.shape[1]//2)) | ||
green_mosaic = np.tile(green_kernel, (img.shape[0]//2, img.shape[1]//2)) | ||
blue_mosaic = np.tile(blue_kernel, (img.shape[0]//2, img.shape[1]//2)) | ||
|
||
img = img/np.max(img) | ||
|
||
r = red_mosaic * img | ||
g = green_mosaic * img | ||
b = blue_mosaic * img | ||
|
||
fig, ax = plt.subplots(nrows=1, ncols=4, figsize=(7,3)) | ||
|
||
ax[0].imshow(r, cmap='gray') | ||
ax[0].set_title('Red') | ||
ax[0].axis('off') | ||
|
||
ax[1].imshow(g, cmap='gray') | ||
ax[1].set_title('Green') | ||
ax[1].axis('off') | ||
|
||
ax[2].imshow(b, cmap='gray') | ||
ax[2].set_title('Blue') | ||
ax[2].axis('off') | ||
|
||
ax[3].imshow(img, cmap='gray') | ||
ax[3].set_title('Full Bayer image') | ||
ax[3].axis('off') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters