idealo / image-super-resolution

🔎 Super-scale your images and run experiments with Residual Dense and Adversarial Networks.
https://idealo.github.io/image-super-resolution/
Apache License 2.0
4.55k stars 755 forks source link

Super-resolution by grayscale #158

Open FakerHU2020 opened 3 years ago

FakerHU2020 commented 3 years ago

I want to run Prediction on a grayscale image. Therefore, I tried rewriting as follows. The pixel size of the file used is (512,512) `import numpy as np from PIL import Image from ISR.models import RRDN

img = Image.open('/usr/src/app/image-super-resolution/data/input/gray.png') lr_img = np.array(img) print(np.shape(lr_img))

rrdn = RRDN(weights='gans',c_dim=1) sr_img = rrdn.predict(lr_img) new_img = Image.fromarray(sr_img) print(new_img.mode) new_img.save("/usr/src/app/image-super-resolution/data/superGray.png")` However, the following error occurred. ValueError: Error when checking input: expected LR_input to have 4 dimensions, but got array with shape (1, 512, 512)

Therefore, the following files were also rewritten. Rewritten c_dim = 3 to c_dim = 1 in rrdn.py. Then it changed to the following error. ValueError: Shapes (3, 3, 32, 16) and (48, 32, 3, 3) are incompatible.

How does ESRGAN's Prediction work on grayscale images? I understand, of course, that training is needed for accurate results. Ideally I want to perform super-resolution on a 16-bit Grescale image. I would be grateful if you could give me some hints.

cfrancesco commented 3 years ago

Hi, if you change the number of channel in the model, you cannot load the pre-trained model weights, as they have 3 input channels. There are two way you can go about this: copy you single channels three times (look up how to convert from png to rbg) or change the code and train a new model. In that case, you want to input images that have 1 channel: (batch_size, x, y, channels), so not (1, 512, 512) as you tried, but (1, 512, 512, 1).

Hope this helps.

FakerHU2020 commented 3 years ago

I am very grateful to you. I will try it.

ZouYao0720 commented 1 year ago

hi @FakerHU2020 have you ever successfully trained with grey images?