How to find coordiates of the LAST point of the aray which has been plotted?

Hello! I have plotted a few time series on a graph. I need to be able to crop out a certain a fixed part (rectangle area 1000x1000 pixels) For this I was able to find this code:
imagesize=size(I);
xsize=imagesize(1,2)
ysize=imagesize(1,1)
xziseout=xsize-xsize*0.3
yziseout=ysize/2-ysize/5;
I2 = imcrop(I,[xziseout yziseout 1000 1000]); % [xmin ymin width height]
imshow(I)
figure, imshow(I2)
print('-dpng', printnamepngfile, '-r350')
I am using this code to roughly get the area out of the center of the picture but it fails because I actually need to focus on cpecific pixel. This pixel is the last point of a plotted array. I wonder how I can get pixel coordinates of the last data point that was plotted n a chart. I need these XY coordinates to be relative to the absolute pixel height and width of the output picture.
Thanking many times for any help in this matter!!!
Dima

回答 (2 件)

Image Analyst
Image Analyst 2014 年 8 月 10 日

0 投票

You forgot to attach the picture. I don't know if you have an image, or if you have some kind of 1D data plotted as a line chart in an axes, or an image of a graph. I don't understand why you say "plotted". Generally images are "displayed", not "plotted". And I don't know what you mean by the last point. Do you mean I(end, end), or I2(end, end)????

9 件のコメント

Dima
Dima 2014 年 8 月 10 日
編集済み: Dima 2014 年 8 月 10 日
Thank you for your reply...Actually we can use any code to get the picture.I just need to find out the exact coordinates of a last data point placed on the chart/figure.
We can us this code to create picture:
function getPlotPointCoord()
clc;
figure(1);
x = -2*pi:0.05:+2*pi;
subplot(1,2,1);
hold on;
plot(x, sin(x));
plot(0, sin(0), 'bx', 'ButtonDownFcn', {@getPoint, 0, sin(0)});
print('-dpng', 'x', '-r350')
end
I just need to knwo how to find exact X Y pixel coordinates of the last point plotted on the graph. I hope this can be done in Matlab! Thanks a lot for your help!
Dima
Dima 2014 年 8 月 10 日
and here is the sample picture
Image Analyst
Image Analyst 2014 年 8 月 10 日
The last point plotted was (0, sin(0)).
Dima
Dima 2014 年 8 月 11 日
yes but how do I convert that point into raw pixel coordinates RELATIVE to absolute pixel height and width of the output picture? thanks!
Dima
Dima 2014 年 8 月 11 日
Anyone can please help me with this?????
Image Analyst
Image Analyst 2014 年 8 月 11 日
Why do you need the pixel coordinates? You'd probably have to call getframe and then do some sort of spatial calibration, which would involve knowing where the origin (pixel coordinates) of the graph was, along with one other point that's known.
Dima
Dima 2014 年 8 月 11 日
編集済み: Dima 2014 年 8 月 11 日
thank you for your reply...the thing is I need to know this coordinate position because I want to crop out a THUMBNAIL image focusing on the LAST data point from a LARGE image....it would be terrific if you could help me do that!)
Dima
Dima 2014 年 8 月 12 日
Do you think this kind of task can be accomplished in principle???? I need it a lot to complete the current assignment....thank you!
Image Analyst
Image Analyst 2014 年 8 月 12 日
Why not just use imresize() to create a thumbnail image????

サインインしてコメントする。

Michael Haderlein
Michael Haderlein 2014 年 8 月 12 日
So I believe you know the position inside the axis you want to focus, right? Let's say you've plotted something between x=100:102 and y=-90:-88 and you want to get the position of the center point (101,-89). You first need the relative position inside the axis and then get the absolute position (e.g. in pixels):
figure, axes, plot(100:102,-90:-88)
x=101;y=-89;
lim=get(gca,{'xlim','ylim'});
xfrac=(x-lim{1}(1))/diff(lim{1});
yfrac=(y-lim{2}(1))/diff(lim{2});
ax_units=get(gca,'units');
set(gca,'units','pixels');
ax_pos=get(gca,'position');
x_abs=ax_pos(1)+xfrac*ax_pos(3)
y_abs=ax_pos(2)+yfrac*ax_pos(4)
set(gca,'units',ax_units)
Hope this helps.

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2014 年 8 月 10 日

コメント済み:

2014 年 8 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by