question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blury on rotated image.

See original GitHub issue

Here is a comparison between PIL rotation and kornia rotation. It is pretty clear that the image was blurred.

import torch

import kornia.augmentation.functional as F
from torchvision.transforms import functional as tvF
from torchvision.transforms import transforms

import matplotlib.pyplot as plt
import numpy as np

to_tensor = transforms.ToTensor()
to_pil = transforms.ToPILImage()

def tensor_pre_transform_wrapper(input: torch.Tensor):
    """ A wrapper that tried to reproduce the actual output from:
        - transforms.ToPILImage()
        - transforms.ToTensor()
        For each image, simply (img * 255).int() // 255
    """
    return (input * 255).int().float() / 255

in_tensor = torch.rand((3, 23, 44))
in_pil = to_pil(in_tensor)
degrees = 10
out_tensor = F._apply_rotation(
    tensor_pre_transform_wrapper(in_tensor), {'degrees': torch.tensor(degrees)}, False)
out_pil = tvF.rotate(in_pil, angle=degrees)
plt.imshow(np.moveaxis(out_tensor.numpy(), 0, -1))
plt.imshow(np.array(out_pil))
Screenshot 2020-03-21 at 12 57 59 AM

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
edgarribacommented, Mar 20, 2020

Let’s add that flag

0reactions
edgarribacommented, Aug 24, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Rotating my drawings make them pixelated and blurry
Solved: When i ctrl + t and rotate or move something it comes out pixelally and gross. It didnt do this before but...
Read more >
Image is getting blurry after rotating it. : r/GIMP - Reddit
Hi, Im trying to rotate an image, but after rotating it becomes blurry like in the picture below. The picture i try to...
Read more >
Rotation makes the image blurred (#2280) - GIMP - GitLab
When I try to rotate an image, it gets blurred. And the more I apply a rotation, the more it gets blurred. I...
Read more >
CSS Transforms - Why does a simple rotation make the image ...
Looking to rotate an image 90deg, but the resulting image is unacceptably blurry. transform: rotate(90deg); This is the same in both Firefox and...
Read more >
Image blurred after rotation. - Procreate Folio
I noticed the quality of an image is reduced whenever it is rotated, be it it's the original sketches or after duplication of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found