pytorch / pytorch/vision

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

Open
#8,911 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the linked RandomAdjustSharpness API documentation and its sharpness_factor parameter description; compare it with the examples and proposed wording in the issue. Done when the docs accurately describe negative, zero, one, and greater-than-one factors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.