% CS143, Intro to Computer Vision, Michael Black % Matlab code for lecture 5 (pyramids and edges) im=double(imread('barbara.tif')); % plot a 1D signal that shows what edges look like plot(im(250,:)) % build our Gaussian filter G=fspecial('gaussian',3,1); % smooth the image a few times cim = imfilter(im,G,'symmetric','conv'); cim = imfilter(cim,G,'symmetric','conv'); cim = imfilter(cim,G,'symmetric','conv'); % plot the smoothed intensity profile s=cim(250,:); plot(s) % look at the smoothed image imagesc(cim) % plot the first difference of the smoothed signal % Note that I cut off the ends of the signal. clf ds=(s(3:length(s)-1)-s(2:length(s)-2)); plot(ds); hold on plot((s(2:length(ds))-mean(s))/5,'r'); % Simple example of an edge: clf im=zeros(100,100); im(:,1:30)=100; im(:,70:100)=100; imagesc(im) cim = imfilter(im,G,'symmetric','conv'); cim = imfilter(cim,G,'symmetric','conv'); cim = imfilter(cim,G,'symmetric','conv'); imagesc(cim) % plot original image intensity along a line clf plot(cim(50,:)); % plot smoothed intensity % cut off ends to remove boundary effects sim=cim(5:95,5:95); plot(sim(50,:)) % compute and plot the first derivative using finite differences sderiv=(sim(50,2:size(sim,1))-sim(50,1:size(sim,1)-1)); plot(sderiv) % compute and plot the second derivative sderiv2=sderiv(2:length(sderiv))-sderiv(1:length(sderiv)-1); plot(sderiv2)