
Colormap on the outside of a circle
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hans Bernhard
am 25 Apr. 2015
Beantwortet: Chad Greene
am 9 Mai 2016
Hi, I am new to MATLAB but have ovecome a huge learning curve thanks to the user answers provided on this site. There is something I am stumpped by and I was wondering if there were any suggestions...
I have a colormap of around 16000 color shades in a specific order that I would like to distribute evenly around the outside of a circle. The closest I have gotten is using the pie chart function to render an image like the one attached. This is almost exactly what I would like to have, except for 2 things:
-I only need the outer maybe 10%, the ineer content is not important to me -when I try to make a pie chart with divisions greater than 1000, the processing time is extremely long
is there a more efficient way of mapping the 16000 color colormap to the outside of a circle?
Thanks so much
0 Kommentare
Akzeptierte Antwort
Star Strider
am 25 Apr. 2015
Bearbeitet: Star Strider
am 27 Apr. 2015
———————————————————————————————————————————————
I believe Image Analyst has one of these ready to go, but lacking it, I came up with this:
N = 256; % Nr Colours
c = colormap(jet(N)); % Define ‘colormap’
th = linspace(0, 2*pi, N); % Create Polar Grid
r = 0.5:0.5:1;
[TH,R] = meshgrid(th,r);
[X,Y] = pol2cart(TH,R);
C = bsxfun(@times,(X + Y),th); % Multiply X,Y, by ‘th’ —> Spiral
figure(1) % Plot Flat Spiral
surf(X,Y,C)
view([0 90])
axis square
grid off
You will likely have to experiment with it to get the result you want. It’s fairly simple, and I copied some of the basic ideas from Contour Plot in Polar Coordinates (since I believe in giving credit where credit is due). The idea of using the spiral to force the colour mapping to the spiral was mine! :) All you need do is to define the colormap, and the plot does the rest magickally.
producing:

This plot has edges between the faces. If you want a smooth plot without the edges, and therefore seamless colour transitions (as you likely would with 16000 colours), replace the previous ‘figure(1)’ plot with this code:
figure(1) % Plot Flat Spiral Without Edges
hs = surf(X,Y,C);
view([0 90])
axis square
grid off
set(hs, 'EdgeColor','none')
Otherwise, the code is the same. You can also experiment with the lighting and other options, turning the axes off, and other such tweaks if you like, since this is a surface object. See Chart Surface Properties for details.
14 Kommentare
Mike Garrity
am 28 Apr. 2015
Bearbeitet: Mike Garrity
am 28 Apr. 2015
@Image Analyst That's interesting.
Here's what I see with your code:
>> caxis
ans = 0 65535
>> h = get(gca,'Children')
h = Image with properties:
CData: [800x1600 uint16]
CDataMapping: 'scaled'
>> max(h.CData(:))
ans = 16384
So it thinks that the colormap should cover the values from 0 to 65,535. However the largest value in your image is 16,384. Therefore the image only uses a 1/4 of the colormap.
The next thing to check is the CLimMode:
>> get(gca,'CLimMode')
ans = manual
Ah, someone has set the CLim manually! I'm not sure where that happened. My guess is that it's hiding inside imshow somewhere. I'll try to get a chance to look for it later.
For the time being, you can just do this:
caxis auto
to get the entire colormap.
Now, we do need to be clear that the size of the colormap is only one part of the pipeline. To really get more colors displayed on the screen, we need to worry about the narrowest representation of colors in the entire pipeline. The reality is that you are going to see banding caused by operations which truncate to 8 bit. Getting rid of the limit on the colormap size was a really important step, but it's not the only limitation that matters here.
I should also mention that many graphics cards will struggle with aliasing issues with colormaps like flag(16384).
Star Strider
am 28 Apr. 2015
I tried that, but with 'FaceColor','interp' it threw an error. I’m not sure what the problem was, but the code provided an decent plot without it at a lower number of colours, so I just let it go at that.
Weitere Antworten (2)
Image Analyst
am 26 Apr. 2015
Looks like you've gotten an acceptable answer, but for what it's worth, here's my color wheel demo, attached. You need to adapt it to make the hue some constant, like 0.9 for purple or something. Then quantize the value image instead of the hue image to take on values from 0 to 0.5 or something.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Color and Styling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





