【问题标题】:Extracting data from pixels of a contour plot figure in Python or MATLAB在 Python 或 MATLAB 中从等高线图的像素中提取数据
【发布时间】:2018-10-23 15:46:32
【问题描述】:

我有一个这样的等高线图:

现在,如果我没有生成等高线图的数据,而我只有图像,我如何从图像中提取每个像素的值并将其存储在一个数组?

MATLAB/Python 中的任何建议或示例都会有所帮助!

【问题讨论】:

    标签: python matlab image-processing matlab-figure contour


    【解决方案1】:

    这是一个可以完成这项工作的小型 Matlab 脚本(使用一些 GUI,阅读图形倾斜处的指导线):

    %// Import the data:
    imdata = importdata('your_picture_file');
    Gray = rgb2gray(imdata.cdata);
    colorLim = [-1 1]; %// this should be set manually
    %// Get the area of the data:
    f = figure('Position',get(0,'ScreenSize'));
    imshow(imdata.cdata,'Parent',axes('Parent',f),'InitialMagnification','fit');
    %// Get the area of the data:
    title('Click with the cross on the most top left area of the *data*')
    da_tp_lft = round(getPosition(impoint));
    title('Click with the cross on the most bottom right area of the *data*') 
    da_btm_rgt = round(getPosition(impoint));
    dat_area = double(Gray(da_tp_lft(2):da_btm_rgt(2),da_tp_lft(1):da_btm_rgt(1)));
    %// Get the area of the colorbar:
    title('Click with the cross within the upper most color of the *colorbar*')
    ca_tp_lft = round(getPosition(impoint));
    title('Click with the cross within the bottom most color of the *colorbar*')
    ca_btm_rgt = round(getPosition(impoint));
    cmap_area = double(Gray(ca_tp_lft(2):ca_btm_rgt(2),ca_tp_lft(1):ca_btm_rgt(1)));
    close(f)
    %// Convert the colormap to data:
    data = dat_area./max(cmap_area(:)).*range(colorLim)-abs(min(colorLim));
    

    现在,data 就是您要找的。​​p>

    这里是使用问题中的图的输出说明:

    插图代码:

    figure('Position',[100 200 1200 400]);
    subplot 121
    imshow(imdata.cdata)
    hold on
    plot(da_tp_lft(1),da_tp_lft(2),'m+','MarkerSize',7,'LineWidth',2)
    plot(da_btm_rgt(1),da_btm_rgt(2),'m+','MarkerSize',7,'LineWidth',2)
    plot(ca_tp_lft(1),ca_tp_lft(2),'r+','MarkerSize',7,'LineWidth',2)
    plot(ca_btm_rgt(1),ca_btm_rgt(2),'r+','MarkerSize',7,'LineWidth',2)
    hold off
    title('The original image')
    
    subplot 122
    surf(data)
    shading interp
    view(50,40)
    colorbar
    caxis([-1 1])
    title('Illusration of the data')
    axis tight
    

    【讨论】:

    • @arun 请让我知道这个答案是否对您有帮助,或者您正在寻找不同的东西。
    【解决方案2】:

    如果你知道像素值,使用find,你可以找到你想要的位置。

    I = imread('y5dZ1.png');
    I1 = rgb2gray(I) ;
    %%
    pix = [48 : 10 : 200] ;
    [y,x] = find(I1==200) ;
    
    imshow(I)
    hold on
    plot(x,y,'.r')
    

    【讨论】:

      猜你喜欢
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多