How do I find the X and Y coordinates of image (want to plot this figure)
84 views (last 30 days)
DGM on 20 Mar 2022
Edited: DGM on 20 Mar 2022
To paraphrase prior answers to similar questions:
If you want the original data, you're out of luck. It's gone. Simply put, the image is not the data. All images of plotted data are simplified representations of the underlying data, intended for visualization -- not as a store of data. The size of the image, the width of the lines, and the degree of destructive compression used all create ambiguity that influences the precision of any recovery attempt. Accordingly, the quality of any extracted information will be questionable.
Starting with a poor source of information and expecting to automagically extract the underlying data without human effort is simply an exercise in tedious oversight. In other words, you either have to invest effort in transcribing the data, or you'll have to invest at least as much effort in babysitting a very fragile automation of the same.
You can try to throw a bunch of image processing at it, or you can just manually transcribe the curves and rescale them to the data coordinate space described by the axes labels. The question is whether it's subjectively less of a hassle to spend your time guessing where the missing or malformed line segments go, or whether you prefer to spend your time writing and debugging an elaborate script that does the same amount of guessing without the benefit of conceptual insight.
For something like this, I'd suggest starting by trying to rectify the image. The image appears to be scanned. It is not merely rotated, but also distorted. You'll have to transform it back into a rectangle.
At that point, you can use images.roi.Polyline() and get a point list. Then rescale those image coordinates to data coordinates.
EDIT: here's a start:
A = imread('1.jpg');
A = rgb2gray(A);
% these are the coordinates of the box corners
boxm = [81 28; % [x y]
% assert that this is where they're supposed to be
boxf = [80 30; % [x y]
% rectify the image
TF = fitgeotrans(boxm,boxf,'projective');
outview = imref2d(size(A));
B = imwarp(A,TF,'fillvalues',255,'outputview',outview);
% the extent of the data axes
dataaxes = [1 1; % [x y]
% where did that 286 come from? find the x-location of the 281 tick ...
%(281-1) * range(boxf(:,1))/(955-min(boxf(:,1))) + 1
% UNCOMMENT THIS
% % create a polyline ROI object
% R1 = images.roi.Polyline(gca)
% R1.draw % start manually drawing it
% pause() % wait for the user to finish adjusting the ROI
% % user has to hit enter in the console to continue
% THIS IS JUST PLACEHOLDER DATA TO REPLACE THE COMMENTED CODE ABOVE
% DELETE THIS
R1.Position = [93 134;133 73.4;206 86.8;252 58.9;462 309;478 231;569 284;657 141;672 184;730 166;764 97.2;911 60;940 101;977 61];
% rescale the ROI coordinates to data coordinates
% trace1 is a Mx2 array of points formatted as [x y]
trace1 = (R1.Position - min(boxf,,1))./range(boxf,1); % normalized coordinates
trace1(:,2) = 1-trace1(:,2); % flip y-data
trace1 = trace1.*range(dataaxes,1) + min(dataaxes,,1) % scale to data
Since interactive things like ROI creation can't be used in the forum editor, I slapped in a crude example curve. You'll have to uncomment the ROI stuff and delete the placeholder. You'll have to do whatever you want to generate all four traces (make a loop or something) and save the resulting data (a .mat file or something).
Returning to the discussion of the limitations, note that even after being rectified, the plot box lines are not all straight. The distortion is more complex than a simple perspective; the page was likely not flat. Consequently, the remaining distortion will simply contribute to the error in any transcribed data.