Graphic graph of matlab data by image

What I would like to do is draw a graph image (say, a pdf file or a scanned image). Next, I would like to overlay the axis on the graph in the image, and then display the data on that axis (above the image).

Using imtool, I know the coordinates of the graph in the image (x range = ~ 52-355 pixels, and range y = 23 (upper) - 262 (lower) pixel in this case).

Here is what I tried:

I = imread('C:\MATLAB\R2014a\help\images\ref\ftrans2_fig.png');
I = squeeze(uint8(mean(I,3)));
figure, imshow(I)
[rows, cols] = size(I);
x_data = (-1 : .01 : +1)';
y_data = 1 - x_data.^2;
h1 = axes('Position',([52, 23, 355-52, 262-23] ./ [cols, rows, cols, rows] ));
set(h1, 'Color', 'none')
hold on
plot(x_data, y_data, '-rx')

Question: knowing the pixel coordinates of the graph in the image, how to determine the correct position of the axis in the figure (my code does not take into account the actual size of the figure window, the gray frame around the image). I have to do this for several images and datasets, so I would like to automate the method, assuming that I find the coordinates of the graphs in the image ahead of time.

! (1- , , )

+4
2

, , . :

I = imread('C:\MATLAB\R2014a\help\images\ref\ftrans2_fig.png');
I = squeeze(uint8(mean(I,3)));
[rows, cols] = size(I);
x_data = (-1 : .01 : +1)';
y_data = 1 - x_data.^2;
h1 = axes('Position',([52, 23, 355-52, 262-23] ./ [cols, rows, cols, rows] ));
set(h1, 'Color', 'none')
hold on
image(I, 'Parent', h1);
plot(h1, x_data, y_data, '-rx')

, , . , . , .

!

0

, . , :

figure, h1=imshow(I)
get(h1,'Position')

, "" " " ".

:

I = imread('C:\MATLAB\R2014a\help\images\ref\ftrans2_fig.png');
I = squeeze(uint8(mean(I,3)));
in_mag = 300;
figure, imshow(I, 'Border', 'tight', 'InitialMagnification', in_mag)
[rows, cols] = size(I);
x_data = (-1 : .01 : +1)';
y_data = 1 - x_data.^2;
% Coord of graph in image pixels
x_0 = 50; x_max = 354; y_0 = 262; y_max = 23;
h1 = axes('Position',([x_0,   rows-y_0,   x_max-x_0,   y_0-y_max] ...
                   ./ [cols,   rows,      cols,          rows] ));
set(h1,'Color','none')
hold on
plot(x_data, y_data, '-rx')
ylim([0,1.4])
set(gca,'YColor', [0 0 1], 'XColor', [0 0 1])

, - , !

0

Source: https://habr.com/ru/post/1548562/


All Articles