Attempting to remove poor quality barcode

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
depthless
Posts: 3
Joined: 2017-12-01T14:42:39-07:00
Authentication code: 1152

Attempting to remove poor quality barcode

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Attempting to remove poor quality barcode

Post 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?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Attempting to remove poor quality barcode

Post 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
depthless
Posts: 3
Joined: 2017-12-01T14:42:39-07:00
Authentication code: 1152

Re: Attempting to remove poor quality barcode

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Attempting to remove poor quality barcode

Post 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.
Post Reply