CVBpy 15.0
All Classes Namespaces Functions Variables Enumerations Enumerator Properties Modules Pages
spectral/ColorConvert
1# @brief Example for normalizing and calculating Lab and sRGB images on
2# **hyperspectral cubes**.
3
4import cvb
5import cvb.spectral
6import numpy as np
7import os
8
9data_root = os.path.join(cvb.install_path(), "tutorial", "Spectral", "Images", "Color")
10
11object_header = os.path.join(data_root, "ColorCube.hdr")
12object_binary = os.path.join(data_root, "ColorCube.bin")
13
14white_ref_header = os.path.join(data_root,"WhiteCube.hdr")
15white_ref_binary = os.path.join(data_root, "WhiteCube.bin")
16
17black_ref_header = os.path.join(data_root, "DarkCube.hdr")
18black_ref_binary = os.path.join(data_root, "DarkCube.bin")
19
20print("Load cube from:")
21print("\t"+ str(object_header))
22print("\t"+ str(object_binary))
23print("White Refernce:")
24print("\t"+ str(white_ref_header))
25print("\t"+ str(white_ref_binary))
26print("Black Refernce:")
27print("\t"+ str(black_ref_header))
28print("\t"+ str(black_ref_binary))
29
30
31object_cube = cvb.spectral.Cube(object_header, object_binary)
32white_ref = cvb.spectral.Cube(white_ref_header, white_ref_binary)
33black_ref = cvb.spectral.Cube(black_ref_header, black_ref_binary)
34
35cube_norm = cvb.spectral.normalize(object_cube, white_ref, black_ref, cvb.spectral.NormalizationMethod.AverageReferences1)
36print("Normalization done!")
37
38interpolator = cvb.spectral.Interpolator(cube_norm, cvb.spectral.StdObserver.CIE2006_2deg, cvb.spectral.StdIlluminant.D50, cvb.spectral.InterpolationMethod.Linear)
39
40lab_image = cvb.spectral.convert_cube_to_lab(cube_norm, interpolator)
41print("Lab calculation done!")
42
43rgb_image = cvb.spectral.convert_lab_to_rgb8(lab_image, interpolator)
44print("sRGB calculation done")
45
46lab_image.save("LabImage.tiff")
47rgb_image.save("RGBImage.tiff")
Spectral Cube object.
Definition: __init__.py:47
Spectral Interpolator object.
Definition: __init__.py:286
Common Vision Blox Spectral module for Python.
Definition: __init__.py:1
cvb.Image convert_lab_to_rgb8(cvb.Image lab_image, cvb.spectral.Interpolator interpolator)
Converts a Lab image to a sRGB 8bit image.
Definition: __init__.py:666
cvb.spectral.Cube normalize(cvb.spectral.Cube cube, cvb.spectral.Cube white_reference, cvb.spectral.Cube black_reference, int normalization_method)
This function creates a normalized cube using the white- and black-reference and the object cube.
Definition: __init__.py:750
cvb.Image convert_cube_to_lab(cvb.spectral.Cube cube, cvb.spectral.Interpolator interpolator)
Converts a normalized cube to a Lab image.
Definition: __init__.py:632
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8318