0

Given a list of irregularly spaced data points that are used to describe a line or curve or some noisy function, I would like to convert the data to an image-like numpy array, where each "pixel" either contains data or not (say, 1/0 for data / no data). A similar question was asked here; however, I do not necessarily have a data point for each possible x position, and my points are not necessarily integer values.

For example, say I wanted my output image array to span -10 <= x <= 30, 0 <= y <= 20 with each element in the array spanning 1 distance unit (image array would be 20x40). I have data points [(0.1, 0), (20, 5), (23.5, 18)] that I want to "plot". I would like to find all elements in the array that fall on the line segments created by connecting these points, and populate the array by setting these elements equal to 1 and the rest equal to 0.

EDIT: This is a start, but it seems to convert an entire plot into an image, not just the data (so, it includes axes, labels, etc).

6
  • You can calculate the lines from each of these points to the following point, but these lines are rarely going to be integer coordinates, like you said. If you wanted to you could probably include a threshold and if a set of integer coordinates are within that threshold from the lines then "activate" that coordinate. This will create a line-ish in the array, but won't be the most accurate.You could also simply treat each coordinate as a box (e.g. 0,0 is the box from [0->.99,0->.99], etc) and if the line goes through that box then activate it. Commented Jun 17, 2018 at 1:03
  • You can use the Bresenham line drawing algorithm. Or just use a graphics library like PIL to draw your lines. Commented Jun 17, 2018 at 1:05
  • OTOH, if your points as supposed to be on a curve then you could join them with Bézier curves. Commented Jun 17, 2018 at 1:11
  • @PM2Ring Do you know of a particular function in PIL (or another library) that handles this, or is there an easy way to use one of those libraries to accomplish this? And no, I'm not necessarily assuming that the points lie on a smooth curve. Commented Jun 17, 2018 at 2:41
  • I guess should have specified that the points do not necessarily describe a smooth function. I updated my first sentence to reflect that. Commented Jun 17, 2018 at 2:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.