Ask Your Question

Revision history [back]

I do not think he wants to calculate the euclidean distance, but he wants to define the pixel values falling on that line.

You should first consider how a line defined by 2 points can be represented mathematically. Given point 1 and point 2, the line equation equals:

Point1 = Point(x1,y1); Point2 = Point(x2,y2);   
y = y1 + [(y2 - y1) / (x2 - x1)]·(x - x1);

This gives you the ability to know exactly which pixels correspond to that line. Loop over your image, enter the x coördinate in the equation and look if the output is still the index your are currently in y position. If this check holds, than add the current value of the pixel to a storage container, for example an int that increases in value each time.