function im=mainKurtKluever(im,k) %mainKurtKluever Seam Carving Demo % Removes k number of seams from the input image (im) and displays the % results. Example: % im = imread('faces.jpg'); % mainKurtKluever(im, 20); % javarmpath sf.jar; javaaddpath sf.jar; figure, subplot(2,1,1), imshow(im), title('Original'); for i=1:k fprintf('------------------Removing seam %i\n', i); tic fprintf('Computing energy of image:\t\t'); nrg = computeNRG(im); toc tic fprintf('Initializing SeamFinder java class:\t'); sf = com.kloover.school.compvision.SeamFinder(nrg); toc tic fprintf('Converting im to double im:\t\t'); dim = im2double(im); toc tic fprintf('Finding path through the image:\t\t'); path = sf.findPath(); toc tic fprintf('Removing the seam from the image:\t'); % Change the last parameter of this call to false in order to place % black lines on the image where the seams are instead of actually % removing them from the image. im = sf.removeSeam(dim, path, true); toc end subplot(2,1,2), imshow(mat2gray(im)), title('Seam Carved'); end function G=computeNRG(image) G=zeros(size(image,1),size(image,2)); for i=1:size(image,3) G = G + abs(filter2([1 0 -1; 1 0 -1; 1 0 -1;], image(:,:,i))); end end