Filter löschen
Filter löschen

create colormap from matrix value

5 Ansichten (letzte 30 Tage)
gugum gumbira
gugum gumbira am 2 Mai 2016
Bearbeitet: Stephen23 am 2 Mai 2016
Dear all, I have matrix data with range of value [-15 to 34].
From that value I want that -9.99 show with white color and another value is degradation from red-white-blue.
How to do that ?
Any help will be great
Thanks

Antworten (1)

Image Analyst
Image Analyst am 2 Mai 2016
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Create sample data in the range of -15 to +34
oneLine = linspace(-15, 34, 800);
grayImage = repmat(oneLine, [600, 1]);
subplot(1, 2, 1);
imshow(grayImage, []);
title('The Image', 'fontSize', fontSize);
r = zeros(256, 1);
g = zeros(256, 1);
b = zeros(256, 1);
%Find index of -999
index999 = round((-9.999 - -15)/(34 - -15) * 256)
r(1:index999) = linspace(0, 1, index999);
g(1:index999) = linspace(0, 1, index999);
b(1:index999) = 1;
r(index999:end) = 1;
255-index999
g(index999:end) = linspace(1, 0, 257-index999);
b(index999:end) = linspace(1, 0, 257-index999);
subplot(1, 2, 2);
plot(r, 'r-', 'LineWidth', 9);
hold on;
plot(g, 'g-', 'LineWidth', 6);
plot(b, 'b-', 'LineWidth', 3);
grid on;
xlim([1,256]);
cmap = [r,g,b]; % jet(256);
colormap(cmap);
colorbar;
caxis([-15, 34]);
title('The Colormap', 'fontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
  4 Kommentare
gugum gumbira
gugum gumbira am 2 Mai 2016
I am sorry not read the tutorial how to format question before post in this forum.
Do you mean to fix that problem I have to make function ?
Thanks
Image Analyst
Image Analyst am 2 Mai 2016
or you can leave it like that and just make sure whiteValue is the number that you say is changing on every iteration. Right now it says whiteValue = -9.999 because that's what you said. Just don't hard code the number in if it changes every iteration - use the value that's changing instead of using -9.999. It's a lot less messy to pass that number to a function and get the colormap back than having all those lines of code in your for loop.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by