10.03.2024, 19:37
Hello Selur,
I completed the writing of new version. The changes are so many that I decided to bump the version to 2.0 (not yet on github).
I attached the source of the new version, so that you can start to look at parameters.
The full list of parameters is shortly described in the file __init__.py
As decided dd_method is now used to switch on/off Deodify or DDColor.
I added 3 merging methods
2) Simple Merge: already implemented in the previous versions
3) Adaptive Luma Merge: I noted that DDColor is sensible to luma, in dark scenes the quality of colored images is poor. This method will reduce the weight applied to DDColor when the luma is low, till a minimum weight defined by the parameter min_weight.
4) Constrained Chroma Merge: This method try to solve the problem by not allowing the DDColor estimated chroma values to be too much different from the chroma values estimated by Deoldify, the constrain is defined by the parameter luma_threshold.
Finally I added the possibility to change the brightness, the contrast and the gamma of original B&W image before is provide in input to DDColor. This kind of tweak has been developed for helping DDColor estimates. Since usually changing these parameters can damage significantly the final quality, after the estimation are propagated back only the chroma values, while luma will be the original one of the B&W image. In this way will be improved the chroma without destroying the luma.
I added also a constrained tweak, controlled by dd_tweak_luma_bind. The behavior is similar to the unconstrained tweak, but in this case the bright will be increased only on the images having average luma below luma_min, also gamma will be applied only in the case the average luma will be below gamma_luma_min.
The results are quite interesting.
For example the B&W image of frame 899 of clip provided in my previous post is the following:
The image colored with Deoldify (default settings) is the following:
The colored image, is quite good, but the estimate provided by DDColor (default settings) is the following:
which is quite bad. But applying the tweak: bright=0.2, gamma=3, the image becomes:
which is quite good.
In the following picture are shown some examples of results obtained by applying other methods.
There is still a lot to experiment, but with this version I think to have included all the more interesting tools.
The source code should help in understanding better the meaning of some option, but please don't hesitate to contact me for any doubt.
Thanks,
Dan
Here the source code
I completed the writing of new version. The changes are so many that I decided to bump the version to 2.0 (not yet on github).
I attached the source of the new version, so that you can start to look at parameters.
The full list of parameters is shortly described in the file __init__.py
def ddeoldify(
clip: vs.VideoNode, model: int = 0, render_factor: int = 24, sat: list = [1.0,1.0], hue: list = [0.0,0.0],
dd_model: int = 1, dd_render_factor: int = 24, dd_tweak_luma_bind: list = [False, 0.0, 0.0], dd_bright: float = 0, dd_cont: float = 1, dd_gamma: float = 1.0,
dd_method: int = 2, dd_method_params: list = [0.5, 1.2, 0.15, 0.1], device_index: int = 0, n_threads: int = 8, dd_num_streams: int = 1,
torch_hub_dir: str = model_dir
) -> vs.VideoNode:
"""A Deep Learning based project for colorizing and restoring old images and video
:param clip: clip to process, only RGB24 format is supported.
:param model: deoldify model to use (default = 0):
0 = ColorizeVideo_gen
1 = ColorizeStable_gen
2 = ColorizeArtistic_gen
:param render_factor: render factor for the model, range: 10-40 (default = 24).
:param sat: list with the saturation parameters to apply to color models (default = [1,1])
:param hue: list with the hue parameters to apply to color models (default = [0,0])
:param dd_model: ddcolor model (default = 0):
0 = ddcolor_modelscope,
1 = ddcolor_artistic
:param dd_render_factor: ddcolor input size equivalent to render_factor, if = 0 will be auto selected
(default = 24) [range: 0-64]
dd_tweak_luma_bind parameters for luma constrained ddcolor preprocess
[0] : luma constrained ddcolor preprocess enabled (default = False)
[1] : luma min value for tweak activation (default = 0, non activation)
[2] : luma min value for gamma tweak activation (default = 0, non activation)
:param dd_tweak_bright ddcolor tweak's bright (default = 0)
:param dd_tweak_cont ddcolor tweak's constrast (default = 1)
:param dd_tweak_gamma ddcolor tweak's gamma (default = 1)
:param dd_method: method used to combine deoldify with ddcolor (default = 0):
0 : deoldify olny (no merge)
1 : ddcolor only (no merge)
2 : Simple Merge
3 : Adaptive Luma Merge
4 : Constrained Chroma Merge
:param dd_method_params: list with the parameters to apply to selected dd_method:
[0] : clipb_weight, used by: SimpleMerge, AdaptiveLumaMerge, ConstrainedChromaMerge
[1] : scale_factor, used by: AdaptiveLumaMerge
[2] : min_weight, used by: AdaptiveLumaMerge
[3] : luma_threshold, used by: ConstrainedChromaMerge
:param device_index: device ordinal of the GPU, choices: GPU0...GPU7, CPU=99 (default = 0)
:param n_threads: number of threads used by numpy, range: 1-32 (default = 8)
:param dd_num_streams: number of CUDA streams to enqueue the kernels (default = 1)
:param torch_hub_dir: torch hub dir location, default is model directory,
if set to None will switch to torch cache dir.
"""
As decided dd_method is now used to switch on/off Deodify or DDColor.
I added 3 merging methods
2) Simple Merge: already implemented in the previous versions
3) Adaptive Luma Merge: I noted that DDColor is sensible to luma, in dark scenes the quality of colored images is poor. This method will reduce the weight applied to DDColor when the luma is low, till a minimum weight defined by the parameter min_weight.
4) Constrained Chroma Merge: This method try to solve the problem by not allowing the DDColor estimated chroma values to be too much different from the chroma values estimated by Deoldify, the constrain is defined by the parameter luma_threshold.
Finally I added the possibility to change the brightness, the contrast and the gamma of original B&W image before is provide in input to DDColor. This kind of tweak has been developed for helping DDColor estimates. Since usually changing these parameters can damage significantly the final quality, after the estimation are propagated back only the chroma values, while luma will be the original one of the B&W image. In this way will be improved the chroma without destroying the luma.
I added also a constrained tweak, controlled by dd_tweak_luma_bind. The behavior is similar to the unconstrained tweak, but in this case the bright will be increased only on the images having average luma below luma_min, also gamma will be applied only in the case the average luma will be below gamma_luma_min.
The results are quite interesting.
For example the B&W image of frame 899 of clip provided in my previous post is the following:
The image colored with Deoldify (default settings) is the following:
The colored image, is quite good, but the estimate provided by DDColor (default settings) is the following:
which is quite bad. But applying the tweak: bright=0.2, gamma=3, the image becomes:
which is quite good.
In the following picture are shown some examples of results obtained by applying other methods.
There is still a lot to experiment, but with this version I think to have included all the more interesting tools.
The source code should help in understanding better the meaning of some option, but please don't hesitate to contact me for any doubt.
Thanks,
Dan
Here the source code