用Python或MatLab从等高线图形的像素中提取数据 [英] Extracting data from pixels of a contour plot figure in Python or MATLAB

查看:40
本文介绍了用Python或MatLab从等高线图形的像素中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个等高线图,如下所示:

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

任何用MatLab/Python编写的建议或示例都会很有帮助!

推荐答案

这里有一个小的MatLab脚本,它可以完成这项工作(使用一些图形用户界面,阅读图底部的指南):

%// 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就是您要查找的内容。

以下是使用问题中的图形显示的输出:

插图代码:

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

这篇关于用Python或MatLab从等高线图形的像素中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆