From 2ca61608f85667301cac5a62547ae7ab1be2db2c Mon Sep 17 00:00:00 2001 From: wfng92 <43742196+wfng92@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:59:00 +0800 Subject: [PATCH] Correct color channels in upscale using array slicing --- ldm/invoke/restoration/realesrgan.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ldm/invoke/restoration/realesrgan.py b/ldm/invoke/restoration/realesrgan.py index dc3eebd9123..4b83fcbb109 100644 --- a/ldm/invoke/restoration/realesrgan.py +++ b/ldm/invoke/restoration/realesrgan.py @@ -60,14 +60,18 @@ def process(self, image, strength: float, seed: str = None, upsampler_scale: int print( f'>> Real-ESRGAN Upscaling seed:{seed} : scale:{upsampler_scale}x' ) + + # REALSRGAN expects a BGR np array; make array and flip channels + bgr_image_array = np.array(image, dtype=np.uint8)[...,::-1] output, _ = upsampler.enhance( - np.array(image, dtype=np.uint8), + bgr_image_array, outscale=upsampler_scale, alpha_upsampler='realesrgan', ) - res = Image.fromarray(output) + # Flip the channels back to RGB + res = Image.fromarray(output[...,::-1]) if strength < 1.0: # Resize the image to the new image if the sizes have changed