Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Name: colorByNum Inputs: (char) A string identifying an image file (cel

ID: 651678 • Letter: F

Question

Function Name: colorByNum

Inputs:

(char) A string identifying an image file

(cell array) A cell array of colors. Each index will contain a 1x3 vector of RGB values

Outputs:

(none)

File Outputs:

1. A image file of the colored in input file

Function Description:

Remember in Kindergarten when you had to color in a picture by number? Yeah, turns out younger you was actually doing some complex computations to figure out what regions to color in with which color, as you will quickly see when you try to tell a computer how to do it. You will be making a function that takes a grayscale image that is mostly white with black lines and colors each region with the corresponding colors in the cell array of colors provided in the second input. A grayscale image is simply an image where the R, G and B layers are identical (i.e. you can ignore all but the first layer).

? You should assign colors to each region in

Explanation / Answer

% Create an array of filenames that make up the image sequence
fileFolder = fullfile(matlabroot,'toolbox','images','imdemos');
dirOutput = dir(fullfile(fileFolder,'AT3_1m4_*.tif'));
fileNames = {dirOutput.name}';
numFrames = numel(fileNames);
I = imread(fileNames{1});
% Preallocate the array
sequence = zeros([size(I) numFrames],class(I));
sequence(:,:,1) = I;
% Create image sequence array
for p = 2:numFrames
sequence(:,:,p) = imread(fileNames{p});
end
% Process sequence
sequenceNew = stdfilt(sequence,ones(3));
% View results
figure;
for k = 1:numFrames
imshow(sequence(:,:,k));
title(sprintf('Original Image # %d',k));
pause(1);
imshow(sequenceNew(:,:,k),[]);
title(sprintf('Processed Image # %d',k));
pause(1);
end