This article cuts out only the Code part handled in the article serialized in Note. If you are interested in the technical background, please refer to the Note article. This is the final episode of the pre-processing part. Now that we have prepared with Dark shading correction and Image correction process, we will integrate them to complete the Pre-process part.
Define the value to be used as the Global constant first. The purpose is to collect image size and project folder related information in one place for easy management.
parameter.py
class ProjectFolder(Enum):
""" Define project folders
TOP
project top folder
DARK
folder of dark shading
PGM
folder for pgm, the folder should include left and right raw image data
JPG
folder for saving JPEG images
DISPARITY
folder for saving disparity images as a result of depth estimation
"""
TOP = #Project's top-level absolute path
DARK = 'dark/'
PGM = 'pgm/'
JPG = 'jpg/'
DISPARITY = 'disparity/'
class ImageSize(Enum):
""" Define image size
WIDTH
image width
HEIGHT
image height
"""
HEIGHT = 1512
WIDTH = 2016
Everything is ready. Now let's define the Main function.
main.py
import parameters
import dark
import dualpixel
import helper
import matplotlib.pyplot as plt
if __name__ == "__main__":
# path setting
DARK_PATH = parameters.ProjectFolder.TOP.value + parameters.ProjectFolder.DARK.value
PGM_PATH = parameters.ProjectFolder.TOP.value + parameters.ProjectFolder.PGM.value
JPG_PATH = parameters.ProjectFolder.TOP.value + parameters.ProjectFolder.JPG.value
# image size setting
width = int(parameters.ImageSize.WIDTH.value)
height = int(parameters.ImageSize.HEIGHT.value)
# initialize dark image
print('--- Start dark shading correction ---')
dk_sh = dark.Dark(DARK_PATH, 'pgm', dsize=(width, height))
# calculate gain map for dark shading correction
# left_gain_map :use this map to correct left-PD image
# right_gain_map :use this map to correct right-PD image
left_gain_map, right_gain_map = dk_sh.get_gain_map(kernal_size=32, analog_gain=[0.6, 0.6, 0.6], \
left_offset=(0, 150), right_offset=(-80, 150))
# initialize dualpd class
print('--- Start raw data cooking ---')
dualpd = dualpixel.DualPixel(PGM_PATH, 'pgm', dsize=(width, height))
# set left and right gain map
dualpd.set_dksh_gain_map(left_gain_map, left=True)
dualpd.set_dksh_gain_map(right_gain_map, left=False)
# run process
raw_data_file_list, proc_imgs = dualpd.run_process(bi_kernel_size=5, bi_disp=75, \
unsharp_sigma=2, eq_grid_size=2, eq_sigma=32, eq_mean_value=128)
# write images
print('--- Outputing the processed images to folder ---')
helper.write_img_to_path(JPG_PATH, raw_data_file_list, proc_imgs)
print('--- Finished !! ---')
All you have to do is arrange the definitions defined so far in the order of processing.
Recommended Posts