% ee435 sample pseudocolor program % Note: the image we will use here, is a grayscale image, but it is % actually stored as if it were a color image, with a red, green and blue % component to each pixel. In order for this to appear as only shades of % gray, all components (r, g, and b) are the same value for each pixel. a=imread('herndon.jpg'); % this is a grayscale image so r=a(:,:,1); % matrix r is the red component g=a(:,:,2); % matrix g is the green component b=a(:,:,3); % matrix b is the blue component gray=r; % set aside a single component grayscale image to use in the following... % define 2 thresholds for pseudocoloring thresh1=240; thresh2=120; % find all gray levels > threshold 1 and set the color to red loc=find(gray >thresh1); r(loc)=gray(loc); % set the red component at these locations to max value (255) g(loc)=0; % set the green component at these locations to 0 b(loc)=0; % set the blue component at these locations to 0 % find all gray levels < threshold 2 and set the color to blue loc=find(gray < thresh2); r(loc)=0; % set the red component at these locations to 0 g(loc)=0; % set the green component at these locations to 0 b(loc)=gray(loc); % set the blue component at these locations to 255 % find all gray levels in between thresholds 1 and 2 and set the color that % shade of green loc=find(gray >= thresh2 & gray <=thresh1); r(loc)=0; % set the red component at these locations to 0 g(loc)=gray(loc); % set the green component to be the gray level b(loc)=0; % set the blue component at these locations to 0 % put these component planes back together into new color image a1 a1=zeros(size(a)); a1(:,:,1)=r; a1(:,:,2)=g; a1(:,:,3)=b; a1=uint8(a1); % convert from double to uint8 % create a display for the original grayscale and the pseudocolor image figure(1) subplot(1,2,1) imshow(a) title('original grayscale') subplot(1,2,2) imshow(a1) % image() needs color images to have values 0.0-1.0 title('pseudocolor')