Googlebot
Googlebot

Reputation: 15683

Does SciPy have any function for extracting data from image?

I have to analyze the data given as an image like: enter image description here

What I do is

  1. Earasing the axises manually.
  2. Convert the image to (x,y) coordinates by imagemagick (collecting the coordinates of black pixels)
  3. Adjusting the (x,y) values (according to the axis values (rather than the pixel coordinates), then y direction: in images, the y coordinate increases from top to bottom).
  4. Sorting the data by x.
  5. Loading the data in a 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

Answers (1)

MB-F
MB-F

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:

  1. img = img[:-k, :] # Erase axes manually, k is the height of the axis in pixels
  2. y, x = np.where(img == 0) # Find x and y coordinates of all black pixels
  3. y -= y.max() # invert y axis so (0,0) is in the bottom left corner
  4. 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

Related Questions