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. 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.

It would be helpful if you could share the complete code you have used to plot the matplotlib figure.

You are most likely taking a RGBA instead of a regular RGB as input into the 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).

If that is the case I would suggest that you try to plot this

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

