OpenHSI Simulated Camera Implementation
This module can be imported using from openhsi.cameras import *
Simulated camera implementation for testing and development purposes. The simulated camera can:
Generate hyperspectral data from RGB images using CIE XYZ matching functions
Simulate HgAr calibration lamp spectra
Generate flat field data using blackbody radiation
Provide consistent interface matching hardware cameras
Simulated Camera
The SimulatedCamera provides a software-only implementation that follows the same interface as hardware cameras. It’s useful for:
Testing camera functionality without hardware
Development and debugging
Generating synthetic hyperspectral data
Calibration testing with known spectra
source
SimulatedCameraBase
SimulatedCameraBase (img_path:str=None, mode:str=None)
Core functionality for simulated camera
img_path
str
None
Path to an RGB image file
mode
str
None
Default is to generate lines from the RGB image. Other options are HgAr
and flat
to simulate the HgAr spectrum and a flat field respectively.
source
SimulatedCamera
SimulatedCamera (img_path:str=None, mode:str=None)
Simulated camera using an RGB image as input. Hyperspectral data is produced using CIE XYZ matching functions.
img_path
str
None
Path to an RGB image file
mode
str
None
Default is to generate lines from the RGB image. Other options are HgAr
and flat
to simulate the HgAr spectrum and a flat field respectively.
source
SimulatedCameraBase.mode_change
SimulatedCameraBase.mode_change (mode:str=None)
Switch between simulating HgAr, flat field, or neither.
source
SimulatedCameraBase.rgb2xyz_matching_funcs
SimulatedCameraBase.rgb2xyz_matching_funcs (rgb:numpy.ndarray)
convert an RGB value to a pseudo-spectra with the CIE XYZ matching functions.
with SimulatedCamera(img_path= "../../assets/great_hall_slide.png" ,
n_lines= 1606 ,
processing_lvl = 2 ,
json_path= "../../assets/cam_settings.json" ,
cal_path= "../../assets/cam_calibration.nc" ) as cam:
cam.collect()
fig = cam.show(plot_lib= "bokeh" ,hist_eq= True )
Allocated 754.04 MB of RAM. There was 31658.28 MB available.
100%|██████████████████████████████████████| 1606/1606 [00:08<00:00, 184.10it/s]
fig.opts(width= 400 ,height= 300 ,title= "simulated hyperspectral datacube" )
Each RGB value is converted into a pseudo-spectra by using the CIE XYZ matching functions.
Simulated flat field picture
We will use the Sun’s blackbody radiation for this.
source
SimulatedCameraBase.gen_flat
SimulatedCameraBase.gen_flat ()
simulated blackbody radiation
with SimulatedCamera(mode= "flat" ,
n_lines= 128 ,
processing_lvl = - 1 ,
json_path= "../../assets/cam_settings.json" ,
cal_path= "../../assets/cam_calibration.nc" ,
) as cam:
cam.collect()
fig = cam.show(plot_lib= "bokeh" )
fig.opts(width= 256 ,height= 400 )
Allocated 139.86 MB of RAM. There was 31190.12 MB available.
100%|███████████████████████████████████████| 128/128 [00:00<00:00, 3281.47it/s]
If we look at each simulated picture as it goes into the datacube, it looks like this a blackbody spectrum along the wavelength axis. There are also top and bottom black bars to simulate the rows that would get illuminated in a real camera.
# Create the image plot
img = hv.Image(cam.dc.data[:,0 ,:]).opts(
cmap= 'gray' ,
xlabel= "wavelength index" ,
ylabel= "cross-track" ,
width= 600 ,
height= 400 ,
colorbar= True
)
img
Simulated HgAr lamp pic
For testing wavelength calibration.
source
SimulatedCameraBase.gen_sim_spectra
SimulatedCameraBase.gen_sim_spectra ()
simulated picture of a HgAr lamp
with SimulatedCamera(mode= "HgAr" , n_lines= 128 , processing_lvl = - 1 ,
json_path= "../../assets/cam_settings.json" ,
cal_path= "../../assets/cam_calibration.nc" ,
) as cam:
cam.collect()
Allocated 139.86 MB of RAM. There was 31465.22 MB available.
100%|███████████████████████████████████████| 128/128 [00:00<00:00, 7084.32it/s]
We can see the emission lines in roughly the spot where a real HgAr spectral line should fall. The intensity of each emission line is also roughly simulated.
# Create the image plot
img = hv.Image(cam.dc.data[:,0 ,:]).opts(
cmap= 'gray' ,
xlabel= "wavelength index" ,
ylabel= "cross-track" ,
width= 600 ,
height= 400 ,
colorbar= True
)
img
source
SharedSimulatedCamera
SharedSimulatedCamera (img_path:str=None, mode:str=None)
Core functionality for simulated camera
img_path
str
None
Path to an RGB image file
mode
str
None
Default is to generate lines from the RGB image. Other options are HgAr
and flat
to simulate the HgAr spectrum and a flat field respectively.
Due to requiring double the amount of memory and more to facilitate saving in a separate process, make sure your datacubes can fit in your RAM. Have not tested this but I would suggest choosing n_lines
<= 1/3 the amount used using the regular OpenHSI.