# Extend the line

Given an image with a line on it, produce or display an image with the line extended the the line to the edge of image. The line is black and the background is white. The image size is 100x100 The image comes in any reasonable format (e.g. jpg, png, ppm, bmp).

## Line format

I'm using a simplified version of Bresenham's line algorithm for drawing lines. Lines will only have an integer slope so that the line will never partially cover a pixel but not color it:

At a minimum the line will be 3x3 unless the line is straight, in which case you will only see 3x1 or 1x3 in the image. Lines will also have one side on the edge of the image, so you only have to extend it in one direction.

## Real examples (.png)

### ====================

• Would the program have to take the image input as the filename or would it be allowed to take input in other forms? (e.g. hexdump, link, upload, copy/paste) I only ask because some programming languages would require the use of other forms of input. – DanTheMan Feb 17 '16 at 18:02
• I don't know of any languages that can't read a image file. Do you know a common format that I can include in the I/O section as valid? – J Atkin Feb 17 '16 at 18:05
• @JAtkin can we take input as a URL? – Downgoat Feb 18 '16 at 22:58
• I guess... Why would you want to? – J Atkin Feb 18 '16 at 22:59

ImageRotate@Image@SparseArray[Array[Floor,101,#&@@ImageLines[ColorNegate@#,Method->"RANSAC"]]+1->0,{101,101},1][[;;-2,;;-2]]&

ImageLines detect lines in the image with method RANSAC. We take the first detected line and convert it back to an image. The whole function takes an image as the argument and returns an image.