Page 1 of 1

Attempting to remove poor quality barcode

Posted: 2017-12-01T14:47:50-07:00
by depthless
I'm currently using Imagemagick to very successfully deskew images. It'd be AMAZING if i could get it to also remove the barcodes fom my images. Below is an example of what the image would look like. In a REALLY ideal world we'd somehow erase everything except the numbers :).

I can't use coordinates as these end up all over the place thanks to being fed by ADF.

Image

Tried a few forum posts based around removing vertical lines, but had no luck.

Re: Attempting to remove poor quality barcode

Posted: 2017-12-01T15:17:50-07:00
by snibgo
The trick is to remove the barcode without also removing other important detail. In your example, after denoising, the bars are substantially larger than the text, so removing them and not the text is quite easy. But what else do your images contain? How much do bars vary (in size) between images?

Re: Attempting to remove poor quality barcode

Posted: 2017-12-01T15:30:11-07:00
by fmw42
If your results are this clean, then average the image down to one column and threshold to locate the darkest region. Then find the top and bottom of that region and composite a white horizontal strip of that height over that section of the original image.

Try this (unix):

Code: Select all

size=`convert -ping Capture.png -format "%wx%h" info:`
width=`echo "$size" | cut -dx -f1`
height=`echo "$size" | cut -dx -f2`

bgcolor=`convert  Capture.png -format "%[pixel:u.p{0,0}]" info:`

cropvals=`convert Capture.png -resize 1x! -auto-level -threshold 50% -format "%@" info:`
ht=`echo $cropvals | cut -d+ -f1 | cut -dx -f2`
ht=$((ht+4))
yoff=`echo $cropvals | cut -d+ -f3`
yoff=$((yoff-2))
convert Capture.png -size ${width}x${ht} xc:"$bgcolor" -geometry +0+$yoff -compose over -composite Capture_clean.png
Image

Re: Attempting to remove poor quality barcode

Posted: 2017-12-02T13:12:41-07:00
by depthless
snibgo wrote: 2017-12-01T15:17:50-07:00 The trick is to remove the barcode without also removing other important detail. In your example, after denoising, the bars are substantially larger than the text, so removing them and not the text is quite easy. But what else do your images contain? How much do bars vary (in size) between images?
So nothing else on the image really matters. I'm using a UZN file with Tesseract to recognize only this part of the image.

This image should give a pretty good idea of how much the bars vary in size.
fmw42 wrote: 2017-12-01T15:30:11-07:00 If your results are this clean, then average the image down to one column and threshold to locate the darkest region. Then find the top and bottom of that region and composite a white horizontal strip of that height over that section of the original image.
They're not QUITE this clean. This is the lower righthand corner of an 8.5x11 sheet of paper. Is it possible to set a boundary on the functions you've listed?

Re: Attempting to remove poor quality barcode

Posted: 2017-12-02T13:20:08-07:00
by fmw42
depthless wrote:They're not QUITE this clean. This is the lower righthand corner of an 8.5x11 sheet of paper. Is it possible to set a boundary on the functions you've listed?
Can you be more specific? Boundary on what?

My method requires that you isolate the region where the barcode exists, since it is distinguished by being the darkest contiguous vertical section in the image. So you would have to crop out this region and then process it, then paste it back in. Not much to be gained this way, since you have to crop manually, unless the barcode is in the same region in all images.