Reputation: 15683
I have to analyze the data given as an image like:
What I do is
imagemagick
(collecting the coordinates of black pixels)SciPy
script.I wonder if there is a function to do any of the steps 1-4 in the same SciPy
script.
Since SciPy
has a range of functions for image recognition, I would like to know if there is a function to translate an image into the (x,y) coordinates of the black pixels creating the curve, and so on.
Upvotes: 0
Views: 77
Reputation: 23647
First, load the image with sp.misc.imread
or PIL so that it resides in a numpy array that I'll refer to as img
below. (If it is a color image convert it to grayscale with img = np.mean(img, axis=-1)
. Then:
img = img[:-k, :] # Erase axes manually, k is the height of the axis in pixels
y, x = np.where(img == 0) # Find x and y coordinates of all black pixels
y -= y.max() # invert y axis so (0,0) is in the bottom left corner
i = np.argsort(x); x, y = x[i], y[i] # Sort data by x
Assumed imports:
import numpy as np
import scipy as sp
Upvotes: 1