v=[1:64]; image(v); //generate a default gradient image map=colormap //to see colormap numerically size(map) //ans = 1 3 //to verify the size of the map //Notice that it has 64 rows and three columns. Each row is one entry in the colormap. The three columns give the amounts of red, green, and blue respectively in the colormap. //These amounts range from 0 (none of the color present) to 1.0 (the maximum amount of the color possible). map=gray(256); colormap(map); //generate a plain gray image([1:256]); //generate a gray gradient //grayscale colormap %% Generate a sine wave of black and white color >> for row = 1:200 for col = 1:200 b(row,col) = 128*(1 + cos(2*pi*row/200)); end end >> image(b), axis image map=white(256); axis image //force matlab not to stretch cd U: cd lab02 //change to directory imfinfo('helen.jpg') //get image information helen=imread('helen.jpg'); //image read image(helen); //display image in a stretched version axis image //display image in the original dimension whos //display info of everything in the workspace pixel = helen(1,1,:) //upper left pixel of the image (3 basic colors) //looks like bright color is high number, dark color is small number whos helen //display the array information rgb=squeeze(pixel) //squeeze the info for array of length one %%Template for creating an image numFrames = 15; m = moviein(numFrames); for frame = 1:numFrames; %%... create an image X ... image(X), axis image m(:,frame) = getframe; end movie(m) %% Sinusoidal Movie k = 1:199; map = gray(256);colormap(map); numFrames = 15; m = moviein (numFrames); for frame = 1:numFrames; row_v = (sin(2*pi*k/200+pi/2+frame*pi/2)+1); newimage = 128*repmat(row_v',1,200); image(newimage), axis image m(1,frame) = getframe; end movie(m) %% extract only the red attributes of the image (in gray) red = helen(:,:,1); %% display red info of the pic whos red image(red), axis image %%instruction said to make the image less colorful map = gray(256); colormap(map); %%to display the red portion of the image in red map = gray(256);%%reset the color map colormap(map); helen = imread('helen.jpg');%%reset the image red = helen(:,:,1); image(red), axis image; rowr = [ones(256,1) zeros(256,1) ones(256,1)]; redpic = map .* rowr; colormap(redpic) %%display in green map = gray(256);%%reset the color map colormap(map); helen = imread('helen.jpg');%%reset the image green = helen(:,:,2); image(green), axis image; rowg = [zeros(256,1) ones(256,1) zeros(256,1)]; greenpic = map .* rowg; colormap(greenpic) %%display in blue map = gray(256);%%reset the color map colormap(map); helen = imread('helen.jpg');%%reset the image blue = helen(:,:,3); image(blue), axis image; rowb = [zeros(256,1) zeros(256,1) ones(256,1)]; bluepic = map .* rowb; colormap(bluepic) %% moving average, blurring an image helen = imread('helen.jpg');%%reset the image red = helen(:,:,1); bwImage = double(red); image(bwImage), axis image colormap(gray(256)) newImage = zeros( 295, 195); for i = 3: 297 for j = 3:197 for k = ( i - 2 ): (i + 2) for n = (j - 2 ): (j + 2) %%the average function newImage((i - 2), (j - 2)) = newImage((i - 2), (j - 2)) + bwImage( k, n); end; end; %%divided by 25 because 25 pixels are mapped to 1 pixel newImage((i - 2), (j - 2)) = newImage((i - 2), (j - 2))/25; end; end; image(newImage), axis image; %% edge detection, draw the outline of an image colormap(gray(256)) helen = imread('helen.jpg');%%reset the image red = helen(:,:,1); bwImage = double(red); for i = 2:300 for j = 2:200 if (abs (bwImage(i,j) - bwImage(i-1, j)) >= 30) || (abs (bwImage(i, j) - bwImage (i, j-1)) >= 30) newBwImage (i-1, j-1) = 1; end; end; end; newBwImage = 255* xor (newBwImage, 1); uint8(newBwImage); image(newBwImage); axis image