1

I am in the process of comparing various contourplots from Ansys Fluent and Matlab. Everything is plotted on the same coordinates and with the same caxis limits. However I am struggling to get the colormaps to match. Exporting the data from fluent to matlab is not an option unfortunately.

I have the Ansys Fluent colormap saved as a .jpg or .png. I am trying to make a custom colormap for matlab from [url=http://www.arc.vt.edu/ansys_help/flu_ug/graphics/g_flu_ug_panel_cmap.png image similar to this[/url] so I can plot my matlab data with the same colormap. Obviously I clipped away the uneccesary data so that just the colormap was left.

I have tried to do something with imread and rgb2ind but that gave me some very funky results.

h=imread('custom_colormap.jpg')
[X, map] = rgb2ind(h,50);
colormap(map);

Your ideas are much appreciated.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
Arno
  • 11
  • 3
  • (A) Is `'custom_colormap.jpg'` cropped to only include the actual colourmap portion? (B) how high quality is that image and shouldn't you perhaps be using a lossless image format for this, say bitmap? – Dan Oct 16 '14 at 15:38
  • Thank you for the reply. (A) yes i have cropped the image to only include the colourmap portion. I have also tried rotating it by 90 degrees (B) I took a screenshot. So it's not extremely high resolution. Just to be safe I tried it with a bitmap and it didn't help. (C)Perhaps It can be done without using imread but pick the colors somehow. I know there are 50 different colours in the plot, I don't need more. I think i can find out what exact z value in my contour each colour should represent. – Arno Oct 16 '14 at 15:59
  • Next thing to try is calling `unique` on your image to see how many colours there are (i.e. to determine if there is noise on the image) – Dan Oct 16 '14 at 16:02
  • If there is not much noise then you could just create the colormap yourself using unique (with the `'stable'`) option. It's possible that `rgb2ind` is just picking the wrong order... – Dan Oct 16 '14 at 16:04
  • Finally you can try just creating your own map, it seems like it just goes from pure blue to pure green to pure red with linear grading in between... just use `linspace` as in this technique: http://stackoverflow.com/questions/17230837/how-to-create-a-custom-colormap-programatically/17232355#17232355 – Dan Oct 16 '14 at 16:07
  • 1
    Do you need that exact map? You can get pretty close by trimming Matlab's `hsv` map: `n = 20; cm = hsv(ceil(n/.7)); cm = cm(1:n,:); colormap(cm), colorbar` – Luis Mendo Oct 16 '14 at 16:16
  • @LuisMendo and possibly a `lrflip` if needed – Dan Oct 16 '14 at 16:17
  • I didn't succeed in using unique, can you elaborate? It's very possible that rgb2ind is picking the wrong order. – Arno Oct 16 '14 at 17:13
  • I also tried to make my own colormap with the link you suggested. It seems that the red (255 0 0) and blue (0 0 255) are too "red" or "blue". – Arno Oct 16 '14 at 17:20
  • @ArnoEijkelkamp Then use the color picker in something like MS Paint to check from your screen shot what the actual RBG values for the red,green and blue are and adjust in the `colormapeditor` appropriately. Just note that in that link I posted, I'm interpolating in RGB space not in HSV space which will not give the desired results! It might be as simple as calling hsv2rgb but it also might not. Either way the editor tool does it for you. – Dan Oct 17 '14 at 09:20
  • @ArnoEijkelkamp Also have a look at this: http://www.mathworks.com/matlabcentral/fileexchange/11175-blue-to-red-colormap you can see how he coded it... – Dan Oct 17 '14 at 09:21

2 Answers2

2

Have you tried just creating your own custom colormap? You can do it quite easily using the colormapeditor tool:

enter image description here

Dan
  • 45,079
  • 17
  • 88
  • 157
  • Thank you, I managed to get the best result with this solution. unfortunately it can't get it to match the data close enough. – Arno Oct 16 '14 at 17:17
2

Do you need that exact map? You can get pretty close by trimming Matlab's hsv map:

n = 20; %// desired number of colors
t = .7; %// trimming factor
cm = hsv(ceil(n/t));
cm = cm(1:n,:);
%// cm = flipud(cm); %// if needed. Thanks to Dan
colormap(cm);
colorbar

enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • Thank you for this. It's quite usefull but I can't quite get it right with the accuracy that I need. I also tried it with the jet colormap (the one i was originally using). I will try again tomorrow. – Arno Oct 16 '14 at 17:17