Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mjl13 committed Oct 2, 2017
0 parents commit fda52ea
Show file tree
Hide file tree
Showing 730 changed files with 27,845 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/proj1/data
/proj2/data
/proj3/data
/proj4/data
/proj5/data
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is a repo for my Computer Vision (CSCI 1430) projects at Brown. Support code was written by Prof. James Hays and the TA staff. Information on the class can be found at http://cs.brown.edu/courses/csci1430/. All code was written in MATLAB. There are a lot of untracked dependencies that I can’t resolve because I do not have a MATLAB license anymore. I have also omitted a number of the training sets. However, an explanation of my algorithm and results can be found in the html/index.html file.


Project 1: Hybrid Images
Project 2: SIFT
Project 3: Camera Calibration and Fundamental Matrix Estimation
Project 4: Scene Recognition with a Bag of Words
Project 5: Face Detection with a Sliding Window
Project 6: Convolutional Neural Networks
Binary file added proj1/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions proj1/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is my readme. I have no information to include that is not in the html.
Binary file added proj1/code/.DS_Store
Binary file not shown.
Binary file added proj1/code/high_frequencies1.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 proj1/code/high_frequencies2.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 proj1/code/high_frequencies3.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 proj1/code/hybrid_image1.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 proj1/code/hybrid_image2.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 proj1/code/hybrid_image3.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 proj1/code/hybrid_image_scales1.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 proj1/code/hybrid_image_scales2.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 proj1/code/hybrid_image_scales3.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 proj1/code/low_frequencies1.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 proj1/code/low_frequencies2.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 proj1/code/low_frequencies3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions proj1/code/my_imfilter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function output = my_imfilter(image, filter)
% mirrors functionality of the built in imfilter function
image_pad = pad_image(image, filter);
filter = rot90(filter, 2);
output = [];
[image_height, image_width, colors] = size(image);
[filter_height, filter_width] = size(filter);
rows_to_pad = floor((filter_height-1)/2);
cols_to_pad = floor((filter_width-1)/2);

for p = 1:colors
for m = (1+rows_to_pad):(rows_to_pad+image_height) % 2:4
for n = (1+cols_to_pad):(cols_to_pad+image_width) % 2:4
p_val = filter_pixel([m n p], image_pad, filter);
output(m-rows_to_pad, n-cols_to_pad, p) = p_val;
end
end
end
end

function pix_val = filter_pixel(index, image_padded, filter)
% returns the filtered pixel value at a specified index
[f_height, f_width] = size(filter);
row_bound_low = index(1) - floor(f_height/2);
row_bound_upp = index(1) + floor(f_height/2);
col_bound_low = index(2) - floor(f_width/2);
col_bound_upp = index(2) + floor(f_width/2);
color = index(3);
sub_mat = image_padded(row_bound_low:row_bound_upp, col_bound_low:col_bound_upp, color);
pix_val = sum(sum(sub_mat.*filter));
end

function padded_image = pad_image(image, filter)
% Takes an image and pads it appropriately given a filter
[image_height, image_width] = size(image);
[filter_height, filter_width] = size(filter);
rows_to_pad = floor((filter_height-1)/2);
cols_to_pad = floor((filter_width-1)/2);
padded_image = padarray(image, [rows_to_pad cols_to_pad]);
end
121 changes: 121 additions & 0 deletions proj1/code/proj1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
% Before trying to construct hybrid images, it is suggested that you
% implement my_imfilter.m and then debug it using proj1_test_filtering.m

% Debugging tip: You can split your MATLAB code into cells using "%%"
% comments. The cell containing the cursor has a light yellow background,
% and you can press Ctrl+Enter to run just the code in that cell. This is
% useful when projects get more complex and slow to rerun from scratch

close all; % closes all figures

%% Setup
% read images and convert to floating point format
% image1 = im2single(imread('../data/dog.bmp'));
% image2 = im2single(imread('../data/cat.bmp'));

% Several additional test cases are provided for you, but feel free to make
% your own (you'll need to align the images in a photo editor such as
% Photoshop). The hybrid images will differ depending on which image you
% assign as image1 (which will provide the low frequencies) and which image
% you asign as image2 (which will provide the high frequencies)

%% Filtering and Hybrid Image construction
cutoff_frequency1 = 5;
cutoff_frequency2 = 5;
cutoff_frequency3 = 4;
cutoff_frequency4 = 7;
cutoff_frequency5 = 5;
cutoff_frequency6 = 2;
% This is the standard deviation, in pixels, of the
% Gaussian blur that will remove the high frequencies from one image and
% remove the low frequencies from another image (by subtracting a blurred
% version from the original version). You will want to tune this for every
% image pair to get the best results.
filter1 = fspecial('Gaussian', cutoff_frequency1*4+1, cutoff_frequency1);
filter2 = fspecial('Gaussian', cutoff_frequency2*4+1, cutoff_frequency2);
filter3 = fspecial('Gaussian', cutoff_frequency3*4+1, cutoff_frequency3);
filter4 = fspecial('Gaussian', cutoff_frequency4*4+1, cutoff_frequency4);
filter5 = fspecial('Gaussian', cutoff_frequency5*4+1, cutoff_frequency5);
filter6 = fspecial('Gaussian', cutoff_frequency6*4+1, cutoff_frequency6);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% YOUR CODE BELOW. Use my_imfilter to create 'low_frequencies' and
% 'high_frequencies' and then combine them to create 'hybrid_image'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Remove the high frequencies from image1 by blurring it. The amount of
% blur that works best will vary with different image pairs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
low_source1 = im2single(imread('../data/bicycle.bmp'));
low_filtered1 = my_imfilter(low_source1, filter1);
low_frequencies1 = low_filtered1;

low_source2 = im2single(imread('../data/dog.bmp'));
low_filtered2 = my_imfilter(low_source2, filter3);
low_frequencies2 = low_filtered2;

low_source3 = im2single(imread('../data/bird.bmp'));
low_filtered3 = my_imfilter(low_source3, filter5);
low_frequencies3 = low_filtered3;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Remove the low frequencies from image2. The easiest way to do this is to
% subtract a blurred version of image2 from the original version of image2.
% This will give you an image centered at zero with negative values.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

high_source1 = im2single(imread('../data/bicycle.bmp'));
high_filtered1 = my_imfilter(high_source1, filter2);
high_frequencies1 = high_source1-high_filtered1;

high_source2 = im2single(imread('../data/cat.bmp'));
high_filtered2 = my_imfilter(high_source2, filter4);
high_frequencies2 = high_source2-high_filtered2;

high_source3 = im2single(imread('../data/plane.bmp'));
high_filtered3 = my_imfilter(high_source3, filter6);
high_frequencies3 = high_source3-high_filtered3;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Combine the high frequencies and low frequencies
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

hybrid_image1 = high_frequencies1+low_frequencies1;
hybrid_image2 = high_frequencies2+low_frequencies2;
hybrid_image3 = high_frequencies3+low_frequencies3;



%% Visualize and save outputs
figure(1); imshow(low_frequencies1)
figure(2); imshow(high_frequencies1 + 0.5);
vis = vis_hybrid_image(hybrid_image1);
figure(3); imshow(vis);
imwrite(low_frequencies1, 'low_frequencies1.jpg', 'quality', 95);
imwrite(high_frequencies1 + 0.5, 'high_frequencies1.jpg', 'quality', 95);
imwrite(hybrid_image1, 'hybrid_image1.jpg', 'quality', 95);
imwrite(vis, 'hybrid_image_scales1.jpg', 'quality', 95);

figure(3); imshow(low_frequencies2)
figure(4); imshow(high_frequencies2 + 0.5);
vis = vis_hybrid_image(hybrid_image2);
figure(5); imshow(vis);
imwrite(low_frequencies2, 'low_frequencies2.jpg', 'quality', 95);
imwrite(high_frequencies2 + 0.5, 'high_frequencies2.jpg', 'quality', 95);
imwrite(hybrid_image2, 'hybrid_image2.jpg', 'quality', 95);
imwrite(vis, 'hybrid_image_scales2.jpg', 'quality', 95);

figure(6); imshow(low_frequencies3)
figure(7); imshow(high_frequencies3 + 0.5);
vis = vis_hybrid_image(hybrid_image3);
figure(8); imshow(vis);
imwrite(low_frequencies3, 'low_frequencies3.jpg', 'quality', 95);
imwrite(high_frequencies3 + 0.5, 'high_frequencies3.jpg', 'quality', 95);
imwrite(hybrid_image3, 'hybrid_image3.jpg', 'quality', 95);
imwrite(vis, 'hybrid_image_scales3.jpg', 'quality', 95);




78 changes: 78 additions & 0 deletions proj1/code/proj1_test_filtering.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
% this script has test cases to help you test my_imfilter() which you will
% write. You should verify that you get reasonable output here before using
% your filtering to construct a hybrid image in proj1.m. The outputs are
% all saved and you can include them in your writeup. You can add calls to
% imfilter() if you want to check that my_imfilter() is doing something
% similar.
close all

%% Setup
% test_image = im2single(rgb2gray(imread('../data/cat.bmp')));
test_image = im2single(imread('../data/cat.bmp'));
test_image = imresize(test_image, 0.7, 'bilinear'); %resizing to speed up testing
figure(1)
imshow(test_image)

%% Identify filter
%This filter should do nothing regardless of the padding method you use.
identity_filter = [0 0 0; 0 1 0; 0 0 0];

identity_image = my_imfilter(test_image, identity_filter);

figure(2); imshow(identity_image);
imwrite(identity_image, 'identity_image.jpg', 'quality', 95);

%% Small blur with a box filter
%This filter should remove some high frequencies
blur_filter = [1 1 1; 1 1 1; 1 1 1];
blur_filter = blur_filter / sum(sum(blur_filter)); %making the filter sum to 1

blur_image = my_imfilter(test_image, blur_filter);

figure(3); imshow(blur_image+0.5);
imwrite(blur_image, 'blur_image.jpg', 'quality', 95);

%% Large blur
%This blur would be slow to do directly, so we instead use the fact that
%Gaussian blurs are separable and blur sequentially in each direction.
large_1d_blur_filter = fspecial('Gaussian', [25 1], 10);

large_blur_image = my_imfilter(test_image, large_1d_blur_filter);
large_blur_image = my_imfilter(large_blur_image, large_1d_blur_filter'); %notice the ' operator which transposes the filter

figure(4); imshow(large_blur_image);
imwrite(large_blur_image, 'large_blur_image.jpg', 'quality', 95);

% %If you want to see how slow this would be to do naively, try out this
% %equivalent operation:
% tic %tic and toc run a timer and then print the elapsted time
% large_blur_filter = fspecial('Gaussian', [25 25], 10);
% large_blur_image = my_imfilter(test_image, large_blur_filter);
% toc

%% Oriented filter (Sobel Operator)
sobel_filter = [-1 0 1; -2 0 2; -1 0 1]; %should respond to horizontal gradients

sobel_image = my_imfilter(test_image, sobel_filter);

%0.5 added because the output image is centered around zero otherwise and mostly black
figure(5); imshow(sobel_image + 0.5);
imwrite(sobel_image + 0.5, 'sobel_image.jpg', 'quality', 95);


%% High pass filter (Discrete Laplacian)
laplacian_filter = [0 1 0; 1 -4 1; 0 1 0];

laplacian_image = my_imfilter(test_image, laplacian_filter);

%0.5 added because the output image is centered around zero otherwise and mostly black
figure(6); imshow(laplacian_image + 0.5);
imwrite(laplacian_image + 0.5, 'laplacian_image.jpg', 'quality', 95);

%% High pass "filter" alternative
high_pass_image = test_image - blur_image; %simply subtract the low frequency content

figure(7); imshow(high_pass_image + 0.5);
imwrite(high_pass_image + 0.5, 'high_pass_image.jpg', 'quality', 95);

%by James Hays
26 changes: 26 additions & 0 deletions proj1/code/vis_hybrid_image.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function output = vis_hybrid_image(hybrid_image)
%visualize a hybrid image by progressively downsampling the image and
%concatenating all of the images together.

scales = 5; %how many downsampled versions to create
scale_factor = 0.5; %how much to downsample each time
padding = 5; %how many pixels to pad.

original_height = size(hybrid_image,1);
num_colors = size(hybrid_image,3); %counting how many color channels the input has
output = hybrid_image;
cur_image = hybrid_image;

for i = 2:scales
%add padding
output = cat(2, output, ones(original_height, padding, num_colors));

%dowsample image;
cur_image = imresize(cur_image, scale_factor, 'bilinear');
%pad the top and append to the output
tmp = cat(1,ones(original_height - size(cur_image,1), size(cur_image,2), num_colors), cur_image);
output = cat(2, output, tmp);
end


%code by James Hays
Binary file added proj1/html/.DS_Store
Binary file not shown.
Binary file added proj1/html/bikebike_high_frequencies.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 proj1/html/bikebike_hybrid_image.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 proj1/html/bikebike_hybrid_image_scales.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 proj1/html/bikebike_low_frequencies.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 proj1/html/birdplane_high_frequencies.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 proj1/html/birdplane_hybrid_image.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 proj1/html/birdplane_hybrid_image_scales.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 proj1/html/birdplane_low_frequencies.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 proj1/html/catdog_high_frequencies.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 proj1/html/catdog_hybrid_image.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 proj1/html/catdog_hybrid_image_scales.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 proj1/html/catdog_low_frequencies.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions proj1/html/highlighting/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2006, Ivan Sagalaev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of highlight.js nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit fda52ea

Please sign in to comment.