I am trying to extract data points from an image of a graph.

17 views (last 30 days)
Here is a script that allows the user to manually plot data points over an image of a temperature againts time graph. These data points are then ectracted as timeData and tempData.
% Script to plot image of measured temperature, and trace it using the mouse.
%
% Image from http://www.cs.odu.edu/~mln/ltrs-pdfs/NASA-aiaa-2001-0352.pdf
%
% D N Johnston 05/01/23
name = 'temp597';
img=imread([name '.jpg']);
image(img);
title("Click left button to set data points, right button to end")
% You can adapt the following code to enter data interactively or automatically.
timeData = [];
tempData = [];
hold on
while 1 % infinite loop
[x, y, button] = ginput(1); % get one point using mouse
if button ~= 1 % break if anything except the left mouse button is pressed
break
end
plot(x, y, 'og') % 'og' means plot a green circle.
% Add data point to vectors. Note that x and y are pixel coordinates.
% You need to locate the pixel coordinates of the axes, interactively
% or otherwise, and scale the values into time (s) and temperature (F, C or K).
timeData = [timeData, x];
tempData = [tempData, y];
end
hold off
%save data to .mat file with same name as image file
save(name, 'timeData', 'tempData')
The axes of the image, however does not align with the axes of the MATLAB plot, meaning the maunually interpolated data is nothing like the real data. How can I get the image to exactly match the axis in the MATLAB plot?

Answers (1)

Star Strider
Star Strider on 13 Mar 2023
See if the digitize2.m File Exchange contribution will do what you want.
It seems to be highly regarded, with 14.7K downloads in the past 30 days.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!