Skip to content

Conversation

@wfng92
Copy link
Contributor

@wfng92 wfng92 commented Oct 20, 2022

Similar to issue #1175, REALSRGAN expects BGR as input instead of RGB. This implementation reused the same numpy array slicing code as #1178.

@psychedelicious
Copy link
Contributor

psychedelicious commented Oct 20, 2022

Oooh, interesting. Did you notice any difference in results?

Edit: I did some testing with 3 random images. The resulting images definitely are different. In some cases, imperceptibly so, but in other cases, noticeable. Still very minor differences, but they are certainly there.

928 different pixels (the result from this PR is noticeably sharper in some areas):
Original implementation:
000435 1090395965 postprocessed
Corrected channels:
000432 1090395965 postprocessed

24 different pixels:
Original implementation:
000436 2061004291 postprocessed
Corrected channels:
000433 2061004291 postprocessed

32 different pixels:
Original implementation:
000437 unknown_seed postprocessed
Corrected channels:
000434 unknown_seed postprocessed

@wfng92
Copy link
Contributor Author

wfng92 commented Oct 20, 2022

Yes, the resulting images are different. Based on the code from official repositories, both GFPGAN and REAL-ESRGAN use cv2.imread to read the file, which decodes the image into a matrix with the color channels stored in the order of Blue, Green, Red and A (depends on the flag used)

# GFPGAN 
input_img = cv2.imread(img_path, cv2.IMREAD_COLOR)

# REAL-ESRGAN
img = cv2.imread(path, cv2.IMREAD_UNCHANGED)

Hence, the expected image input should be BGR instead of RGB.

@lstein
Copy link
Collaborator

lstein commented Oct 20, 2022

Help me out here. This is the third PR that solves the GBR <-> RGB problem. How is this different from #1178?

EDIT: Nevermind. Just realized that this applies to ESRGAN and the previous PRs were for GFPGAN.

Copy link
Collaborator

@lstein lstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lstein lstein merged commit 3e0a7b6 into invoke-ai:development Oct 20, 2022
@wfng92 wfng92 deleted the patch-1 branch October 21, 2022 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants