You are on page 1of 11

Image Piocessing: Assignment

ueometiical Tiansfoim


















Bote: 84..
Nome looto 5tol l esco
AJJtess colslooo 285 2lp 7522Mc oscbeJe
mol l l lstol l escostoJeototweoteol
5toJeot Nombet 5107005J
Jocotloool ltoqtom lecttl col oqloeetloq 1el ecommool cotl oo Netwotks


694.;;1 !ndent: Left: 4.S", Space After: 10
pt, Line spacing: Nultiple 1.1S li


1he purpose of Lhls exerclse ls sLlLchlng a whole map ouL of Lwo
parLlallyoverlapplng lmages by applylng a geomeLrlcal Lransform Lo Lhe second lmage

I|gure 1Sch|er_|eft[pg and Sch|er_r|ght[pgtwo segments of the same map

1 lnd Lhe approprlaLe MaLlab Lransform for Lhls appllcaLlon and moLlvaLe your cholce
rom Lhe avallable Lransforms (moketfotm afflne pro[ecLlve cusLom box composlLe and
Lhe exLra ones broughL by cp2tfotm nonreflecLlve slmllarlLy slmllarlLy polynomlal plecewlse llnear
local welghLed mean ) l belleve LhaL ln general Lhe besL way Lo model a LransformaLlon ls Lhrough a
cusLom meLhod whlch granLs you Lhe posslblllLy Lo adapL Lo more dlverse LransformaLlon effecLs
ln our case Lhough we cannoL model such a meLhod slnce we have Loo llLLle lnformaLlon
abouL Lhe condlLlons ln whlch Lhe plcLures were Laken and modlfled (lf Lhe case)
Slnce Lhe poslLlon and orlenLaLlon of Lhe camera are dlfferenL relaLlve Lo Lhe Lwo map
segmenLs Lhere ls a ptojectlve LransformaLlon lnvolved ln Lhe lmage acqulslLlon process 1hls can be
a hlnL ln chooslng Lhe rlghL approach lf we conslder Lhe offloe LransformaLlon a parLlcular case of Lhe
pro[ecLlve one meanlng LhaL ln Lhe offloe case we conslder Lhe vanlshlng polnL Lo be slLuaLed aL
lnflnlLy
8y vlsually evaluaLlng Lhe Lwo lmages we cannoL Lell lf Lhe apparenLlyparallel llnes are really
parallel or Lhey are converglng aL a really small devlaLlon from Lhelr lnlLlal orlenLaLlon
or plcklng Lhe rlghL Lransform l chose Lhe mlnlmum number of conLrol polnLs needed for
each Lransform and verlfled Lhe resulLs As deducLed from Lhe formulas for each LransformaLlon we
need Lhree palrs of conLrol polnLs (slx coordlnaLes on boLh axes) for Lhe afflne Lransform and four
palrs (elghL coordlnaLes on boLh axes) for Lhe pro[ecLlve one Lo obLaln Lhe used parameLers value

Afflne
Y

Y Y
Y

XY XY X

ro[ecLlve

Y

Y Y
XY XY X

Y

XY XY X
XY XY X


8y showlng Lhe reconsLrucLed lmages (see lgure 2) afLer applylng flrsL Lhe afflne Lransform
wlLh Lhree palrs of conLrol polnLs and Lhen Lhe pro[ecLlve Lransform wlLh four palrs Lhe resulL was ln
favour of Lhe afflne Lransform


I|gure 2 Lowerr|ght corner of the |mage after app|y|ng success|ve|y the aff|ne transformat|on w|th
3 pa|rs of contro| po|nts and the pro[ect|ve transformat|on w|th 4 pa|rs of contro| po|nts
8y seLLlng a larger number of conLrol polnLs we mlghL expecL some lmprovemenLs slnce Lhe
LransformaLlon should be beLLer modeled 1he lmprovemenLs were very small as seen ln lgure 3 so
Lhere was no concluslve observaLlon Lo be drawn 1he small mlsallgnmenL could be due Lo Lhe
manual seLLlng of Lhe conLrol polnLs alLhough for mosL of Lhe palr l used predlcLed correspondenLs ln
Lhe Lwo lmages
1he besL way Lo solve Lhls problem was verlfylng lf parallel llnes were lndeed kepL parallel
Lhrough afflne LransformaLlon lf Lhls would have been Lhe case Lhen Lhe pro[ecLlve LransformaLlon
would have had no [usLlflcaLlon rom boLh plcLures l plcked Lwo seLs of parallel llnes and checked lf
Lhe angles would lndeed be kepL ln Lhe resulLed lmage
Us|ng a Mat|ab |mp|emented ang|e computat|on funct|on (see







ALnulx A) l found ouL LhaL Lhe llnes lndeed do noL keep Lhelr angles aL Lhelr lnlLlal values
buL presenL a varlaLlon of 2
o
3
o
ln Lhe sense of llnes focuslng ln one polnL So lndeed we need a
pro[ecLlve LransformaLlon

I|gure 3 ro[ect|ve transformed |mage (|eft) and Aff|ne transformed |mage (r|ght) both w|th 16
pa|rs of contro| po|nts


I|gure 4 Ang|e preservat|on |n the two segments the upper ang|e drops from 88 to 86 degrees and
the |ower ang|e |ncreases from 91 to 94 degrees

2 wbot ls tbe mlolmol oombet of cottespooJloq polots tbot ls oeeJeJ to Jefloe tbls
ttoosfotm? wby?
ln a pro[ecLlve LransformaLlon quadrllaLerals map Lo quadrllaLerals SLralghL llnes remaln
sLralghL Afflne LransformaLlons as sald before are a subseL of pro[ecLlve LransformaLlons ro[ecLlve
LransformaLlon can brlng flnlLe polnLs ln Lhe flnlLe range Lo lnflnlLy and Lhe oLher way around or
example lf Lhe lnner producL of a polnL ln homogenous coordlnaLe and Lhe lasL row of Lhe
LransformaLlon maLrlx ls zero Lhen Lhe lasL dlmenslon would become zero and Lhe resulLlng polnL ls
aL lnflnlLy A clrcle ln a homogenous coordlnaLe sysLem would become a parabola ln Lhe pro[ecLlve
sysLem
As dlscussed ln Lhe prevlous exerclse Lhe number of polnLs needed Lo deflne a
LransformaLlon ls glven by Lhe number of parameLers ln lLs expresslon 8y havlng Lhe full seL of
parameLers (a b c d e f g h l) we can correcLly pro[ecL one seL of coordlnaLes (polnL segmenL
shape seml plane eLc) lnLo Lhe correspondlng seL of Lhe second coordlnaLe sysLem lf only one
LransformaLlon ls reallsed Lhe coefflclenLs are mapped ln a 3by3 Lransform maLrlx and aL leasL four
conLrolpolnLs palrs are needed Lo solve for Lhe nlne unknown coefflclenLs
lf more Lhan one LransformaLlon ls used Lhe LransformaLlon coefflclenLs musL be arranged as
a byNmaLrlx where n ls Lhe number of LransformaLlons
1he varlaLlon of Lhe parameLers need for applylng Lhe dlfferenL Lransforms comes from Lhe
dlsplacemenLs and varlaLlons each Lransform handles 1he pro[ecLlve Lransform has exLra parameLers
wlLh respecL Lo Lhe afflne one due Lo Lhe facL LhaL lL handles also angle varlaLlons

J cteote ooJ execote oo mflle tbot Jefloes o set of cottespooJloq polots
1he compleLe code ls aLLached ln Lhe ALnulx secLlon or Lhls subexerclse l used Lhe
synLax

% input_points, base_points, = cpselect(input,base,'Wait', true);
B=rgb2gray(base);
I=rgb2gray(input);
input_pts = cpcorr(cpstruct.inputPoints,cpstruct.basePoints, I,B);

1he flrsL row wlll be found commenLed ln Lhe code because l only used lL once Lo seL Lhe
proper values for my conLrolpolnLs palrs and saved Lhe obLalned sLrucLure ln cpsttoctmot 1o
opLlmlse Lhe polnLs chosen l used Lhe predlcLor found ln Lhe funcLlon's Cul and Lhe cpcott funcLlon
for ad[usLlng Lhe values ln Lhe lnpuL_polnLs fleld
1he conLrol polnLs correlaLor crosscorrelaLes a 11x11 area around Lhe lnpuL conLrol polnLs
wlLh a 21x21 area around Lhe correspondlng base conLrol polnLs Where lL flnds a crosscorrelaLlon
peak lL seLs Lhe found poslLlon as an ad[usLed" value of Lhe old lnpuL conLrol polnL
All conLrol polnLs were chosen ln Lhe common area namely beLween 7
o
and 13
o
longlLude
merldlans deplcLed ln Lhe map


4 cteote ooJ execote oo mflle tbot oses tbe set of cottespooJloq polots ooJ cteotes o
ttoosfotmotloo sttoctote
np=16;
transf = cp2tform(input_pts(1:np,:), cpstruct.basePoints(1:np,:),
'projective');

ln Lhe slnLax for creaLlng Lhe Lransform we use Lhe ad[usLed polnL palrs and Lhe 'pro[ecLlve'
Lype of LransformaLlon afLer Lhe resulLs found ln exerclse 1 WlLh Lhe help of Lhe op varlable l could
vary Lhe number of conLrolpolnLs Lo use for consLrucLlng Lhe Lransform Pere lL has Lhe maxlmum
value slnce cpsttoct has 16 enLrles

5 xteoJ tbe mflle of 4 opply tbe ttoosfotm to tbe secooJ lmoqe by osloq tbe
ttoosfotmotloo sttoctote lo lmttoosfotm
reg = imtransform( input,transf,...
'XData', 1 size(base,2)+ size(input,2)/2,,...
'YData', 1 size(base,1),);

or sLlLchlng Lhe Lwo lmages LogeLher l consldered easler Lo copy Lhe lefL slde of Lhe map on
Lo Lhe Lransformed rlghL parL slnce lL we know Lhe coordlnaLe of Lhe lefLmosL polnLs of Lhe map
1herefore l creaLed Lhe Lransformed teq lmage large enough Lo hosL boLh lmages by addlng an
offseL ln Lhe horlzonLal axls slnce Lhls was Lhe dlrecLlon on whlch Lhe dlmenslon varled mosL 1he
resulLed lmage ls deplcLed ln rror! keference source not found
When Lhe ouLpuLspace locaLlons of Lhe Lransformed lmage are noL speclfled lmttoosfotm
auLomaLlcally uses floJboooJs Lo compuLe Lhem or Lhe pro[ecLlve LransformaLlon Lhls funcLlon ls
sufflclenLly fasL

I|gure S 1he pro[ected sch|er_r|ght[pg after co|or ba|anc|ng

copy1 tbe fltst lmoqe to tbe ttoosfotmeJ lmoqe obtoloeJ lo 5
final = stitch(reg,base,1,1);
figure, imshow(final,,);
where Lhe funcLlon stltcb ls Lhe one glven below
function complete = stitch(complete, initial, row,col)
complete( row:size(initial,1) + row - 1,...
col:size(initial,2) + col- 1, ...
:) = initial;
end

I|gure 6 the reconstructed map after exposure compensat|on |nterpo|at|on and co|or ba|anc|ng

7 lotetptet tbe tesolts coo yoo lJeotlfy posslble ptoblems?

1he whlLe balance of Lhe Lwo plcLures ln dlfferenL so color compensaLlon was needed Slnce
any grayscale value can be decomposed ln 8 C 8 values followlng Lhe formula welghLs
C02989 * 8 + 03870 * C + 01140 * 8
l ad[usLed Lhe colour composlLlon ln Lhe Lransformed lmage only afLer Lhe red and green
componenLs (Lhey are accounLed for 8839 of Lhe colour) whlch musL be found ln a raLlo of
8/C02989/03870 03092

I|gure 7 1he h|stograms of sch|er_r|ght |mage before(|eft) and after (r|ght) co|or ba|anc|ng w|th the representat|on of the
kG8 components

Also l applled a llnear lnLerpolaLlon of Lhe rlghL lmage ln for a sllghLly beLLer deLall and for
compensaLlng for avoldlng offseL dlscrepancles LhaL mlghL appear when sLlLchlng Lhe lmages
LogeLher due Lo Lhe even/ odd number of plxels on each dlrecLlon
1he exposure compensaLlon facLor was chosen manually and alLhough lL brlngs an
lmprovemenL lL ls cerLalnly noL Lhe besL opLlon

SLlll Lhe lmages don'L blend perfecLly due Lo
O Lhe manual ad[usLlng of colour componenLs
O Lhe auLomaLlc scallng dld by Lhe lmttoosfotm funcLlon l couldn'L esLlmaLe Lhe
scallng facLor so lL was compuLed from Lhe lnpuL plxels scale and Lhe lnpuL lmage
scale mlghL noL be perfecLly equal Lo Lhe base one's
O Lhe approxlmaLlons made by Lhe lnLerpolaLlon colour compensaLlon (approxlmaLlng
all Lhe negaLlve values obLalned by subLracLlon wlLh zero)offseLs converslon Lo
double
O nonllnear lens dlsLorLlons and oLher facLors











APPENDIX A

function angle_mesure(im)
figure('Name','My Angle Measurement Tool','NumberTitle','off',...
'IntegerHandle','off');
imshow(im)
m = size(im,1);
n = size(im,2);

% Get center point of image for initial positioning.
midy = ceil(m/2);
midx = ceil(n/2);

694.;;1 Font: Not !talic, Dutch
(Netherlands), Not Expanded by / Condensed by
694.;;1 Dutch (Netherlands)
694.;;1 Font: Not !talic, Dutch
(Netherlands), Not Expanded by / Condensed by
694.;;1 Dutch (Netherlands)
% Position first point vertically above the middle.
firstx = midx;
firsty = midy - ceil(m/4);
lastx = midx + ceil(n/4);
lasty = midy;

% Create a two-segment right-angle polyline centered in the image.
h = impoly(gca,firstx,firsty;midx,midy;lastx,lasty,,'Closed',false);
api = iptgetapi(h);
initial_position = api.getPosition();

% Display initial position
updateAngle(initial_position)

% set up callback to update angle in title.
api.addNewPositionCallback(@updateAngle);
fcn = makeConstrainToRectFcn('impoly',get(gca,'XLim'),get(gca,'YLim'));
api.setPositionConstraintFcn(fcn);
%

% Callback function that calculates the angle and updates the title.
function updateAngle(p)

% Create two vectors from the vertices.
% v1 = x1 - x2, y1 - y2,
% v2 = x3 - x2, Y3 - y2,
v1 = p(1,1)-p(2,1), p(1,2)-p(2,2),;
v2 = p(3,1)-p(2,1), p(3,2)-p(2,2),;

% Find the angle. Convert it to degrees.
theta = acos(dot(v1,v2)/(norm(v1)norm(v2)));
angle_degrees = (theta (180/pi));

% Display the angle in the title of the figure.
title(sprintf('(%1.0f) degrees',angle_degrees))

n Motlob nelp lmoqe ltocessloq 1oolbox usets ColJe bollJloq Culs wltb MoJolot tools
cteotloq oot Owo MoJolot 1ools xomple cteotloq oo Aoqle Meosotemeot 1ool


APPENDIX B
clc
close all
clear all
load cpstruct.mat

%1.Read the two images
base= im2double(imread('schier_left.jpg'));
input= im2double(imread('schier_right.jpg'));

%Compensating for the colour difference between the two images
input(:,:,1) = input(:,:,1) - 0.2;
694.;;1 Font: Not !talic, Dutch
(Netherlands), Not Expanded by / Condensed by
694.;;1 Dutch (Netherlands)
input(:,:,2)= input(:,:,2) - 0.12;

% Bring the minimum of the image back to zero
input(input<0)=0;

%2.Select the control points

% input_points, base_points, = cpselect(input,base,'Wait', true);


%3.Fine tune the control points selection
B=rgb2gray(base); % Converting the base and input images into
I=rgb2gray(input); % Graylevel images to be able to apply cpcorr

input_pts = cpcorr( cpstruct.inputPoints,cpstruct.basePoints, I,B);


%4.Create the transformation structure using the adjusted control points
clear I;
clear B;
np=16; %Use np for tuning the number of control points
transf = cp2tform(input_pts(1:np,:),cpstruct.basePoints(1:np,:),
'projective');

%Create an interpolation function
interpol = makeresampler('linear', 'fill');

%5. Apply the transform
reg = imtransform( input, transf, interpol, 'XData', 1 size(base,2)+
+size(input,2)/2,, 'YData', 1 size(base,1),);
figure, imshow(reg);

%Exposure compensation and dynamic range increase
reg = 1.33 reg;

%6. Copy the two segments in one image
final = array_overwrite(reg,base,1,1);
figure, imshow(final,,);

You might also like