C
C#2w ago
Nox

Image Manipulation (Cleaning QR Codes)

Anyone have any bright ideas on how to clean up this image? In particular I need to straighten the jagged edges and restore as much detail as I can. I'm currently using image manipulation. Also taking suggestions for other discords to visit about this.
No description
22 Replies
ero
ero2w ago
my initial idea might be to create some kind of grid over the qr code and taking the pixel (or the average of some range of pixels) at the center of each cell in the grid
Nox
NoxOP2w ago
I don't want to implement my own algorithm for this, because I know it exists somewhere in ImageMagick
Nox
NoxOP2w ago
For instance, this is getting some okay results:
magick.Blur(1, 2);
magick.Threshold((Percentage)50, Channels.Black);

magick.Morphology(new MorphologySettings
{
Iterations = 1,
Kernel = Kernel.Square,
KernelArguments = "1",
Method = MorphologyMethod.Dilate
});

magick.Morphology(new MorphologySettings
{
Iterations = 1,
Kernel = Kernel.Square,
KernelArguments = "1",
Method = MorphologyMethod.Smooth
});
magick.Blur(1, 2);
magick.Threshold((Percentage)50, Channels.Black);

magick.Morphology(new MorphologySettings
{
Iterations = 1,
Kernel = Kernel.Square,
KernelArguments = "1",
Method = MorphologyMethod.Dilate
});

magick.Morphology(new MorphologySettings
{
Iterations = 1,
Kernel = Kernel.Square,
KernelArguments = "1",
Method = MorphologyMethod.Smooth
});
No description
Nox
NoxOP2w ago
But still has work to do.
wasabi
wasabi2w ago
I mean... I hate to be obvious, but is is a QR code. And the first is perfectly readable. So read it and re generate it. :)
Nox
NoxOP2w ago
It is not readable by zxing at least.
wasabi
wasabi2w ago
my google phone gets it
Nox
NoxOP2w ago
So does mine, how can I use their models in C#?
wasabi
wasabi2w ago
Probably would need to figure out what they're doing and just yank it. Lets see.
Nox
NoxOP2w ago
Also tried OpenCV, but no dice. But yeah whatever accuracy is in phone scanners works
wasabi
wasabi2w ago
So they have this MLKit page about barcode models. Looks to be some sort of replacement for their mobile vision API. So maybe it's what they use now. Also the Google code scanner API apparently.
Nox
NoxOP2w ago
Mhm. Proprietary shit, and off-prem.
wasabi
wasabi2w ago
Maaaybe. Oh. Also, xzing works for me. https://zxing-js.github.io/library/examples/qr-camera/ I justpointed my web cam at my discord and it got it
Nox
NoxOP2w ago
Might have something to do with it being further away I can try to reduce the scale it's reading
wasabi
wasabi2w ago
I had to put the camera a bit close to the screen.
Nox
NoxOP2w ago
regardless I don't have that kind of input, just dealing with raw image data
wasabi
wasabi2w ago
Generally, my view, and this is kind of theoritical, is that the optimal algo for cleaning up the image is going to be one specifically tailored to the exact type of image and expectation. And that's going to be a QR reader.
Nox
NoxOP2w ago
I'm totes fine with trying other readers, but their number is few. I tried both zbar and opencv, both didn't work.
wasabi
wasabi2w ago
If there's line detection you can apply to redraw and stuff, it'll be already built into the QR code libraries.
Nox
NoxOP2w ago
Some of them - zxing for instance fails most of these QR codes unless I apply a slight blur
wasabi
wasabi2w ago
Interesting. Might be built around expectations of a camera being involved.
Nox
NoxOP2w ago
I think the problem space changes when all you have is raw images as opposed to some sort of webcam

Did you find this page helpful?