a_raw = imread('potato03.jpg','jpeg'); % reads image file into 3d array a_raw(:,:,:). The last index % of a_raw goes from 1:3 and indexes the R, G, B color % values of the image, respectively. a_big = sum(a_raw,3); % sums up RGB values to get "intensity" of each pixel. imagesc(a_big); axis('image'); drawnow; % see the image in false color pause colormap(gray); pause % or convert to gray scale % The a_big array is probably too large (too many pixels) to be directly % useful in your model. You'll need to sample or interpolate somehow to % reduce it's size. Here are a couple of ways to do that. % This just samples every fifth pixel [m_big,n_big] = size(a_big); a_smaller1 = a_big(1:5:m_big,1:5:n_big); imagesc(a_smaller1); axis('image'); pause % This interpolates the image to any size grid desired, say (mi x ni) % mi = 32; ni = 64; [X,Y] = meshgrid([0:(n_big-1)]/(n_big-1),[0:(m_big-1)]/(m_big-1)); [Xi,Yi] = meshgrid([0:ni-1]/(ni-1),[0:mi-1]/(mi-1)); a_smaller2 = interp2(X,Y,a_big,Xi,Yi); imagesc(a_smaller2); axis('image'); pause % Finally, here's how to use the conv2 function to blur an image % I'll make g(x,y) a gaussian for simplicity. You'll use the g as we computed % in class. [xg,yg] = meshgrid([-8:8]/8,[-8:8]/8); % generates a 17x17 grid indexing [-1,1]x[-1,1]; gfun = exp(-4*pi*(xg.^2 + yg.^2)); % gfun is a gaussian a_new = conv2(gfun,a_smaller2); % do the convolution imagesc(a_new); axis('image');