Extract data from contour plot of .png file?

33 ビュー (過去 30 日間)
Surendra Gupta
Surendra Gupta 2020 年 10 月 12 日
コメント済み: jay shah 2021 年 6 月 2 日
Hi,
I have the attached contour plot figure in .png format. I need to extract the data points form the plot (x,y,z)?
Would someone please help me with the same?
Thanks in advance.
  6 件のコメント
Rik
Rik 2020 年 10 月 12 日
I hard-coded the coordinates for this example image. It looks like there is an issue with rescaling the data, but I will leave that for you to untangle. Note that this solution does not use the actual colorbar, but convert everything to grayscale first. That is probably done to avoid having to match the actual colors, which can be quite tricky for low resolution images like yours.
%// Import the data:
imdata = importdata('ir_image.png');
Gray = rgb2gray(imdata.cdata);
colorLim = [300 1220]; %// this should be set manually
%// Get the area of the data:
da_tp_lft = [25 13];
da_btm_rgt = [231 287];
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:
ca_tp_lft = [246 13];
ca_btm_rgt = [246 287];
cmap_area = double(Gray(ca_tp_lft(2):ca_btm_rgt(2),ca_tp_lft(1):ca_btm_rgt(1)));
%// Convert the colormap to data:
data = dat_area./max(cmap_area(:)).*range(colorLim)-abs(min(colorLim));
figure(1),clf(1)
imshow(data,[])
colorbar
Surendra Gupta
Surendra Gupta 2020 年 10 月 12 日
Thank you.

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

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 10 月 12 日
編集済み: Bjorn Gustavsson 2020 年 10 月 12 日
In case the conversion of the colormap to grayscale doesn't work well (i.e. multiple colours mapping to the same gray-level) I once had to solve this problem, and came up with a solution working reasonably well with the functions attached.
HTH
  3 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 11 月 2 日
Ok, the scan2D2data function expects an rgb-image as input, not a string with path to an image-file. So call it something like this:
imfilename = 'your-png-filename.png';
im_rgb = imread(imfilename);
[M_out] = scan2D2data(img_in);
Then the function will interactively query you about the colour-map and the range the data, and the image-region of the data.
HTH
jay shah
jay shah 2021 年 6 月 2 日
Can you please explain in detail how to use the function? like how to select diagonal points and color map etc.

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

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by