colorByNumber - %gets the numbers for the blue layer arr1 =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function imarr = colorByNumber(arr,stru) %Given an m x n array and a structure, use the values in the given %structure to create an m x n x 3 image array. The given structure %will have the following fieldnames: 'number', 'red', 'green', 'blue'. %The 'number' field will contain the value that we want to replace in %the array with the corresponding rgb values found in the 'red', 'green' %and 'blue' fields. If there is no match for a value (if the value %doesn't exist in our code structure), then the pixel should be colored %black. [r c clr] = size(arr); %determines the dimensions of the array num = [stru.number]; %gets the numbers needed for comparison numr = [stru.red]; %gets the numbers for the red layer numg = [stru.green]; %gets the numbers for the green layer numb = [stru.blue];
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %gets the numbers for the blue layer arr1 = zeros(r,c); %creates the first layer of zeros arr2 = zeros(r,c); %creates the second layer of zeros arr3 = zeros(r,c); %creates the third layer of zeros for ind = 1:length(num) arr1(arr==num(ind)) = numr(ind); %indexes into the first layer to fill the true spots with the %respective red numbers arr2(arr==num(ind)) = numg(ind); %indexes into the second layer to fill the true spots with the %respective blue numbers arr3(arr==num(ind)) = numb(ind); %indexes into the third layer to fill the true spots with the %respective green numbers end imarr(:,:,1) = uint8(arr1); imarr(:,:,2) = uint8(arr2); imarr(:,:,3) = uint8(arr3); %indexes the red, green, and blue arrays into their respective layers end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online