makeColorByNumber

makeColorByNumber - (0-255): '); end e % Do colorByNumber...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function out = makeColorByNumber(array) % usage: out = makeColorByNumber(array) % array is the matrix which you would like to color. % If replicate.m or resizeImage.m are in the same folder, you get even more % options. % if ~exist('colorByNumber.m') error('You must first write colorByNumber.'); end e % Get codes codes = sort(unique(array(:))); c % Offer to replicate the array if replicate.m is present [r c] = size(array); newwidth = input(['Old width: ' num2str(c) ' New width: ']); newheight = input(['Old height: ' num2str(r) ' New height: ']); array = replicate(array,newwidth,newheight); end e % Build color structure for i = 1:length(codes) fprintf('Make color code %d what color?\n',codes(i)); codestruct(i).number = codes(i); codestruct(i).red = colorinput('Red (0-255): '); codestruct(i).green = colorinput('Green (0-255): '); codestruct(i).blue = colorinput('Blue
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (0-255): '); end e % Do colorByNumber out = colorByNumber(array,codestruct); o % Offer to resize it if exist('resizeImage.m') && printYN('Shrink or stretch image?') fprintf('Input width and height in pixels or percentage (no need for quotes)\ n'); [r c l] = size(out); fprintf('Current size: %dx%d\n',c,r); newwidth = input('New width: ','s'); newheight = input('New height: ','s'); out = resizeImage(out,newwidth,newheight); end e % Show it off imshow(out); i function out = colorinput(prompt) out = -1; while out < 0 | out > 255 try out = input(prompt); catch fprintf('Invalid input. Color should be between 0 and 255.'); out = -1; end end e function out = printYN(prompt) out = 'z'; while ~any(out(1)=='yn') try out = lower(input([prompt ' (Y/N): '],'s')); if isempty(out) out = 'a'; end catch fprintf('Answer "yes" or "no".\n'); out = 'a'; end end out = out(1)=='y';...
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.

Page1 / 2

makeColorByNumber - (0-255): '); end e % Do colorByNumber...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online