About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
See full specifications

scripts default iconmat2im (Scripts) Publisher's description

This code snippet converts a 2D matrix to a 3D matrix where the values in the 3rd dimension correspond to pixel intensity in the red, green, and blue domains

This code snippet converts a 2D matrix to a 3D matrix where the values in the 3rd dimension correspond to pixel intensity in the red, green, and blue domains. This is the format used by many functions in the Image Processing Toolbox (which is not required for this function to run).

The code works by mapping the values of matrix "mat" onto the rows of colormap "cmap" using a fast vectorised operation.

function im=mat2im(mat,cmap,maxVal)

Uses vectorized code to convert matrix "mat" to an m-by-n-by-3
image matrix which can be handled by the Mathworks image-processing
functions. The the image is created using a specified color-map
and, optionally, a specified maximum value. Note that it discards
negative values!

mat - an m-by-n matrix
cmap - an m-by-3 color-map matrix. e.g. hot(100). If the colormap has
few rows (e.g. less than 20 or so) then the image will appear
limits - by default the image is normalised to it's max and min values
so as to use the full dynamic range of the
colormap. Alternatively, it may be normalised to between
limits(1) and limits(2). Nan values in limits are ignored. So
to clip the max alone you would do, for example, [nan, 2]

im - an m-by-n-by-3 image matrix

Example 1 - combine multiple color maps on one figure
clf, colormap jet, r=rand(40);
subplot(1,3,1),imagesc(r), axis equal off , title('jet')
subplot(1,3,2),imshow(mat2im(r,hot(100))) , title('hot')
subplot(1,3,3),imshow(mat2im(r,summer(100))), title('summer')
colormap winter %changes colormap in only the first panel

Example 2 - clipping
p=peaks(128); J=jet(100);
subplot(2,2,1), imshow(mat2im(p,J)); title('Unclipped')
subplot(2,2,2), imshow(mat2im(p,J,[0,nan])); title('Remove pixels <0')
subplot(2,2,3), imshow(mat2im(p,J,[nan,0])); title('Remove pixels >0')
subplot(2,2,4), imshow(mat2im(p,J,[-1,3])); title('Plot narrow pixel range')

Rob Campbell - April 2009

See Also: ind2rgb

System Requirements:

MATLAB 7.8 (R2009a)
Program Release Status: New Release
Program Install Support: Install and Uninstall

mat2im (Scripts) Tags:

Click on a tag to find related softwares

Is mat2im (Scripts) your software?

Manage your software

Most Popular

scripts default icon ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation
scripts default icon Simulink Communication Labs 1.1
Simulink Communication Labs allows you to learn communication systems in greater depth.
scripts default icon M-QAM modulation and demodulation 1.1
M-QAM modulation and demodulation is the QAM modulation and demodulation tech.
scripts default icon LZW Compression/Decompression 1.1
LZW Compression/Decompression - Updated LZW compressor and decompressor with reasonable performance
scripts default icon InSPIRE utility to plot a 2D displacement field (Scripts) 1.0
This program plots the deformation field (displace vectors) contained in vector.txt.