How to display a matrix as a image ?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Himank Airon
am 6 Jul. 2015
Beantwortet: Image Analyst
am 6 Jul. 2015
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 ?
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 6 Jul. 2015
Bearbeitet: Azzi Abdelmalek
am 6 Jul. 2015
A=randi([-1 200],120,50)
map=[0 0 0;1 1 1;1 0 0];
idx1=A==-1
idx0=A==0
idx2=A>0
A(idx1)=1
A(idx0)=2
A(idx2)=3
image(A)
colormap(map)
0 Kommentare
Weitere Antworten (1)
Image Analyst
am 6 Jul. 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;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Colormaps 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!