csxmli2016 / MARCONet

Learning Generative Structure Prior for Blind Text Image Super-resolution [CVPR 2023]
Other
185 stars 14 forks source link

crop_DF2K.py不理解 #10

Closed chuan1093 closed 10 months ago

chuan1093 commented 10 months ago

文章中说“The text background is obtained from DIV2K [1] and Flick2K [59] datasets, in which each image is randomly cropped and upsampled to ×4 ∼16 to synthesize the complex background”,代码中实现的似乎与文章不符,代码中的逻辑也不大理解,可以麻烦稍微介绍一下代码逻辑吗~

   for split in SplitNames:
        fis = os.listdir(osp.join(TestImgPath, split))
        for fi in fis:
            KeyLists = os.listdir(osp.join(TestImgPath, split, fi))
            for key in KeyLists:
                ImgLists = os.listdir(osp.join(TestImgPath, split, fi, key))
                for ImgName in ImgLists:
                    ImgPath = osp.join(TestImgPath, split, fi, key, ImgName)
                    A = Image.open(ImgPath).convert('RGB')
                    w,h = A.size
                    print([split,fi,key,ImgName])
                    for ss in ScaleLists: 
                        new_w = w*ss//10
                        new_h = h*ss//10
                        if ss < ScaleLists[0]:
                            A = A.resize((new_w, new_h), Image.LANCZOS)

                        HowmanyEach = min(new_w//CropSize, new_h//CropSize) * 2 * 2
                        for j in range(HowmanyEach):
                            _, Crop, V, M = GetHighPatch(A, CropSize)
                            total = total + 1
                            SaveName = '{}_{}_{}_{}_{:05d}_{:02d}.png'.format(split, fi, key, ImgName[:-4],j,ss)
                            Crop.save(os.path.join(SavePath, SaveName))
csxmli2016 commented 10 months ago

文章中说“The text background is obtained from DIV2K [1] and Flick2K [59] datasets, in which each image is randomly cropped and upsampled to ×4 ∼16 to synthesize the complex background”,代码中实现的似乎与文章不符,代码中的逻辑也不大理解,可以麻烦稍微介绍一下代码逻辑吗~

   for split in SplitNames:
        fis = os.listdir(osp.join(TestImgPath, split))
        for fi in fis:
            KeyLists = os.listdir(osp.join(TestImgPath, split, fi))
            for key in KeyLists:
                ImgLists = os.listdir(osp.join(TestImgPath, split, fi, key))
                for ImgName in ImgLists:
                    ImgPath = osp.join(TestImgPath, split, fi, key, ImgName)
                    A = Image.open(ImgPath).convert('RGB')
                    w,h = A.size
                    print([split,fi,key,ImgName])
                    for ss in ScaleLists: 
                        new_w = w*ss//10
                        new_h = h*ss//10
                        if ss < ScaleLists[0]:
                            A = A.resize((new_w, new_h), Image.LANCZOS)

                        HowmanyEach = min(new_w//CropSize, new_h//CropSize) * 2 * 2
                        for j in range(HowmanyEach):
                            _, Crop, V, M = GetHighPatch(A, CropSize)
                            total = total + 1
                            SaveName = '{}_{}_{}_{}_{:05d}_{:02d}.png'.format(split, fi, key, ImgName[:-4],j,ss)
                            Crop.save(os.path.join(SavePath, SaveName))

crop_DF2K.py 这个文件只是将DF2K图像裁剪成图像块,对应的是‘The text background is obtained from DIV2K [1] and Flick2K [59] datasets, in which each image is randomly cropped’, 后面的’upsampled to ×4 ∼16 to synthesize the complex background‘ 是在读取训练数据时用到的,参考https://github.com/csxmli2016/MARCONet/blob/495858d08bf08d3968515b8db31172fc66e8255f/Train/tspgan/data/text_degradation_dataset.py#L263