Locate points on a line graph of an image

3 Ansichten (letzte 30 Tage)
QI LI
QI LI am 13 Aug. 2021
Kommentiert: QI LI am 17 Aug. 2021
Hello,
I have an image with a line graph with x-y axis (The values on the x-y axis are not evenly distributed). How do I locate a specific x coordinate and get its corresponding y coordinate?
Any help would be appreciated.

Antworten (2)

Bjorn Gustavsson
Bjorn Gustavsson am 13 Aug. 2021
For that type of task I occasionally use grabit - which is a very useful tool. Automatic detection is also possible but more often require rather lots of work if the image is not clear enough.
HTH
  4 Kommentare
Bjorn Gustavsson
Bjorn Gustavsson am 16 Aug. 2021
If you have the data plotted on logarithmic scaled axes you can simply do the required transform on the grabited data:
y = 10.^(data(:,2));
x = 10.^(data(:,1));
To simplify this I typically select the y-axis limit values as 1 (log10(10)) and 5 (log10(10e5)) at the corresponding points, then do the same in the x-direction.
In the worst of cases where the mapping is neither linear or logarithmic you could in principle simply set the limits of the axeses to 0 and 1, and then digitize the intermediate points of the tick-marks (you know the corresponding x and y-values). Then you'll have to make a rescaling of the values, which hopefully should be reasonably straightforward with interp1:
x_true_vals = interp1(data_grabit_xticks,your_xtick_values,data_graph_x,'pchip');
For sanity-checks you should probably plot the curve of (data_grabit_xtics, your_xtick_values) just to make sure it looks sensible. Then the same procedure for the y-coordinate points.
HTH
QI LI
QI LI am 17 Aug. 2021
Thank you for your reply. Let me try the methods.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 16 Aug. 2021
xq = 26.8; %x coordinate to query for
ax = gca();
lh = findobj(ax, 'type', 'line');
matched_lines = gobjects(0);
yq = [];
for K = 1 : numel(lh)
h = lh(K);
xd = h.XData;
yd = h.YData;
if ~issorted(xd)
fprintf('Warning: line %#d is not in sorted order, could be multiple results\n', K);
[xd, idx] = sort(xd);
yd = yd(idx);
end
this_yq = interp1(xd, yd, xq);
if ~isnan(this_yq)
yq(end+1) = this_yq;
matched_lines(end+1) = h;
end
end
At the end of this, yq will be a (possibly empty) vector of y values that correspond to the query x, and matched_lines will be a (possibly empty) vector of the handles of the lines that were matched against (just in case you wanted to examine their tags or DisplayName or something like that.)
The code does not assume that any given line is in sorted order -- a line could double back on itself. However, instead of trying to find all of the possible locations, it takes the short-cut of sorting the line coordinates and finding at most a single match per line. If you want to find multiple intersection lines for a line that doubles back, then you will need to change the logic.

Kategorien

Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by