简体   繁体   English

使用 pytorch 展开后图像会变色

[英]Images change color after unfolding using pytorch

I am new to pytorch, for one of my projects I am dividing a large image into smaller tiles/patches.我是 pytorch 的新手,对于我的一个项目,我将大图像划分为较小的图块/补丁。 I am using unfold to make this happen.我正在使用展开来实现这一点。 My code is as follows我的代码如下

data = training_set[1][0].data.unfold(1, 64, 64).unfold(2, 64, 64).unfold(3, 64, 64)

After doing this I transpose the resultant matrix since the images are flipped, like this sample code这样做之后,我转置结果矩阵,因为图像被翻转,就像这个示例代码

torch.t(data [0][0][0][0])

but the resultant images lose color, or get discolored for some reason, and I am worried that this might affect any calculations I do based on these patches.但是生成的图像会失去颜色,或者由于某种原因变色,我担心这可能会影响我基于这些补丁所做的任何计算。

The following is a screenshot of the problem下面是问题的截图在此处输入图像描述

The top is the patch and the bottom one is the complete picture上为贴片,下为全图

Any help is appreciated, thanks任何帮助表示赞赏,谢谢

I think your dataset is probably fine.我认为您的数据集可能很好。

I had a similar issue in the past related to this.过去我也遇到过与此相关的类似问题。 In this situation I have the feeling that the culprit is the matplotlib.imshow() function.在这种情况下,我感觉罪魁祸首是 matplotlib.imshow() function。

It would be helpful if you could share the complete code you have used to plot the matplotlib figure.如果您可以分享您用于 plot matplotlib 图的完整代码,将会很有帮助。

You are most likely taking a RGBA instead of a regular RGB as input into the plt.imshow() function.您很可能将 RGBA 而不是常规 RGB 作为 plt.imshow() function 的输入。 Thus the color are just because you also display an alpha value (A) on top of the regular red green blue (RGB).因此,颜色只是因为您还在常规的红绿蓝 (RGB) 之上显示了一个 alpha 值 (A)。

If that is the case I would suggest that you try to plot this如果是这种情况,我建议您尝试 plot 这个

image = torch.t(data [0][0][0])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM