# Robust method to find vertical lines in image

Consider the following images with vertical grid lines.

They can be loaded in mathematica by the following code:

path="https://raw.githubusercontent.com/ccosnett/epc_parser/master/assets/bestiary/";
imgs = path <> # & /@ {
"102489965-2-ei-rating.png"
, "102492044-1-epc.jpg"
, "102519884-1-epc-graphs.jpg"
, "102729176-2-eir.jpeg"
, "102984668-1-epc-rating-graph.png"
, "103003823-1-epc.gif"
, "103187228-4-epc-rating-graph.png"
, "103309151-1-ee-rating.png"
, "105825026-1-epc-1.png"
, "105825038-1-epc-1.jpeg"
, "105829613-1-epc-1.png"
, "105835280-1-epc-1.jpeg"
, "108300254-1-epc-rating-graph.png"
, "108386993-1-environment-impact.jpg"
, "108386993-2-energy-efficiency.jpg"
, "test-1-12.png"
, "test-81-29.png"
, "test-88-1.png"};
images = Import /@ imgs


# Challenge:

write a function which returns the vertical grid lines on the right hand side of the images.

# Attempt 1:

I tried to preprocess my images to make it easier for ImageLines. I made all the images grayscale and all the lines white on black.

Clear[verticalLines];
verticalLines[im_] := Module[{imag, lines, vertLines},
imag = ColorNegate[ColorConvert[im, "Grayscale"]];
lines = ImageLines[imag];
vertLines = Cases[lines, Line[{{x1_, _}, {x2_, _}}] /; Abs[x1 - x2 ] < 2];
HighlightImage[imag, vertLines ]
];
verticalLines /@ images


Unfortunately this is not a robust method because it misses many of the vertical lines.

How can I detect vertical lines in a more robust manner?

Any help would be really appreciated. Thanks in advance!

• This preprocessing seems more stable Binarize[GaussianFilter[ColorConvert[im,"Grayscale"],1,{0,1}],0.05] Commented Aug 6, 2021 at 0:03
• Did you try using the second and/or third parameters of ImageLines? These provide some flexibility in what is detected. Commented May 28, 2023 at 14:59

jj = Rasterize[fig, RasterSize -> 200];

I guess, the simplest way is to use the built-in function ImageLines
i = 4;