MATLAB Answers

Generating a filled contour colormap

36 views (last 30 days)
Michael
Michael on 4 Jun 2019
Hello,
Here is my issue. I want to make a countour with filled in level
example: say 5 level That should mean I have 5 color transitions from say Red (hot) to Blue (cold). The data I have is 1200 x 1600 monochrome png file (0-255). Range of the data was (50-125). I'm am able to generate a countour plot that has levels image one, which gave me the countours percent of max. Then I tried to fill in the countours image two and I can't get the fill to work properly. I also tryied the surf function, which gave the 3d surf but I was not able to rotate the data in the figure window to a top down view (plot would not rotate at all). Any help would be useful
Code
Z1 = imread ('\\zfcae\RenderedScene.png');
Z2 = Z1 (1:end,1:end, 1);
B = double(flipud(Z2));
Z = (smoothdata(B));
[X,Y] = meshgrid(1:1600,1:1200);
f1 = figure;
contour (Z, 10);
f2 = figure;
contourf(X,Y,Z,10)
colormap jet
f3 = figure;
h = surf (Z);
set(h,'LineStyle','none')
--- Output in sequence---
Capture1.JPG
Capture2.JPG
Capture3.JPG

  0 Comments

Sign in to comment.

Answers (3)

Bjorn Gustavsson
Bjorn Gustavsson on 4 Jun 2019
Instead of using surf you can use pcolor, then you get the "from-above-view" automatically. You shold have a function for doing exactly what you want: contourf, should be a drop-in replacement of contour - check the help of either to adjust the contour-levels and what-not...
HTH

  0 Comments

Sign in to comment.


Michael
Michael on 4 Jun 2019
Hello Bjorn,
Thanks for the help. The contourf didn't work it produced a plot that was all a single color. Either red or yellow depending on if colormap jet was commented or not.
pcolor did seem to get the view I was looking for is there a way to set the number of colored regions and ther percent of the maximun?

  1 Comment

Bjorn Gustavsson
Bjorn Gustavsson on 4 Jun 2019
Oh, I missed that you tried contourf. It should be a drop-in replacement. Does the same single-coloured thing happen if you excplicityl command the function to draw contours at specified levels?
contourf(X,Y,Z,[linspace(50,125,7)])
Have you some other function shading the contourf in matlab, what does:
which contourf -all
return?
Pcolor maps the range of your data (Z) to the entire current colourmap. You could mimick
contourf (but will still not get exactly the same result (not the single-coloured version, but the one you want) as contourf) by reducing the numbers of colours in the colormap:
colormap(jet(7)) % or whichever colourmap you choose...
HTH

Sign in to comment.


Michael
Michael on 4 Jun 2019
Hello Bjorn,
I did get my reults to work with something similar to what you listed for the third method. The first two did ntseem to work for me see reply below. The only think that might be nice would be to add a level indicator at a specifiec location on the colorbar
f2 = figure;
contourf(X,Y,Z,[linspace(50,125,7)])
--Returns---
Capture2.JPG
f2 = figure;
contourf(X,Y,Z,10)
contourf -all
-- Results in---
Error using contourf (line 57)
Error in color/linetype argument.
Error in test (line 13)
contourf -all
c = jet;
c = jet(20);
f1 = figure;
contour (Z, 10);
% f2 = figure;
% contourf(X,Y,Z,10)
colormap (c)
f4 = figure;
h2 = pcolor(B);
set(h2,'LineStyle','none')
colormap (c)
colorbar
--Result are what I needed---
Capture3.JPG

  1 Comment

Bjorn Gustavsson
Bjorn Gustavsson on 5 Jun 2019
Seems like you've gotten a reasonably working solution - for now. I'm still a good bit curious since contourf should work. That you get an error after contourf -all is no surprice since what I wanted to know is the information about which version of contourf your matlab-session is using at that time, so could you tell us what you get after:
which contourf -all
that will tell us what version is is.
Can you share the troublesome data so that we can test in other versions?

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019a