Skip to content
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

[Image Resizer] Resized image is blurry #10675

Open
Pingumania opened this issue Apr 9, 2021 · 6 comments
Open

[Image Resizer] Resized image is blurry #10675

Pingumania opened this issue Apr 9, 2021 · 6 comments
Assignees
Labels
Cost-Medium Medium work item - 1-3 Days worth of work. Planning-Consideration Consideration for 2021 stability release Priority-2 Bug that is medium priority Product-Image Resizer Things regarding image resizing module Status-In progress This issue or work-item is under development Status-Reproducible This issue was reproduced by a maintainer

Comments

@Pingumania
Copy link

Pingumania commented Apr 9, 2021

Microsoft PowerToys version

0.35.0

Running as admin

No

Area(s) with issue?

Image Resizer

Steps to reproduce

I took a random screenshot and resized it with Image Resizer and Paint to have a width of 600.
I used 95 jpeg quality and "fit 600x600 pixel".
The measurements of the orignal screenshot are 1213x750.
The measurements of the Paint image are 600x370.
The measurements of the Image Resizer one are 600x371.

Here are the images
Original

Image Resizer

Paint

✔️ Expected Behavior

The Image Resizer picutre shouldn't be blurry.

❌ Actual Behavior

The picture from the Image Resizer is blurry compared the one from Paint.

Other Software

No response

@Pingumania Pingumania added Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Apr 9, 2021
@crutkas
Copy link
Member

crutkas commented Apr 9, 2021

Notes:

  • if image was PNG, this works as expected and clear text is outputted.
  • Able to repro with JPG via paint

@crutkas crutkas added Priority-2 Bug that is medium priority Product-Image Resizer Things regarding image resizing module Planning-Consideration Consideration for 2021 stability release Cost-Medium Medium work item - 1-3 Days worth of work. and removed Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Apr 9, 2021
@crutkas
Copy link
Member

crutkas commented Apr 9, 2021

doing the tweak i think is easy, doing the testing here is where most of the time will be spent.

need to validate

  • small to big picture
  • small to big text
  • big to small picture
  • big to small text

validate we didn't break other formats

@Jay-o-Way
Copy link
Collaborator

What kind of algorithm does Image Resizer use? Is it always the same or can we use different for enlargement versus smaller?

@Kissaki
Copy link
Contributor

Kissaki commented Apr 21, 2024

To add a data point with more details - anime screenshot:

  • Original: 1080p, 346 kB
  • Resized: 480p, 104 kB
  • GIMP-Resized: 480p, 107 kB

Even with the same quality settings (confirmed with Irfanview on the exported images) JPEG, quality: 90, subsampling ON (2x2)
the GIMP-resized file looks significantly better, significantly less blurred.

Alternating the scaling interpolation in GIMP in all cases (None, Linear, Cubic interpolation) looks better. (Linear looks worse than Cubic, but still better than Image Resizer. None has no blur.)

@Jay-o-Way Jay-o-Way added the Status-Reproducible This issue was reproduced by a maintainer label Apr 21, 2024
@Kissaki
Copy link
Contributor

Kissaki commented Apr 21, 2024

Project ImageResizerUI, ResizeOperation.Transform creates a System.Windows.Media.Imaging.TransformedBitmap with a ScaleTransform argument.

From what I can see, the blurring issue limitation is a given from that standard lib. I don't see any parameters beyond the scale factors/transformation matrix.

reference docs

Kissaki added a commit to Kissaki/PowerToys that referenced this issue May 9, 2024
Fixes microsoft#10675

In some cases a resized image becomes very blurry.

Loading the input image file into cache in BitmapDecoder resolves the blurriness.

---

I tried to find the technical reason why caching resolves it, or why it is blurry in the first place, but was unable to locate it.

The issue seems to occur only on specific images. I was not able to identify a strong parameter that would cause it.

Nevertheless, with the images I will attach to the PR, I hope to make an evident case for the factual resolution of the issue. And maybe or hopefully someone with more knowledge about the respective used APIs will be able to provide the factual, technical reason for it.

---

`ResizeOperation` uses `BitmapDecoder` to load the image file. In main the decoder is instantiated with `BitmapCacheOption.None`. Changing it to `BitmapCacheOption.OnLoad` resolves the issue.

The pass-along of image data is as follows:

1. create decoder
2. decoder -> image file metadata
3. decoder -> `BitmapFrame` -> `TransformedBitmap` -> `BitmapFrame` -> encoder (`Frames.Add()`) -> `encoder.Save()`

---

[transformdoc] mentions the following about loaded cached image data potentially mismatching target pixel size, which made me wonder whether the no-cache delayed reading in combination with the transformation leads to reduced-size-reading. I was not able to confirm it. Given that most images I tested did not have a problem, I don't think it's a plausible cause.

> If you don't do this, the application will cache the image as though it were rendered as its normal size rather than just the size that is displayed.

[transformdoc]: https://learn.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/how-to-apply-a-transform-to-a-bitmapimage

---

For multiple test images, any differences were hard to spot, they did not result in blurriness. The image I had issues with in the past being very colorful made me wonder whether amount of color information could make the difference. But with the technical context, that would only make sense if the encoder caching somehow handled color information differently, which seems unlikely too.
@microsoft-github-policy-service microsoft-github-policy-service bot added the Status-In progress This issue or work-item is under development label May 9, 2024
@Kissaki
Copy link
Contributor

Kissaki commented May 9, 2024

I would appreciate feedback in draft PR #32797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cost-Medium Medium work item - 1-3 Days worth of work. Planning-Consideration Consideration for 2021 stability release Priority-2 Bug that is medium priority Product-Image Resizer Things regarding image resizing module Status-In progress This issue or work-item is under development Status-Reproducible This issue was reproduced by a maintainer
Projects
Status: No status
Development

No branches or pull requests

4 participants