IMAGE Team - The Pantheon project

Tutorial: Removing Thin Straight Lines From Images

Identification

Resources

I. Objective

The goal is to remove thin and nearly straight lines from image. For example, in the image below, the goal is to remove the horizontal lines that compose the table and the separation lines.

The original image.The result image.

II. Method

This method is only convenient for binary and grayscale images because it cannot guarantee to recover the initial colors in case of color images.

The method uses a top-hat with a horizontal linear structuring element to remove the horizontal lines from the resulted image.

The size of the structuring element defines the length of the line to be removed. The top-hat removes the horizontal lines greater than the specified length of the structuring element used in the top hat.

Because, the top-hat yields an image of difference between the closing and the original images, it is necessary afterwards to add the mean value of the input image to recover the initial colors.

Removing vertical lines just needs a vertical linear structuring element instead of a horizontal structuring element.

II.1 Removing the Black Horizontal Lines

The black top-hat with a horizontal structuring element of half-size 7 removes the horizontal lines greater than 15 pixels (=2*7+1).

A black top-hat is the difference between the closing (namely erosion of the dilation of the image) and the image. In this application, we use the inverse of the top-hat image since we want negative values for the difference.

Thus the processing is:

g(x,y) = f(x,y) - εHH(f(x,y)))
pany2pan bordereau.png bordereau.pan
plineardilatation 0 0 7 bordereau.pan tmp1.pan
plinearerosion 0 0 7 tmp1.pan bordereau1-1.pan
psub bordereau.pan bordereau1-1.pan bordereau1-2.pan
bordereau1-1.pan: After the closing.
bordereau1-2.pan: After the difference between the image and its closing.

II.2 Recovering the Initial Grayscale

To recover the initial grayscale values, the mean value of the closing is added to the previous result. This yields the final result.

pmeanvalue bordereau1-1.pan tmp2.pan
paddval tmp2.pan bordereau1-2.pan tmp3.pan
pclipvalues 0 255 tmp3.pan bordereau1-2.panbordereau2.pan
bordereau1-2.pan: After mean addition.

II.3 Variant: Removing Vertical Lines

The same plan is used to remove the vertical lines greater than 21 pixels. The structuring element has been changed to a vertical line of size 10.

plineardilatation 90 0 7 bordereau.pan tmp1.pan
plinearerosion 90 0 7 tmp1.pan bordereau1-1.pan
psub bordereau.pan bordereau1-1.pan bordereau1-2.pan

pmeanvalue bordereau1-1.pan tmp2.pan
paddval tmp2.pan bordereau1-2.pan tmp3.pan
pclipvalues 0 255 tmp3.pan bordereau3.pan
ppan2png bordereau3.pan bordereau.png
bordereau3.pan: After vertical lines removal.

III. The Complete Pandore Script


The Pantheon project
Image Team GREYC Laboratory
UMR CNRS 6072 - ENSICAEN - University of Caen, France
This page was last modified on 22 December 2014