# Image processing: Line detection on paper images

I have some Beta Radiographed papers which all have some vertical lines. I'd like to use the image processing capabilities of Mathematica to automatically detect these vertical lines.

The code which I wrote detects the lines, but when I run the same code on another set of data, I have to manually adjust the Binarize threshold to get decent results. I know I can use Manipulate but I want to save my time in checking each value to see if it detects the vertical lines.

Is there a way in which the operation of detecting these lines in all the beta radiographed data can be automated?

• Since you are James Bond you might ask Q if he can do that easily. If not, I doubt there is a way to automate it. – Öskå Nov 12 '14 at 12:02
• Normalize = Normalize[{{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}, Norm]; gives an error. – C. E. Nov 12 '14 at 14:29
• Sorry, you will need to change it to Normal = Normalize[{{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}, Norm], Since Normalize is reserved. – James Bond Nov 12 '14 at 18:44

This is not a complete answer, but I think you can build on this idea (I currently have no time to push it further).

Considering that the lines are really vertical:

imageData = ImageData[imgRaw];
data = Sum[First /@ imageData[[i]], {i, Length[imageData]}];
ListLinePlot[data]


We can see that there are local minimums. I had no time to automate the detection of this local minimum (as per comments, in version 10, this should be easy with FindPeaks).

So, with no automation, I'm taking the minimums manually from the "get coordinates" tool:

linesCoordinates = First /@ {{58.11, 382.5}, {228.7, 361.2}, {391.6, 446.5}, {568.5,
622.4}};
imageDataAux = imageData;
Do[imageDataAux[[All, Round[i]]] = {0, 0, 0}, {i, linesCoordinates}]
Image[imageDataAux]


Looks promising. Obviously, reducing the analysis to an horizontal band that doesn't have the handwriting may help on the method precision. I hope this helps.

• you say: "I had no time to automate the detection of this local minimum...". In MMA10 this can be done with function FindPeaks – molekyla777 Nov 12 '14 at 13:36
• @molekyla777 I know... But I'm still working with 9 (waiting for 10.0.2 to have 10 on my production machine) – P. Fonseca Nov 12 '14 at 13:37
• peaks = {#[[1]], -#[[2]]} & /@ FindPeaks[-data, 5, 2] works perfectly with your data! – Aisamu Nov 12 '14 at 14:39
• Hey, I tried the above info but got some error in data = Sum[First /@ imageData[[i]], {i, Length[imageData]}]; and in Image[imageDataAux] no image was displayed as an output. I then changed my data set and in other image there was no plotting in the listline. Can you help further? thanks. – James Bond Nov 12 '14 at 18:47
• @JamesBond sure. Can you send me one of the images by e-mail (see in my account)? That way, i'm sure we are seing the same thing. What M version do you have? – P. Fonseca Nov 12 '14 at 19:56