Linfeng-Tang / SwinFusion

This is official Pytorch implementation of "SwinFusion: Cross-domain Long-range Learning for General Image Fusion via Swin Transformer"
161 stars 20 forks source link

MFF多焦点融合目前好像只支持单通道? #16

Open Xinzhe99 opened 1 year ago

Xinzhe99 commented 1 year ago

image 将in_channels改为3 报错: Traceback (most recent call last): File "test_swinfusion.py", line 153, in main() File "test_swinfusion.py", line 50, in main model = define_model(args) File "test_swinfusion.py", line 94, in define_model model.load_state_dict(pretrained_model[param_key_g] if param_key_g in pretrained_model.keys() else pretrained_model, strict=True) File "D:\anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1604, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( size mismatch for conv_last3.weight: copying a param with shape torch.Size([1, 15, 3, 3]) from checkpoint, the shape in current model is torch.Size([3, 15, 3, 3]). size mismatch for conv_last3.bias: copying a param with shape torch.Size([1]) from checkpoint, the shape in current model is torch.Size([3]). 好像是预训练权重在训练时只用了单通道?

Xinzhe99 commented 1 year ago

好想知道原因了,这里输出的结果是Y通道的~

Xinzhe99 commented 1 year ago

应该需要再把融合的Y通道与CbCr通道转换回RGB色彩空间 可以参考https://blog.csdn.net/fovever_/article/details/124625687

Xinzhe99 commented 1 year ago

image 合成后是这样的

Linfeng-Tang commented 1 year ago

是的 论文里也有提到 是将RGB转换到Y通道进行融合的。

Xinzhe99 commented 1 year ago

是的 论文里也有提到 是将RGB转换到Y通道进行融合的。

没错!是阅读时候疏忽了这部分!感谢答复~

Cassiel8196 commented 6 months ago

是的 论文里也有提到 是将RGB转换到Y通道进行融合的。

我按照您论文所写,VI先通过opencv官方库转换为YCBCR格式,然后输入改为VI_Y,输出是将output代替ycbcr中的y通道,再转换为rgb格式,但是结果不理想,原本红色的部分,在输出图里显示蓝色,本人一直没找到解决办法,特此询问作者 ![Uploading rgb_output.png…]()

Linfeng-Tang commented 6 months ago

CV2使用的数据格式是BGR而常规使用的应该是RGB格式 请检查是否是这个问题导致的呢

Cassiel8196 commented 6 months ago

感谢您的回复!我昨晚留言后解决了该问题,怎奈梯子崩了,没能及时反馈,劳烦您发邮件。

---- 回复的原邮件 ---- | 发件人 | Linfeng @.> | | 日期 | 2023年12月20日 11:06 | | 收件人 | @.> | | 抄送至 | BNing @.>@.> | | 主题 | Re: [Linfeng-Tang/SwinFusion] MFF多焦点融合目前好像只支持单通道? (Issue #16) |

CV2使用的数据格式是BGR而常规使用的应该是RGB格式 请检查是否是这个问题导致的呢

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

LJK-WEB commented 5 months ago

可以发下代码是怎么改的吗

Cassiel8196 commented 5 months ago

加一个函数把灰度图改彩色就行了 `def trans(): A_dir = './Dataset/testsets/MSRS/VI_Y' #包含所有源图像A的文件夹路径 Fused_dir = './results/SwinFusion_MSRS' # 融合图像的Y通道的文件夹路径 save_dir = './results/rgb' #彩色融合图像的文件夹路径

for file_A,file_F in zip(os.listdir(A_dir),os.listdir(Fused_dir)):
    filename_A = os.path.join(A_dir +'/'+ file_A)
    filename_F = os.path.join(Fused_dir +'/'+ file_F)
    save_path = os.path.join(save_dir + '/'+file_A)
    I_result = cv2.imread(filename_F,0)   # 融合后的灰度图
    img_rgb = cv2.imread(filename_A,1)
    img_ycrcb = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2YCrCb)
    (y, cr1, cb1) = cv2.split(img_ycrcb)
    ycrcb_fi = np.dstack((I_result, cr1, cb1))
    rgb_fi = cv2.cvtColor(ycrcb_fi, cv2.COLOR_YCrCb2BGR)
    cv2.imwrite(save_path, rgb_fi)`