From 8f49cdd14481484d4b625debb9e13148df78a47f Mon Sep 17 00:00:00 2001 From: Sebastian Olter Date: Sun, 30 Jun 2024 15:44:53 +0200 Subject: [PATCH] fixed mono models code indentation --- QualityScaler.py | 100 +++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/QualityScaler.py b/QualityScaler.py index 3d2d7fd..99d2b96 100644 --- a/QualityScaler.py +++ b/QualityScaler.py @@ -299,21 +299,21 @@ def AI_upscale( output_image[:,:,2] = numpy.clip(output_imageYCbCr[:,:,0] + 1.772 * (output_imageYCbCr[:,:,1] - 0.5), 0, 1) else: - imageR = image[:, :, 0] - imageR = numpy_expand_dims(imageR, axis=2) - imageR = preprocess_image(imageR) - output_image = process_image_with_AI_model(AI_model, imageR) - output_image = numpy.repeat(output_image, 3, 2) - - imageG = image[:, :, 1] - imageG = numpy_expand_dims(imageG, axis=2) - imageG = preprocess_image(imageG) - output_image[:,:,1] = process_image_with_AI_model(AI_model, imageG).squeeze() - - imageB = image[:, :, 2] - imageB = numpy_expand_dims(imageB, axis=2) - imageB = preprocess_image(imageB) - output_image[:,:,2] = process_image_with_AI_model(AI_model, imageB).squeeze() + imageR = image[:, :, 0] + imageR = numpy_expand_dims(imageR, axis=2) + imageR = preprocess_image(imageR) + output_image = process_image_with_AI_model(AI_model, imageR) + output_image = numpy.repeat(output_image, 3, 2) + + imageG = image[:, :, 1] + imageG = numpy_expand_dims(imageG, axis=2) + imageG = preprocess_image(imageG) + output_image[:,:,1] = process_image_with_AI_model(AI_model, imageG).squeeze() + + imageB = image[:, :, 2] + imageB = numpy_expand_dims(imageB, axis=2) + imageB = preprocess_image(imageB) + output_image[:,:,2] = process_image_with_AI_model(AI_model, imageB).squeeze() return postprocess_output(output_image, range) @@ -348,41 +348,41 @@ def AI_upscale( output_image = output_image.squeeze() return postprocess_output(output_image, range) else: - match image_mode: - case "RGB": - image = preprocess_image(image) - output_image = process_image_with_AI_model(AI_model, image) - return postprocess_output(output_image, range) - - case "RGBA": - alpha = image[:, :, 3] - image = image[:, :, :3] - image = opencv_cvtColor(image, COLOR_BGR2RGB) - alpha = opencv_cvtColor(alpha, COLOR_GRAY2RGB) - - image = image.astype(float32) - alpha = alpha.astype(float32) - - # Image - image = preprocess_image(image) - output_image = process_image_with_AI_model(AI_model, image) - output_image = opencv_cvtColor(output_image, COLOR_RGB2BGRA) - - # Alpha - alpha = preprocess_image(alpha) - output_alpha = process_image_with_AI_model(AI_model, alpha) - output_alpha = opencv_cvtColor(output_alpha, COLOR_RGB2GRAY) - - # Fusion Image + Alpha - output_image[:, :, 3] = output_alpha - return postprocess_output(output_image, range) - - case "Grayscale": - image = opencv_cvtColor(image, COLOR_GRAY2RGB) - image = preprocess_image(image) - output_image = process_image_with_AI_model(AI_model, image) - output_image = opencv_cvtColor(output_image, COLOR_RGB2GRAY) - return postprocess_output(output_image, range) + match image_mode: + case "RGB": + image = preprocess_image(image) + output_image = process_image_with_AI_model(AI_model, image) + return postprocess_output(output_image, range) + + case "RGBA": + alpha = image[:, :, 3] + image = image[:, :, :3] + image = opencv_cvtColor(image, COLOR_BGR2RGB) + alpha = opencv_cvtColor(alpha, COLOR_GRAY2RGB) + + image = image.astype(float32) + alpha = alpha.astype(float32) + + # Image + image = preprocess_image(image) + output_image = process_image_with_AI_model(AI_model, image) + output_image = opencv_cvtColor(output_image, COLOR_RGB2BGRA) + + # Alpha + alpha = preprocess_image(alpha) + output_alpha = process_image_with_AI_model(AI_model, alpha) + output_alpha = opencv_cvtColor(output_alpha, COLOR_RGB2GRAY) + + # Fusion Image + Alpha + output_image[:, :, 3] = output_alpha + return postprocess_output(output_image, range) + + case "Grayscale": + image = opencv_cvtColor(image, COLOR_GRAY2RGB) + image = preprocess_image(image) + output_image = process_image_with_AI_model(AI_model, image) + output_image = opencv_cvtColor(output_image, COLOR_RGB2GRAY) + return postprocess_output(output_image, range) def get_image_mode(image: numpy_ndarray) -> str: match image.shape: