Image processing, find coordinates in an image


Hello everyone, I’m new to image processing so any help would be appreciated, I have an image with 2 red lines in it(the image only contains those 2 lines with a black or white background), what method or algorithm would let me get coordinates of points on those 2 lines.

Thank you, Daniel.


Are they line segments, or do they span the image?

Are these rendered lines, or photographed? 1 px thick? Antialiased?

Is this realtime? Will the lines be moving?

When you say coordinates of points on those lines, do you mean end points, any points, all points?

Can you share an example image?

This might be as simple as checking pixels[] or as complex as using OpenCV.


I don’t have a sample right now bcz me and my group still haven’t bought the camera…but the 2 lines are segments…the image is photographed(with a gd camera, we saw a camera that was 16 mpx or maybe it was 18 mpx)…its a photo not video so the lines wont be moving…I don’t think the lines will be 1 px and honestly I need 2 points coordinates on each of the 2 lines(the 2 lines intersect so no prob if 1 of the 2 points is there intersection) so any points or end points or many points won’t matter as long as I can get 2 on each of the 2 lines.


If you are doing line detection on camera images, then you want the OpenCV for Processing library.

Use a Hough transform for line detection:

PDE > File > Examples > Contributed Libraries > OpenCV for Processing > HoughLineDetection

If for example your input image was this:


Then a slight modification of that demo sketch:

import gab.opencv.*;
OpenCV opencv;
PImage src;
ArrayList<Line> lines;

void setup() {
  size(900, 300);
  src = loadImage("red-lines.png");
  src.resize(0, 300);
  opencv = new OpenCV(this, src);
  opencv.findCannyEdges(20, 75);

  // Find lines with Hough line detection
  // Arguments are: threshold, minLengthLength, maxLineGap
  lines = opencv.findLines(100, 30, 20);

void draw() {
  // original image on left
  // edge detection pixel data in center (white-on-black)
  image(opencv.getOutput(), 300, 0);
  // rendering of detected line data on right (blue)
  // lines.angle gives the  angle in radians, measured in double precision
  // lines also have "start" and "end" PVectors with the x,y position.
  for (Line line : lines) {
    line(line.start.x, line.start.y, line.end.x, line.end.y);

…will give you output like this:

Now you can use line-line collision detection, e.g. this example from Thompson:

boolean lineLine(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
  // calculate the distance to intersection point
  float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
  float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
  // if uA and uB are between 0-1, lines are colliding
  if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
    // optionally, draw a circle where the lines meet
    float intersectionX = x1 + (uA * (x2-x1));
    float intersectionY = y1 + (uA * (y2-y1));
    ellipse(intersectionX,intersectionY, 20,20);
    return true;
  return false;

…to find if your lines intersect. Rather than returning true, you could instead return a PVector with the point of intersection.


ohh waw thanks man <3
thanks a lot!