在GNU Octave中绘制显示的图像

时间:2013-02-20 22:30:03

标签: image plot octave

我正在开发Octave中的一些例程,需要显示图像,然后在顶部绘制曲线,希望覆盖一些图像特征。

但是,我无法弄清楚如何匹配图像的原点/比例和图。例如,给定1024x1024像素的图像,我可以这样做:

a=imread('image.png');
x=linspace(1,1024,100);
y=x;
imshow(a);
hold on;
plot(x,y);

但该线未缩放到图像,并且不会从角落开始。 (我知道图像和情节应该来自不同的角落)。当我从光标位置检查图形坐标时,图像显然不在原点,所以我猜这是问题的基础。

3 个答案:

答案 0 :(得分:1)

在这种情况下使用image()代替imshow()

a = imread ('image.png');
x = linspace (1, 1024, 100);
y = x;
image (a);
hold on
plot (x, y);
axis square

答案 1 :(得分:0)

您可以通过以下方式在图像上绘制函数:

  1. 像这样创建一个名为stuff.jpg的图像,任何尺寸都可以,但我的尺寸大约是6x6像素,所以我可以测试一下:
  2. plot functions over an image in gnu octave

    您可以通过以下方式绘制其他功能的功能:

    octave> x = 0:1:5;
    octave> plot(x, (3/2).^x, "linewidth", 2, "color", "blue");
    octave> hold on
    octave> plot(x, 2.^x, "linewidth", 2, "color", "red");
    octave> plot(x, factorial(x), "linewidth", 2, "color", "green");
    octave> plot(x, x.^3, "linewidth", 2, "color", "black");
    octave> 
    

    对我而言,它显示了这一点:

    octave, gnu octave plot multiple lines

    发现这里有一个演练:

    http://ericleschinski.com/c/algorithm_complexity_big_o_notation/

    根据我的年龄绘制我的力量水平。它已经超过九千。

答案 2 :(得分:0)

图像的问题在于它将(0,0)(而不是(min_x,min_y))放在左上角,而我们通常期望(0,0)在左下角。

此外,它仅使用x和y向量的max和min值,因此y(end:-1:1)不起作用。

im = imread('file.png'); %read the file
image([xmin xmax],[ymin ymax],im(end:-1:1,:,:)); %put the image on the screen upside down
axis('xy'); % flip the image by putting (0,0) at bottom left. Image now right side up
axis('square'); if you want to aspect ratio of the image to be 1:1
hold on;
plot([xmin xmax],[ymin ymax]) % this should draw a diagonal from bottom left to upper right.
% plot whatever you want to overlay