Skip to content

Commit

Permalink
done!
Browse files Browse the repository at this point in the history
  • Loading branch information
Yihui-He committed May 7, 2016
1 parent e6f7b85 commit 6a19e7c
Show file tree
Hide file tree
Showing 72 changed files with 259 additions and 105 deletions.
Binary file added .shuffle.bash.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion RANSAC.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [T] = RANSAC(confidence, inliner_Ratio, Npairs, data, epsilon)
function [T,MaxInliers] = RANSAC(confidence, inliner_Ratio, Npairs, data, epsilon)

m = ceil(log(1 - confidence) / log(1 - inliner_Ratio^Npairs)); % calculate number of loops
NPoints = size(data, 1);
Expand Down
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
### panorama

##### features
- [x] use SIFT features
This is my panorama creator, images files are already in ./imgs

##### bonus
I implemented all of the elaborate features described in **BONUS** part.
- I'm able to handle 360 panorama.
- Random sequences is ok.
- I use color blending and smoothing to make the image more continuous.
*details of my algorithms are shown below:*
##### getting features
- [x] use SIFT features(using VLFeat library, professor allowed)
- [x] SURF features, (SIFT is better)

##### 360 panorama
- [x] mapping image to cylindrical coordinate

##### transformation
- [x] boost translate
- [x] homography is not robust
- [x] homography transformation.
- [x] translation transformation.( This is more robust)

##### matching
- [x] boost RANSAC
- [x] RANSAC
- [ ] exposure matching

##### global adjustment
Expand All @@ -22,6 +32,9 @@
- [x] Noblend

##### recognize panorama(random inputs)
- [ ] hard
As described in Brown's paper, I use N_inlier>k\*N_pairs+b to compute whether a pair of images match or not
k,b are const. Set to 5.9 and 0.22 respectively.




2 changes: 1 addition & 1 deletion computeTrans.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
d1 = d2;
[f2, d2] = getSIFTFeatures(imgs(:, :, :, i), Thresh);
[matches, ~] = getMatches(f1, d1, f2, d2);
T(:, :, i) = RANSAC(confidence, inlierRatio, 1, matches, epsilon);
[T(:, :, i),~] = RANSAC(confidence, inlierRatio, 1, matches, epsilon);
end
end

6 changes: 5 additions & 1 deletion create.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
% end to end adjustment
width = size(cylindricalimages, 2);
height = size(cylindricalimages, 1);
panorama_w = abs(round(absoluteTrans(2, 3, end))) + width;
if full360
panorama_w = abs(round(absoluteTrans(2, 3, end))) + width;
% \delta x / \delta y
driftSlope = absoluteTrans(1, 3, end) / absoluteTrans(2, 3, end);

Expand All @@ -45,12 +45,16 @@
maxY = height;
minY = 1;
minX = 1;
maxX=width;
for i = 2 : nImgs
maxY = max(maxY, absoluteTrans(1,3,i)+height);
maxX = max(maxX, absoluteTrans(2,3,i)+width);
minY = min(minY, absoluteTrans(1,3,i));
minX=min(minX,absoluteTrans(2,3,i));
end
panorama_h = ceil(maxY) - floor(minY) + 1;
panorama_w = ceil(maxX)-floor(minX) +1;

absoluteTrans(2, 3, :) = absoluteTrans(2, 3, :) - floor(minX);
absoluteTrans(1, 3, :) = absoluteTrans(1, 3, :) - floor(minY);
end
Expand Down
71 changes: 0 additions & 71 deletions createPanoramaCyl.m~

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
88 changes: 88 additions & 0 deletions imorder.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
function [sorted_imgs]=imorder(imgs)
Thresh = 5;
confidence = 0.999;
inlierRatio = 0.1;
epsilon = 1.5;

nImgs = size(imgs, 4);

T = zeros(3, 3, nImgs);
T(:, :, 1) = eye(3);
imgs_feat{nImgs}={};
imgs_dist{nImgs}={};
for i=1: nImgs
[f, d] = getSIFTFeatures(imgs(:, :, :, i), Thresh);
imgs_feat{i}=f;
imgs_dist{i}=d;
end
ifmatch=zeros(nImgs,nImgs);
transforms{nImgs,nImgs}={};
for i = 1 : nImgs
for j = 1 : nImgs
if j==i
continue
end
[matches, ~] = getMatches(imgs_feat{i}, imgs_dist{i},...
imgs_feat{j}, imgs_dist{j});
[T,nInliers] = ...
RANSAC(confidence, inlierRatio, 1, matches, epsilon);
if nInliers>5.9+.22*length(matches)
ifmatch(i,j)=1;
transforms{i,j}=T;
end
end
end
sequence=[];
sequence(1)=1;
%% forward matching
for i=2:nImgs
nextIdx=find(ifmatch(sequence(i-1),:)==1);
if size(nextIdx,2)==0
break
end
failed=true;
for matched=1:size(nextIdx,2)
if size(find(sequence==nextIdx(matched)),2)==1
continue
end
real_idx=matched;
failed=false;
break
end

if failed==false
sequence(i)=nextIdx(real_idx);
else
break
end
end
%% backward matching
for i=2:nImgs
nextIdx=find(ifmatch(sequence(1),:)==1);
if size(nextIdx,2)==0
break
end
failed=true;
for matched=1:size(nextIdx,2)
if size(find(sequence==nextIdx(matched)),2)==1
continue
end
real_idx=matched;
failed=false;
break
end

if failed==false
sequence=[nextIdx(real_idx),sequence];
else
break
end
end
%% reorder
disp(['using ',int2str(length(sequence)),' of ',int2str(length(imgs(1,1,1,:))),' unordered imgs']);
sorted_imgs=zeros(size(imgs,1),size(imgs,2),size(imgs,3),length(sequence),'like',imgs);
for i=1:length(sequence)
sorted_imgs(:,:,:,i)=imgs(:,:,:,sequence(i));
end


60 changes: 60 additions & 0 deletions imorder.m~
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function [sorted_imgs]=imorder(imgs)
Thresh = 10;
confidence = 0.99;
inlierRatio = 0.3;
epsilon = 1.5;

nImgs = size(imgs, 4);

T = zeros(3, 3, nImgs);
T(:, :, 1) = eye(3);
imgs_feat{nImgs}={};
imgs_dist{nImgs}={};
for i=1: nImgs
[f, d] = getSIFTFeatures(imgs(:, :, :, i), Thresh);
imgs_feat{i}=f;
imgs_dist{i}=d;
end
ifmatch=zeros(nImgs,nImgs);
transforms{nImgs,nImgs}={};
for i = 1 : nImgs
for j = 1 : nImgs
if j==i
continue
end
[matches, ~] = getMatches(imgs_feat{i}, imgs_dist{i},...
imgs_feat{j}, imgs_dist{j});
[T,nInliers] = ...
RANSAC(confidence, inlierRatio, 1, matches, epsilon);
if nInliers>5.9+.22*length(matches)
ifmatch(i,j)=1;
transforms{i,j}=T;
end
end
end
sequence=[];
sequence(1)=1;
for i=2:nImgs
nextIdx=find(ifmatch(sequence(i-1),:)==1);
if size(nextIdx,2)==0
break
end
failed=false;
for i=1:size(nextIdx,2)
if size(find(sequence==nextIdx(i)),2)==1
continue
end
real_idx=i;

break

sequence(i)=nextIdx(1);
end
disp(length(imgs(1,1,1,:)))
disp(length(sequence))
sorted_imgs=zeros(size(imgs,1),size(imgs,2),size(imgs,3),length(sequence),'like',imgs);
for i=1:length(sequence)
sorted_imgs(:,:,:,i)=imgs(:,:,:,sequence(i));
end


37 changes: 23 additions & 14 deletions main.m
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
clear all
%% params

k1=-0;
k2=0;

which=11;
which=8;
path='imgs';

%%
% 1 2bad 3 4 5
% 1 2unorder 3 4 5
datasets={'ucsb4','family_house','glacier4','yellowstone2','GrandCanyon1',...
'yellowstone5','yellowstone4','west_campus1','redrock','intersection',...
...% 6 7 8 9failed 10failed
...% 6 7 8unorder 9 10
'GrandCanyon2'};
% 11 failed

focus=[595,400,2000,1000,1000,1000,1000,1000,1000,1000,1000];
Full360=[0,1,0,0,0,0,0,0,1000,1000,1000];
% 11
% 1 2 3 4 5 6 7 8 9 10 11
focus=[595,400,2000,1000,1000,1000,1000,1000,2000,2000,2000];
Full360=[0,0,0,0,0,0,0,0,0,0,0];
unordered=[0,1,0,0,0,0,0,1,0,0,0];
%%
full=Full360(which);
f=focus(which);
run('lib/vlfeat-0.9.20/toolbox/vl_setup');

disp(['creating panorama for ',datasets{which}])
s=imageSet(fullfile(path,datasets{which}));
img=read(s,1);
imgs=zeros(size(img,1),size(img,2),size(img,3),s.Count,'like',img);
for i=1:s.Count
imgs(:,:,:,i)=read(s,i);
end


if unordered(which)
t=cputime;
disp('ordering unordered images');
imgs=imorder(imgs);
disp([int2str(cputime-t),' sec']);
end


panorama=create( imgs, f, full);
imwrite(panorama,['./results/',datasets{which},'.jpg']);
imwrite(panorama,['./results/',datasets{which},'.jpg']);
if unordered(which)
imwrite(panorama,['./results/',datasets{which},'from unordered.jpg']);
end
Loading

0 comments on commit 6a19e7c

Please sign in to comment.