Extend the line

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.


APL (dzaima/APL), 93 bytes

{w←⍵⋄m←÷/(⊢/-⊃)p←⍸¯1≠⍵.mat⋄y x←⊃p⋄P5.size←⍵.sz⋄P5.setup←{P5.G.bg¯1⋄P5.G.ln∊{⍵,y+m×⍵-x}¨⍳101}}

Try it online!

A dfn which takes the image as an APLImg object. Taking the image as a URL is 102: Try it online!

Uses ⎕IO←0 (0-indexing).

The function effectively takes the line, calculates its equation and redraws it.

Explanation

Slope calculation: m←÷/(⊢/-⊃)p←⍸¯1≠⍵.mat

⍵.mat get the image as an integer matrix

¯1≠ check which pixels aren't white

get all the required coordinates

p← store in p

(⊢/-⊃) subtract the last point from the first

÷/ reduce by division


y x←⊃p store the first point in y and x

P5.size←⍵.sz set canvas size to image size


Draw the image: P5.setup←{P5.G.bg¯1⋄P5.G.ln∊{⍵,y+m×⍵-x}¨0,w.width}

P5.setup←{...} draw the following once:

P5.G.bg¯1 set the background to white

P5.G.ln∊{⍵,y+m×⍵-x}¨⍳101 draw lines between the following points:

{...}¨0,w.width get the points for each x in 0-100:

y+m×⍵-x \$y = y_1+m(x-x_{1})\$

⍵, pair the x value with that

enlist so it can be drawn