Downscaling issue with QR codes #1780
-
I'm working on a generic downscaling process for user image uploads, using this setup (this is from a POC project): originalImage.Mutate(x => x
.BackgroundColor(new Rgba32(0, 0, 0, 0))
.Resize(new ResizeOptions()
{
Size = new Size(200, 200),
Mode = SixLabors.ImageSharp.Processing.ResizeMode.Max,
Sampler = KnownResamplers.Lanczos5,
Compand = true,
})
.GaussianSharpen(0.3f));
var processedStream = new MemoryStream();
originalImage.Save(processedStream, new PngEncoder()
{
CompressionLevel = PngCompressionLevel.BestCompression,
TransparentColorMode = PngTransparentColorMode.Clear,
}); I get good results with this for most images, including images that are just text. The only image I'm having a problem with is a QR code. Here's the before and after: The original has a white background padding around the QR code. In the processed version you can actually see the padding because the transformation changed the color to a light gray. The processed version's edges are "fuzzy" and the resulting file size is twice as big as the original. Using the NearestNeighbor resampler gives a much, much better result: .. but every other image is worse. Is there a setting I'm missing to make Lanczos5 work well with QR codes (and other images like them)? I've tried a few images that are just text (both blocky and thin) and the process above with Lanczos5 looks really good. If not, is there any recommendation on how to move forward with this? I've thought of a couple ideas:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@natehitze not an expert on resamplers, but the questions I would ask at this point:
I'm afraid picking the resampler based on the image contents is already a Machine Learning area, and leads very far. |
Beta Was this translation helpful? Give feedback.
@natehitze not an expert on resamplers, but the questions I would ask at this point:
I'm afraid picking the resampler based on the image contents is already a Machine Learning area, and leads very far.