Extend the line

8

Task

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:

(Wikipedia image)

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.

Example (.png, red line added so you can see it):

enter image description here enter image description here

Real examples (.png)

enter image description here enter image description here

====================

enter image description here enter image description here

====================

enter image description here enter image description here

====================

enter image description here enter image description here

====================

enter image description here enter image description here

J Atkin

Posted 2016-02-17T17:11:36.093

Reputation: 4 846

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 – 2016-02-17T18:02:36.443

1I 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 – 2016-02-17T18:05:08.597

@JAtkin can we take input as a URL? – Downgoat – 2016-02-18T22:58:19.367

I guess... Why would you want to? – J Atkin – 2016-02-18T22:59:40.933

Answers

2

Mathematica, 125 bytes

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

Explanation

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.

njpipeorgan

Posted 2016-02-17T17:11:36.093

Reputation: 2 992