I = imread('medlines.gif'); %read in a test image I = imnoise(I, 'salt & pepper'); figure(1); imshow(I, []) dim = size(I); %get the size, store it in a 1x2 array J = zeros(dim+4); %make a new image 4 pixels wider and taller than I J(3:dim(1)+2,3:dim(2)+2) = I; %stick I in the middle of J ( we now have I padded with a 2 pixel border) J(:,1) = J(:,4); %take care of padding our extra 4 columns J(:,2) = J(:,3); J(:,dim(2)+3) = J(:,dim(2)+2); J(:,dim(2)+4) = J(:,dim(2)+1); J(1,:) = J(4,:); %take care of padding our extra 4 rows J(2,:) = J(3,:); J(dim(1)+3,:) = J(dim(1),:); J(dim(1)+4,:) = J(dim(1)-1,:); K = MedianFilter(J); %pass our padded image to the MEX routine K = K(3:dim(1)+2,3:dim(2)+2); %throw away the padding figure(2); imshow(K,[0 255]); % show it clear mex %useful for debugging. Otherwise Matlab won’t let go of % the DLL and %Visual Studio can’t compile