colorByNumber

colorByNumber - %black[r c clr = size(arr Ştermines the...

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
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %black. [r c clr] = size(arr); %determines the dimensions of the array num = [stru.number]; %gets the numbers needed for comparison numr = [stru.red]; % numg = [stru.green]; numb = [stru.blue]; arr1 = zeros(r,c); arr2 = zeros(r,c); arr3 = zeros(r,c); for ind = 1:length(num) arr1(arr==num(ind)) = numr(ind); arr2(arr==num(ind)) = numg(ind); arr3(arr==num(ind)) = numb(ind); end imarr(:,:,1) = arr1; imarr(:,:,2) = arr2; imarr(:,:,3) = arr3; i...
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 Tech.

Ask a homework question - tutors are online