1

When I display some samples photos from the dataset I use, the previews of images are displayed in low resolution (they look like very low-resolution photos). How I can I display the images without losing their resolutions?

Here are my transformations which are used to move the data to the tensor and apply some transformations using PyTorch functions:

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])
])

Then I load the data through DataLoader:

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

Finally, I display some previews for the sample photos which are retrieved using the DataLoader object:

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()

p.s. Images are in tiff format.

Shai
  • 111,146
  • 38
  • 238
  • 371
talha06
  • 6,206
  • 21
  • 92
  • 147

1 Answers1

1

What resolution are you expecting?

One of the transformations you are applying is

transforms.Resize((50, 50))

That is, you are reducing the input images resolution to 50 by 50 pixels. This is the resolution you are getting when you plot the images.

In order to have a more graceful display of the low-res images you might want to consider changing the interpolation method of imshow to

plt.imshow(example_data[i][0], cmap='gray', interpolation='bicubic')
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Yes, I am aware of that but I do not want them to lose their quality - as I just resize (downscale) them. They currently look like 'pixel to pixel'. – talha06 Aug 13 '19 at 06:21
  • Thanks but it is very blurry now when I use `bicubic` interpolation as you have suggested. – talha06 Aug 13 '19 at 06:25
  • @talha06 what are you expecting from a 50x50 image? – Shai Aug 13 '19 at 06:28
  • I see where you are coming from but not all 50x50 images are being displayed in that pixel to pixel form. – talha06 Aug 13 '19 at 06:34