Skip to content

Setting -5 and 5 to sharpness_factor argument of RandomAdjustSharpness() sharpens and blurs images respectively #8911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hyperkai opened this issue Feb 18, 2025 · 1 comment

Comments

@hyperkai
Copy link

hyperkai commented Feb 18, 2025

πŸ“š The doc issue

The doc of RandomAdjustSharpness() says below:

Adjust the sharpness of the image or video with a given probability.
...
Parameters:

  • sharpness_factor (float) – How much to adjust the sharpness. Can be any non-negative number. 0 gives a blurred image, 1 gives the original image while 2 increases the sharpness by a factor of 2.

But setting -5 and 5 to sharpness_factor argument of RandomAdjustSharpness() sharpens and blurs images respectively as shown below:

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandomAdjustSharpness

sfn5p1_data = OxfordIIITPet( # `sf` is sharpness_factor.
    root="data",             # `n` is negative.
    transform=RandomAdjustSharpness(sharpness_factor=-5, p=1)
)

sf1p1origin_data = OxfordIIITPet(
    root="data",
    transform=RandomAdjustSharpness(sharpness_factor=1, p=1)
)

sf5p1_data = OxfordIIITPet(
    root="data",
    transform=RandomAdjustSharpness(sharpness_factor=5, p=1)
)

import matplotlib.pyplot as plt

def show_images(data, main_title=None):
    plt.figure(figsize=[10, 5])
    plt.suptitle(t=main_title, y=0.8, fontsize=14)
    for i, (im, _) in zip(range(1, 6), data):
        plt.subplot(1, 5, i)
        plt.imshow(X=im)
        plt.xticks(ticks=[])
        plt.yticks(ticks=[])
    plt.tight_layout()
    plt.show()

show_images(data=sfn5p1_data, main_title="sfn5p1_data")
show_images(data=sf1p1origin_data, main_title="sf1p1origin_data")
show_images(data=sf5p1_data, main_title="sf5p1_data")

Image

Image

Image

Suggest a potential alternative/fix

So, the doc of RandomAdjustSharpness() should say something like below:

Sharpen or blur an image or video with a given probability.
...
Parameters:

  • sharpness_factor (float) – How much to adjust the sharpness. Can be any negative or non-negative number. x < 1 gives a blurred image, 1 gives the original image while 1 < x gives a sharpened image.
@NicolasHug
Copy link
Member

fair - happy to consider a PR @hyperkai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants