How to display a matrix as a image ?
Mostra commenti meno recenti
my matrix of dimension 120x50 has elements ranging from -1 to 200 . I want to display this matrix as a image in which the matrix cells containing -1 should be displayed as black and 0 should be displayed as white and all positive numbers by red(or green) How to do it ?
Risposta accettata
Più risposte (1)
Image Analyst
il 6 Lug 2015
Try this, which works just by changing display parameters and colormap, and without changing any values in your image variable:
% Create sample image.
dblImage = randi([-1 200],120,50);
% Initialize the colormap to all red.
myColormap = [ones(202, 1), zeros(202, 2)];
% Set -1 to black
myColormap(1,:) = [0,0,0];
% Set 0 to white
myColormap(2,:) = [1,1,1];
% Display image
imshow(dblImage, [-1, 200], 'InitialMagnification', 500);
axis on;
% Apply the colormap.
colormap(myColormap);
caxis([-1, 200]); % Colormap applies between -1 and 200.
colorbar;
Categorie
Scopri di più su Images in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!