XPixelGroup / BasicSR

Open Source Image and Video Restoration Toolbox for Super-resolution, Denoise, Deblurring, etc. Currently, it includes EDSR, RCAN, SRResNet, SRGAN, ESRGAN, EDVR, BasicVSR, SwinIR, ECBSR, etc. Also support StyleGAN2, DFDNet.
https://basicsr.readthedocs.io/en/latest/
Apache License 2.0
6.76k stars 1.19k forks source link

how to read gray image for 1 channel #526

Open DejaVuyan opened 2 years ago

DejaVuyan commented 2 years ago

我的数据集由灰度图像组成,但是我没有找到怎样让图片按照灰度图像读取(读取的图片通道为1),调整config文件中的num_in_ch也只能调整构造的网络输入通道,读取图片的通道仍然为3。

My dataset consists of grayscale images, but I have not found how to make the images read as grayscale images (the image read channel is 1), adjusting num_in_CH in the config file can only adjust the constructed network input channel, the image read channel is still 3.

ElliotQi commented 1 year ago

Solved

zhgqcn commented 10 months ago

Solved

您好,请问如何解决的。

我是直接读取RGB(复制2个通道)然后获取单个通道,即img[:,:,0] 但是在做扩增时会有问题,不清楚为什么源码里面augment采用了cv2.flip(img, 1, img)多了一个参数导致的,我修改了可以。

    def _augment(img):
        if hflip:  # horizontal
            cv2.flip(img, 1, img)
        if vflip:  # vertical
            cv2.flip(img, 0, img)
        if rot90:
            img = img.transpose(1, 0, 2)
        return img
nianliu26 commented 4 months ago

您好,请问如何解决的。

我是直接读取RGB(复制2个通道)然后获取单个通道,即这样img[:,:,0] 做会增加成本时会有问题,鉴于源码里面增加成本cv2.flip(img, 1, img)参数导致的,我修改了可以。

    def _augment(img):
        if hflip:  # horizontal
            cv2.flip(img, 1, img)
        if vflip:  # vertical
            cv2.flip(img, 0, img)
        if rot90:
            img = img.transpose(1, 0, 2)
        return img
  • 我想这个问题,谢谢

basicsr.utils里的imfrombytes函数中,有个参数flag,传入grayscale,即可读入灰度图片,但是读入的图片维度只有二维,即丢失了通道维度,如果你需要通道维度的的话可以使用numpy的维度扩展函数np.expand_dims即可