preserving RGB color quality from heatmap figures during exporting

I wish to export in RGB heatmaps that were created using imagesc and pcolor for output. The MATLAB .fig outputs look beautiful using the "jet" color map. However, regardless of the format type (.svg, .eps, .png, etc.) the colors get blunted with the blues becoming more purplish and reds and oranges shifted more to the yellow spectrum. This still occurs despite setting/using the export feature in the figure menu to output in RGB. Ultimately, I wish to import the colormaps into adobe illustrator for figure making purposes. Only when I switch to CMYK in Adobe do the colors somewhat return to how it appeared in the original MATLAB figure, but the hues are much less vibrant and dulled. I didn't have this issue previously until recently updating MATLAB and cannot find any information how to bypass this issue. I'm using MATLAB 2020b and using a Mac.
How can I preserve in any graphical export type the same RGB color quality from the original heatmap figure?
Thank you for any help or suggestions.
%Code generating figure:
T = imagesc(pts, pts, conv2(N, g, 'same'));
figure, pcolor(T.CData);
shading(gca,'interp');
colormap(jet(4096));

8 件のコメント

DGM
DGM 2021 年 6 月 22 日
Can you supply a (minimal) example of pts,N,g, such as would allow us to replicate your output exactly? I don't see the problem on my end, but I don't know if that's because I'm using different inputs or because I'm using a different version/environment. A minimal working example of the problem would help reduce the number of unknowns.
hxen
hxen 2021 年 6 月 22 日
編集済み: hxen 2021 年 6 月 22 日
Hi DGM. Thanks. Hopefully this helps clarify better: I am using a Gaussian filter for smoothing across a meshgrid (parameters below) to smooth for a spatial histogram. Essentially my data is a large sparse matrix of occurrances, the spatial density of which I am interested in examining. I have supplied additional code with how the parameters pts, g, and N were used as well as attached a .mat file with the actual values for N and a screenshot of the color shift I am seeing in the Ai embedding (right image) of the Matlab figure. Cheers.
P.S. The version of Matlab before I noticed this issue was 2019a.
% Bin the data:
pts = linspace(0, 1, 51);
N = hist3([y(:), x(:)], [51, 51]);
% Create Gaussian filter matrix:
[xG, yG] = meshgrid(-5:5);
sigma = 2.5;
g = exp(-xG.^2./(2.*sigma.^2)-yG.^2./(2.*sigma.^2));
g = g./sum(g(:));
DGM
DGM 2021 年 6 月 22 日
It may be the version I'm using, but in R2019b/linux, the saved images seem correct. I might try to see if I can get this to work in something newer, but I doubt I'll get access to that soon. Are they all purple in other viewers as well, or just when importing into Illustrator?
If you don't need stuff like the plot box and axes ticks/labels, a workaround might be to construct an indexed image instead of relying on the plot tools to manage the image output.
hxen
hxen 2021 年 6 月 22 日
Thanks DGM! Appreciate the help and time. For me, so far it seems across the board getting the color shift. Even when sent to others on their ends. It could be a compatibility issue with Illustrator perhaps. Big Sur has given a lot of hiccups between platforms and apps, so it might be that too. Thanks again for the valuable feedback.
DGM
DGM 2021 年 6 月 22 日
For what it's worth, I cropped out and rescaled the images from the screenshot. It's not perfect due to the resizing, but I figured I might be able to take a look at what sort of color transformation is happening between the images to see if there are any clues.
This is R,G, and B; the purple image versus the original. Ideally, these would all be straight lines with a slope of 1.
Same thing, only in HSV
Whatever is happening doesn't seem like a simple transformation -- at least not to me. I don't think it's being caused by the colormap being shifted or misread, but maybe I'm mistaken. I wonder if Matlab is aware of some system-level color management and incorrectly saving values adjusted for display? That's a very handwavy supposition on my part; I have no idea how that would work. It seems like an awful lot for an "adjustment" anyway.
hxen
hxen 2021 年 6 月 23 日
Pretty cool what you did above! It's close but you can tell just by the graph something funky is happening in the blue. Weird. If I learn more about why this is happening I will post back here. Thanks again.
Image Analyst
Image Analyst 2021 年 6 月 23 日
Can you post a screenshot of the image side by side in MATLAB and Adobe Illustrator?
hxen
hxen 2021 年 6 月 24 日
Hi. I did in the above comment. You can find the attachment here: https://www.mathworks.com/matlabcentral/answers/862750-preserving-rgb-color-quality-from-heatmap-figures-during-exporting#comment_1598595

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

 採用された回答

Image Analyst
Image Analyst 2021 年 6 月 23 日

1 投票

Did you try exportgraphics()

2 件のコメント

hxen
hxen 2021 年 6 月 23 日
Thank you for the suggestion! Will give it a try. :)
hxen
hxen 2021 年 6 月 23 日
Unfortunately, it did not work. The strange shift with bloue hues stil persists. I am more convinced this is a Mac OS issue with Illustrator. I can open the exported maps using FiJi. I am going to reach out to Adobe. Thank you all for your time and help.

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

その他の回答 (1 件)

hxen
hxen 2021 年 6 月 28 日

1 投票

Just wanted to follow up. I learned that the issue was a Mac OS new update related problem that reset Adobe Cloud settings. This was during the last MATLAB update I had done. It seems many have this issue after updating Adobe, which is easily solved by resetting the color settings under the Edit menu. Anyone reading this have having this issue might find this helpfu for importing any plots into Adobe: https://helpx.adobe.com/acrobat/using/keeping-colors-consistent.html
Thank you all again for your time.

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2020b

質問済み:

2021 年 6 月 22 日

回答済み:

2021 年 6 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by