spectral/ColorConvert
1 
2 import cvb
3 import cvb.spectral
4 import numpy as np
5 import os
6 
7 data_root = os.path.join(cvb.install_path(), "tutorial", "Spectral", "Images", "Leaf")
8 
9 object_header = os.path.join(data_root, "leaf.hdr")
10 object_binary = os.path.join(data_root, "leaf.bin")
11 
12 white_ref_header = os.path.join(data_root,"WRef.hdr")
13 white_ref_binary = os.path.join(data_root, "WRef.bin")
14 
15 black_ref_header = os.path.join(data_root, "BRef.hdr")
16 black_ref_binary = os.path.join(data_root, "BRef.bin")
17 
18 print("Load cube from:")
19 print("\t"+ str(object_header))
20 print("\t"+ str(object_binary))
21 print("White Refernce:")
22 print("\t"+ str(white_ref_header))
23 print("\t"+ str(white_ref_binary))
24 print("Black Refernce:")
25 print("\t"+ str(black_ref_header))
26 print("\t"+ str(black_ref_binary))
27 
28 
29 object_cube = cvb.spectral.Cube(object_header, object_binary)
30 white_ref = cvb.spectral.Cube(white_ref_header, white_ref_binary)
31 black_ref = cvb.spectral.Cube(black_ref_header, black_ref_binary)
32 
33 cube_norm = cvb.spectral.normalize(object_cube, white_ref, black_ref, cvb.spectral.NormalizationMethod.AverageReferences1)
34 print("Normalization done!")
35 
36 interpolator = cvb.spectral.Interpolator(cube_norm, cvb.spectral.StdObserver.CIE2006_2deg, cvb.spectral.StdIlluminant.D50, cvb.spectral.InterpolationMethod.Linear)
37 
38 lab_image = cvb.spectral.convert_cube_to_lab(cube_norm, interpolator)
39 print("Lab calculation done!")
40 
41 rgb_image = cvb.spectral.convert_lab_to_rgb8(lab_image, interpolator)
42 print("sRGB calculation done")
43 
44 lab_image.save("LabImage.tiff")
45 rgb_image.save("RGBImage.tiff")
Common Vision Blox Spectral module for Python.
Definition: __init__.py:1
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:747
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:664
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:7153
Spectral Interpolator object.
Definition: __init__.py:291
Spectral Cube object.
Definition: __init__.py:47
cvb.Image convert_cube_to_lab(cvb.spectral.Cube cube, cvb.spectral.Interpolator interpolator)
Converts the cube to a Lab image.
Definition: __init__.py:630