Skip to content

Commit

Permalink
Generated scale spaces of images.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinLiang committed Mar 21, 2016
1 parent 395a0e4 commit 5e9a7d5
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 0 deletions.
22 changes: 22 additions & 0 deletions SIFT/MakePyramid.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
% This function makes a pyramid of images
% Minsize dictates the minimum height or width of the smallest image
% in the template
function[pyramid] = MakePyramid(im, octaves)
SCALE = 1.6;
SCALES_PER_OCTAVE = 3;
K = sqrt(2);
RATIO = 0.5;

im = imgaussfilt(im,0.5); % Blur the image before doubling the size
im = imresize(im, 2); % Double the size of the image

pyramid = {}; % Initialize cell array

% Make a pyramid with a specified octave number
for i=1:octaves
for j=1:SCALES_PER_OCTAVE
pyramid{i}{j} = imgaussfilt(im,SCALE*(K^(i-1+j)));
end
im = imresize(im, RATIO);
end
end
Binary file added SIFT/SIFT Papers/SIFT01_Early_iccv99.pdf
Binary file not shown.
Binary file added SIFT/SIFT Papers/SIFT02_RecentSummary_ijcv03.pdf
Binary file not shown.
Binary file added SIFT/SIFT Papers/SIFT03_3Drec_cvpr01.pdf
Binary file not shown.
Binary file added SIFT/SIFT Papers/SIFT04_AffineMatch_bmvc2002.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added SIFT/SIFT Papers/SIFT06M4_VideoRetrieval.pdf
Binary file not shown.
18 changes: 18 additions & 0 deletions SIFT/SIFT.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
% Perform edge detection with interpolation during non maximum suppression
function CannyEdgeDetector()
close all; % Close figures
OCTAVES = 4;

% Change the current folder to the folder of this m-file.
% Courtesy of Brett Shoelson
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

im = imread('Test_Photos\box.jpg');
figure; imshow(im);
title('Original Image');

pyramid = MakePyramid(im,OCTAVES);
ShowPyramid(pyramid);
end
16 changes: 16 additions & 0 deletions SIFT/ShowPyramid.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
% This function shows the pyramid image in a figure
function ShowPyramid(pyramid)
if isempty(pyramid)
return
end

pyramidImage = uint8(0);

for i=1:size(pyramid,2) % Iterate through the 1xn pyramid of images
for j=1:size(pyramid{1})
padadd(pyramidImage,pyramid{i});
end
end

imshow(pyramidImage);
end
22 changes: 22 additions & 0 deletions SIFT/ShowPyramid.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
% This function shows the pyramid image in a figure
function ShowPyramid(pyramid)
if isempty(pyramid)
return
end

pyramidImage = cell(1,size(pyramid,2));
pyramidImage(:) = {uint8(0)};

for i=1:size(pyramid,2) % Iterate through the octaves
for j=1:size(pyramid{1},2) % Iterate through the scales
temp = pyramidImage{i};
padadd(temp, pyramid{i}{j});
pyramidImage{i} = temp;
end
end

for i=1:length(pyramidImage)
figure;
imshow(pyramidImage{i});
end
end
Binary file added SIFT/Test_Photos/box.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SIFT/Test_Photos/scene.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions SIFT/build_pyramid.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
%/////////////////////////////////////////////////////////////////////////////////////////////
%
% build_pyramid - build scaled image pyramid and difference of gaussians pyramid
%
% Usage: [pyr,imp] = build_pyramid(img,levels,scl);
%
% Parameters:
%
% img : original image
% levels : number of levels in pyramid
% scl : scaling factor between pyramid levels
%
% Returns:
%
% pyr : difference of gaussians filtered image pyramid
% imp : image pyramid cell array
%
% Author:
% Scott Ettinger
% scott.m.ettinger@intel.com
%
% May 2002
%/////////////////////////////////////////////////////////////////////////////////////////////

function [pyr,imp] = build_pyramid(img,levels,scl)

img2 = img;
img2 = resample_bilinear(img2,1/2); %expand to retain spatial frequencies

%img2 = imresize(img2,2,'bilinear'); %expand to retain spatial frequencies

sigma=1.5; %variance for laplacian filter
sigma2=1.5; %variance for downsampling

sig_delta = (1.6-.6)/levels;


for i=1:levels

if i==1
img3 = img2;
img2 = filter_gaussian(img2,7,.5); %slightly filter bottom level
end

imp{i}=img2;
A = filter_gaussian(img2,7,sigma); %calculate difference of gaussians
B = filter_gaussian(A,7,sigma);
pyr{i} = A-B; %store result in cell array

if i==1
img2 = img3;
else
B = filter_gaussian(img2,7,sigma2); %anti-alias for downsampling
B = filter_gaussian(B,7,sigma2);
end

img2 = resample_bilinear(B,scl); %downsample for next level

end

%show_pyramid(pyr) %show pyramid if desired

%///////////////////////////////////////////////////////////////////////////////
function show_pyramid(pyr)

close all

[h,w] = size(pyr);
for i=1:w

figure
imagesc(pyr{i});
colormap gray;
end
92 changes: 92 additions & 0 deletions SIFT/padadd.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
function [output] = padadd(A, x, index)
% PADADD Adds data columns to an array even column lengths don't match.
% Missmatched areas of data array are padded with NaNs.
%
% answer = padadd(A, x)
% appends "x" column vector as the last column of "A"
%
% answer = padadd(A, x, index)
% assigns "x" to the column specified by "index" in "A"
% by overwriting any existing data.
%
% If "x" is a matrix, "index" specifies the leftmost column written to.
%
% The result is saved recursively to "A" if the output argument is omitted
% and "A" is a defined variable
%
%Example:
% padadd( eye(2,2), 2*ones(4,1) )
%
% ans =
%
% 1 0 2
% 0 1 2
% NaN NaN 2
% NaN NaN 2
%
%Author: HDJ

%check input argument number
if (nargin < 2)
error('not enough input arguments')
end

%transpose 'x' if it is a row vector
if (size(x,1) == 1) | (size(x,2) == 1) & (size(x,2) > size(x,1))
x = x';
end

%get sizes of 'A' and 'x'
dAr = size(A,1);
dAc = size(A,2);
dxr = size(x,1);
dxc = size(x,2);


if nargin == 2
%if index is not specified
%index = dAc + 1; %default to adding a column to the end
index = dAc + (1:dxc); %default to adding all columns to the end
else
%create index array from index argument
index = index(1)+ (0:dxc-1);
end

%%%%%%BEGIN PADDING SECTION%%%%%%
%if index is outside current size of 'A' then pad whole columns of 'A'
if dAc < index(end)
answer = [A,NaN*ones(dAr,index(end)-dAc)];
else
answer = A;
end

%if 'x' is shorter or the same height as 'A' then pad 'x' as necessary
if dAr >= dxr,
%answer(:,index) = [ x(:,1); NaN*ones(dAr-dxr,1)];
answer(:,index) = [ x; NaN*ones(dAr-dxr,dxc)];
end

%if 'x' is taller than 'A' then pad 'A'
if dAr < dxr,
answer = [answer; NaN*ones(dxr-dAr,size(answer,2))];
%answer(:,index) = x(:,1);
answer(:,index) = x;
end
%%%%%%END PADDING SECTION%%%%%%

%%%%%%DECIDE OUTPUT METHOD%%%%%%
%get input arguments name
ARGIN = inputname(1);
%if no output argument, ouput to A is available
if (nargout == 0)
%if ARG is a variable
if ~(isempty(ARGIN))
assignin('caller', ARGIN, answer);
return
end
end

%default action if either there is an ouput argument
%or if input is not a variable
output = answer;
%%%%%%END DECIDE OUTPUT METHOD%%%%%%

0 comments on commit 5e9a7d5

Please sign in to comment.