colorization package¶
Subpackages¶
Submodules¶
colorization.acl_model module¶
colorization.acl_resource module¶
colorization.colorize_process module¶
- colorization.colorize_process.inference(model_path, input_image)¶
This function activate the model process after preprocess, and get result back.
- model_path: str
the path of offline model(*.om file)
- input_image: numpy array
resized image with L_channel obtained from preprocess.
- resultnumpy array
ab channels of the preprocessed image.
- colorization.colorize_process.postprocess(image_input_path, inference_result)¶
- This function converts LAB image to BGR image (colorization).
It combines L channel obtained from source image and ab channels from Inference result.
Parameters:
- image_input_pathstr
the path of the (gray) image to obtain L channel
- inference_resultstr
Path to the .npy file containing the output of the inference function. (Consisting of ab channels)
- return valuenumpy array
Colorized image.
- colorization.colorize_process.preprocess(image_file)¶
This function downsizes the input image to modelWidth*modelHeight and extracts L_channel from the image.
input: image_file : numpy array
An image that is loaded from the specified file.
- return valuenumpy array
L channel of the image subtracted by the 50 for mean-centering.
colorization.model_processor module¶
- class colorization.model_processor.ModelProcessor(acl_resource, params)¶
Bases:
object
- __dict__ = mappingproxy({'__module__': 'colorization.model_processor', '__init__': <function ModelProcessor.__init__>, 'predict': <function ModelProcessor.predict>, '__dict__': <attribute '__dict__' of 'ModelProcessor' objects>, '__weakref__': <attribute '__weakref__' of 'ModelProcessor' objects>, '__doc__': None, '__annotations__': {}})¶
- __init__(acl_resource, params)¶
Initialize self. See help(type(self)) for accurate signature.
- __module__ = 'colorization.model_processor'¶
- __weakref__¶
list of weak references to the object (if defined)
- predict(model_input)¶
colorization.pipeline module¶
- colorization.pipeline.colorize_image(image_input_path, image_output_path)¶
This function does the complete processing of a given image. It combines all of the subtasks together:
preprocess the image
colorize the image
postprocess the image
This function is called by the webservice.
- image_input_pathstr
the path of the (gray) image to be processed
- image_output_pathstr
the path of the (colorized) image after processing
- return valueint
on success this function returns 0 on failure this function returns 1
- colorize_image(‘/home/user/xyz/Pictures/pic1.jpg’,
‘/home/user/xyz/Pictures/pic1_colorized.jpg’)
The directories already exists, and the image can be directly written to the given output path.
- colorization.pipeline.colorize_video(video_input_path, video_output_path)¶
This function does the complete processing of a given video. It combines all of the subtasks together:
split video into images
colorize each image
combine images to a video
if the original video has audio, add the audio to colorized video
This function is called by the webservice.
- video_input_pathstr
the path of the (gray) video to be processed
- video_output_pathstr
the path of the (colorized) video after processing
- return valueint
on success this function returns 0 on failure this function returns 1
colorization.tests module¶
- class colorization.tests.FunctionalTest(methodName='runTest')¶
Bases:
unittest.case.TestCase
This class contains tests for the complete pipeline. (i.e. the function pipeline.colorize_image)
- __module__ = 'colorization.tests'¶
- setUp()¶
Hook method for setting up the test fixture before exercising it.
- tearDown()¶
Hook method for deconstructing the test fixture after testing it.
- test_colorize_twice()¶
Functional test to test the colorization of two images in single session
- test_colorize_video()¶
Functional test to test the colorization of two images in single session
- test_complete_colorize_image()¶
Functional test to test the complete colorizing process
- class colorization.tests.PipelineTests(methodName='runTest')¶
Bases:
unittest.case.TestCase
This class contains tests for each part of the pipeline See https://docs.python.org/3/library/unittest.html for more information.
- __module__ = 'colorization.tests'¶
- setUp()¶
Hook method for setting up the test fixture before exercising it.
- tearDown()¶
Hook method for deconstructing the test fixture after testing it.
- test_step_colorize_image()¶
Unit-Test to test the colorizing of an image
- test_step_postprocess_image()¶
Unit-Test to test the postprocessing of an image
- test_step_preprocess_image()¶
Unit-Test to test the preprocessing of an image
- class colorization.tests.SplitAndMergeTestsForVideo(methodName='runTest')¶
Bases:
unittest.case.TestCase
This class contains tests for the split and merge tests of video
- __module__ = 'colorization.tests'¶
- setUp()¶
Hook method for setting up the test fixture before exercising it.
- tearDown()¶
Hook method for deconstructing the test fixture after testing it.
- test_step_merge_audio_and_video()¶
Unit-Test to test the merge_audio_and_video function
- test_step_split_audio_from_video()¶
Unit-Test to test the split_audio_from_video function
- test_step_video2frames_frames2video()¶
Unit-Test to test the video2frames and frames2video function of a video
colorization.videodata module¶
- colorization.videodata.frames2video(image_input_folder_path, video_output_path)¶
This function is used to convert images into a video. Args:
image_input_folder_path: path to the split images. video_output_path: path to the merged video
- Returns:
0 for SUCCESS. 1 for FAILED.
- colorization.videodata.merge_audio_and_video(video_input_path, audio_input_path, video_output_path)¶
This function is used to mge voice with a video merged from images. Args:
video_input_path: path of the origin video audio_input_path: path of the voice file video_output_path: path to the result video
- Returns: int
on success this function returns 0 on failure this function returns 1
- colorization.videodata.split_audio_from_video(video_input_path, audio_output_path)¶
This function is used to extract voice from a video. Args:
video_input_path: path of the origin video audio_output_path: path to the voice file
- Returns: int
on success this function returns 0 on failure this function returns 1
- colorization.videodata.video2frames(video_input_path, image_output_folder_path)¶
This function is used to convert video into images. Args:
video_input_path: filename of the video. image_output_folder_path: Output folder path containing images
- Returns:
1 on fail. 0 on success.