Noise removal from scanned document for auto crop

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
Jivec
Posts: 2
Joined: 2018-06-03T22:53:05-07:00
Authentication code: 1152

Noise removal from scanned document for auto crop

Post by Jivec »

Thank you in advance for your time

THE PROBLEM

The images are Scanned documents with 300 DPI
The original problem is that i have an image https://imgur.com/a/U4GLbDK

and as you can see i have a bit of noise at random spots outside of the area of interest. I tried many ways to clean the noise and after some searching i found out about the `connectedComponents ` method.

I'm trying to follow this well documented topic but i don't know how i can implement it since connectedComponents seems to not working like i thought.

A BIT OF WHAT TRIED

I also tried to create a mask of the image above but i'm not so sure if i'm applying it the correct way, because it doesn't seem to work. https://imgur.com/a/V3PuK1G

Code: Select all

mgImgModified.Composite(origImg, CompositeOperator.CopyAlpha);
and i also tried this.

Code: Select all

origImg.ReadMask = mgImgModified;
The last one seems to have an effect on the image but not the desired one.

END GOAL

My end goal is to dynamically clean the noise around the area of interest in order to be able to auto crop the image, to only the part i want in every instance.


Thank you:)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Noise removal from scanned document for auto crop

Post by fmw42 »

Are the red line part of the actual image or added for show? If not, then please provide the original. What is the area of interest for this image?

Please always provide your ImageMagick version and platform!
Jivec
Posts: 2
Joined: 2018-06-03T22:53:05-07:00
Authentication code: 1152

Re: Noise removal from scanned document for auto crop

Post by Jivec »

No its not part of the original image added them to show the region i want to trim but there is noise and trim dosnt work ,the original image is this https://imgur.com/a/6tNQJAZ , the area of interest is the document.

I'm using 7.4.6 Magick.Net Q16.

Trying to auto crop/trim ,the documents are not only in this color i want to dynamically remove noise from the white areas in order for trim to work
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Noise removal from scanned document for auto crop

Post by fmw42 »

In command line mode, you can do it as follows:

Code: Select all

magick form.jpg -morphology close octagon:9 -fuzz 10% -format "%@" info:
1736x2698+30+355

Code: Select all

magick form.jpg -crop 1736x2698+30+355 +repage form_crop.png
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Noise removal from scanned document for auto crop

Post by dlemstra »

Thanks for helping out Fred. There are some more files that jivec wants to convert in this issue: https://github.com/dlemstra/Magick.NET/issues/234 and they don't work with your suggested method.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply