【问题标题】:Matplotlib Pylot - Images are being displayed in low resolution (pixel to pixel)Matplotlib Pylot - 图像以低分辨率显示(像素到像素)
【发布时间】:2019-12-19 16:14:27
【问题描述】:

当我显示我使用的数据集中的一些示例照片时,图像的预览以低分辨率显示(它们看起来像非常低分辨率的照片)。如何在不丢失分辨率的情况下显示图像?

这是我的transformations,用于将数据移动到张量并使用PyTorch 函数应用一些转换:

data_transforms = transforms.Compose([
    transforms.Resize((50, 50)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406],
                         std=[0.229, 0.224, 0.225])
])

然后我通过DataLoader加载数据:

train_loader = DataLoader(face_train_dataset,
                          batch_size=train_batch_size, shuffle=False,
                          num_workers=4)

最后,我展示了一些使用DataLoader 对象检索的示例照片的预览:

example_data = example_data.cpu()
example_targets = example_targets.cpu()
for i in range(6):
    plt.subplot(2, 3, i + 1)
    plt.tight_layout()
    plt.imshow(example_data[i][0], cmap='gray', interpolation='none')
    plt.title('{}'.format(folders[example_targets[i]]))

plt.show()

附言图片采用tiff 格式。

【问题讨论】:

    标签: matplotlib computer-vision pytorch torchvision dataloader


    【解决方案1】:

    您期望什么分辨率?

    您正在应用的转换之一是

    transforms.Resize((50, 50))
    

    也就是说,您将输入图像的分辨率降低到 50 x 50 像素。这是您绘制图像时获得的分辨率。

    为了更优雅地显示低分辨率图像,您可能需要考虑将interpolation method 的imshow 更改为

    plt.imshow(example_data[i][0], cmap='gray', interpolation='bicubic')
    

    【讨论】:

    • 是的,我知道这一点,但我不希望它们失去质量 - 因为我只是调整(缩小)它们的大小。它们目前看起来像“像素到像素”。
    • 谢谢,但是当我按照您的建议使用 bicubic 插值时,现在它非常模糊。
    • @talha06 你对 50x50 的图片有什么期望?
    • 我知道您来自哪里,但并非所有 50x50 图像都以像素到像素的形式显示。
    猜你喜欢
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多