# Neural network: Line detection in Image

I am playing around with Mathematica's new Neural Network toolbox and am trying to teach a network to detect lines in quite noisy images.

An example Input image would look like the following:

The corresponding (desired) output is an image like this one (currently I am drawing those lines by hand...):

How would one approach this? In detail:

1. How many Input->Output pairs would I need? Currently I have about 100 but I guess this is not enough.

2. What Network architecture would you recommend? I tried a couple of combinations of Convolution and Ramp/Tanh layers but without amazing results.

3. Is there a more suited loss layer than the standard MeanSquare one for my purpose?

4. Would you even recommend using a neural network for this task?

Thanks, Max

• Why not use techniques from computer vision such as Hough transform? – David G. Stork Apr 17 '17 at 17:56
• @user3683367 Why are you only paying attention to the diagonal lines? Is that a requirement? You seem to be throwing away vertical lines (from noise) which have about same luminosity as the diagonal ones. So how do you know what's noise and what's the real deal? Run these on your source gif and see what you get: Binarize@ImageAdjust[ImageConvolve[ImageAdjust[ImageSubtract[gif,.15],1.05], {{-1,0,1},{-2,0,2},{-1,0,1}}],1.1] or ImageAdjust@GradientFilter[ImageAdjust[ImageSubtract[gif,.1],1.2],{2,.5}] – Gregory Klopper Apr 17 '17 at 19:44
• @DavidG.Stork The lines are not necessary straight but can become quite curved. Also I only want clear diagonal lines and discard noisy areas/lines. Thats why I initially thought the network approach might be best. As far as I understood the Hough Transform is mostly useful to extract broken lines or? – MaxJ Apr 17 '17 at 19:52
• This is a semantic segmentation type problem. The desired output of the network is a heat map (or threshholded heatmap) of whether or not a given pixel belongs to one of your desired pixels. There is an example in the 11.1 docs on semantic segmentation that is a pretty good place to start – Yss Apr 17 '17 at 23:11
• In documentation for NetTrain under Applications> Computer Vision. – Gregory Klopper Apr 18 '17 at 21:32