% jpg2rgb % usage: [R,G,B,Rmap,Gmap,Bmap] = jpg2rgb(pic) or % [R,G,B,Rmap,Gmap,Bmap] = jpg2rgb(pic,'nopic') % read a jpeg image and split into three RGB components % the three compnents are shown in red, green, and blue % unless 'nopic' is given % pic is the name of a jpg file given in 'filename.jpg' format % typically the component images will be returned as matrices of byte-sized unsigned integers % allowing 256 levels for each colour, i.e., 24 bit colour % Rmap, Gmap and Bmap are colormaps for showing the R,G,B components function [R,G,B,Rmap,Gmap,Bmap] = jpg2rgb(pic,varagin); % load picture X = imread(pic); R = X(:,:,1); G = X(:,:,2); B = X(:,:,3); M = double(max([max(R(:)),max(G(:)),max(B(:))])); % define colormaps Z = zeros(M+1,1); C = (0:M)'/M; Rmap = [C,Z,Z]; Gmap = [Z,C,Z]; Bmap = [Z,Z,C]; % show images if nargin > 1 return, end; figure(1) imshow(R,Rmap); figure(2) imshow(G,Gmap); figure(3) imshow(B,Bmap); figure(4) imshow(X);