Hi,
First of all appreciate your hard work for building such a fantastic library for image processing. It really impressive stuff!!
Problem:
Need to clean the random images before OCR (Tesseract) to achieve the highest results. Here is what i want to acheive;
1. Reduce the image resolution to 300*300
2. Convert the image to PNG format - did googling and found PNG format works well for B&W images
3. Remove any background noise (if present)
4. Convert the image to black and white
5. Remove any black border (edges) - (if present)
In order to achieve this i have come up with the following script, which i am not sure can be further simplified. The only problem i am stuck at is
1. An input image may have various levels of background noise OR it may not have at all.
2. An input image may or may not have black borders.
So when i pass all these random images through this standard script, i am not getting the consistent output (a clean image). And i found the problem is with the threshold which i have hard coded (STEP 2 & STEP 3) in the following script.
The following script works for images with heavy background noise (will attach an image sample)
STEP 2:--- 25% white-threshhold & fuzz (next line) & converting to b&W on STEP 3
But the same threshhold doesn't work with less background noise images (i have to increase the threshhold values to 60% to get the desired output)
SO IN SUMMARY HOW CAN HAVE A STANDARD SCRIPT TO REMOVE NOISE FROM ANY RANDOM IMAGE
ANY HELP WOULD BE MUCH APPRECIATED...THANKS
WINDOWS BATCH FILE
====================
echo STEP 1. Convert to png
magick input.jpg result.png
echo STEP 2. Remove Background noise
magick result.png -white-threshold 25%% -transparent white result-no-noise-temp.png
magick result-no-noise-temp.png -fuzz 25%% -transparent white result-no-noise.png
echo STEP 3. Convert to Black n White
magick result-no-noise.png -threshold 25%% result-bw.png
echo STEP 4. Crop black border
magick result-bw.png -bordercolor black -border 1 -fuzz 25%% -fill white -draw "color 0,0 floodfill" -alpha off -shave 1x1 final.png
SAMPLE IMAGES
https://www.dropbox.com/s/0f48wr6gpkdue ... e.jpg?dl=0
https://www.dropbox.com/s/gi0d14d8pei0p ... t.png?dl=0
Remove unknown background noise
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove unknown background noise
On some images such as your second example, you can use -lat to clean the background to white.
Code: Select all
convert result_preview.png -negate -lat 25x25+10% -negate result_preview_lat.jpg
Re: Remove unknown background noise
Hi,
Thanks for your help, I tried your command and i do get acceptable results, but the same command doesn't work for first image. My requirement is to have single script which should work for any background noise.
Many Thanks
Thanks for your help, I tried your command and i do get acceptable results, but the same command doesn't work for first image. My requirement is to have single script which should work for any background noise.
Many Thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove unknown background noise
Your two images have different problems. The first has spotty noise. The second is more a a slowly varying background. So there would be different solutions. Or perhaps you can combine the two solutions into one script.
Re: Remove unknown background noise
Hi,
Yes you are right..
I did passed variety of images to the script and its showing great results. Highly appreciated..
Cheers,
Ashik
Yes you are right..
I did passed variety of images to the script and its showing great results. Highly appreciated..
Cheers,
Ashik
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove unknown background noise
Try this on your first image:
or
Code: Select all
convert noise_preview.jpeg -despeckle -despeckle -despeckle -despeckle -despeckle -despeckle -despeckle -despeckle -despeckle -despeckle miff:- | textcleaner -f 25 -o 10 - result.png
Code: Select all
noisecleaner -m 2 -n 10 noise_preview.jpeg tmp.png
textcleaner -f 25 -o 10 tmp.png result.png