📄 fm_guifun.m
字号:
function fm_guifun(action)
% GUI functions for Fourier-Mellin transform GUI
%
% Adam Wilmer, aiw99r@ecs.soton.ac.uk
% Colormap
m = gray(256);
switch(action)
% Init %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case('create')
data.pathname = 'C:\Documents and Settings\aiw99r\My Documents\My Pictures\'; % path pointing to data
% ------------------- window handle storage --------------------
data.hmain = get(findobj(gcbf,'Tag','Fig1'));
% --------- IMAGE 1 ---------------------------------------------------
data.input1reference = [];
data.input1 = []; % image data
data.input1_windowed = [];
data.input1_freq = [];
data.input1_magSpec = [];
data.input1_freq_lp = [];
data.windowed_input1_freq_lp = [];
data.logmagspec_lp_ms1 = [];
data.filename1 = []; % filename corresponding to image 1
% --------- IMAGE 2 ------------------------------------------------------
data.input2reference = [];
data.input2 = [];
data.input2_windowed = [];
data.input2_freq = [];
data.input2_magSpec = [];
data.input2_freq_lp = [];
data.windowed_input2_freq_lp = [];
data.logmagspec_lp_ms2 = [];
data.filename2 = []; % filename corresponding to image 2
% -------- SOME FOURIER-MELLIN PARAMETERS ------------------------
data.logpolarScaleRes = 256; % arguments for imlogpolar() function - they control resolution of the log-polar plot
data.logpolarAngleRes = 256;
data.autocrop = 0; % automatically crop inputs after resizing
data.windowType = 'none'; % default window type
data.RotInterp = 'nearest'; % the default interpolations to use
data.SclInterp = 'nearest';
data.LogInterp = 'nearest';
data.dispText = 0;
data.performanceLevel = 1;
data.windowScale = 0;
% -------- REGISTERED IMAGE --------------------------------------
data.registered = []; % registered image matrix
data.input1registered = [];
data.input2registered = [];
data.pc_rs = []; % phase correlation for the log-polar form
data.pc_trans = [];
set(gcbf,'Userdata',data);
set(findobj(gcbf,'Tag','CropInput2'),'String',[num2str(100) '%']);
% Load image 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case('loadA')
dispText('','b');
data = get(gcbf,'Userdata');
pathname = data.pathname;
dispTag('Ref_im','r'); % this stuff isn't that apparent in the aplication??!!
dispText('Loading image 1','b');
[filename, pathname] = uigetfile([pathname '*.*'], 'Load image 1'); % GUI file browser
if filename~=0 % if we have a file
if isempty(findstr(filename,'pgm')) % if not a PGM
[M1,ma] = imread([pathname, filename]);
if isind(M1) & ~isempty(ma)
M1 = 256*double(ind2gray(M1,ma));
else
if isgray(M1)
M1 = double(M1);
else
M1 = double(rgb2gray(M1));
end;
end;
else % if it is a PGM
cesta=strrep([pathname, filename],'.pgm',''); % strip off the .pgm bit for some reason
M1=readpgm(cesta); % special pgm reader?!!
end;
data.input1reference = M1;
data.input1 = M1;
data.input1_windowed = window2d(size(M1,1),size(M1,2),data.windowType).*M1;
set(gcbf,'Userdata',data);
updateImage(1,0); % update all the other plots...
data = get(gcbf,'Userdata');
imDims = size(M1); % dimensions
set(findobj(gcbf,'Tag','Ref_im_c'),'String',[filename ', ' int2str(imDims(1)) ' x ' int2str(imDims(2))],'ForegroundColor','k');
data.pathname = pathname; % save pathname of this file
data.filename1 = filename;
set(gcbf,'Userdata',data);
dispTag('Ref_im','k');
dispText('','b');
end;
% Load image 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case('loadB')
dispText('','b');
data = get(gcbf,'Userdata');
pathname = data.pathname;
dispTag('Sens_im','r');
dispText('Loading image 2','b');
[filename, pathname] = uigetfile([pathname '*.*'], 'Load image 2');
if filename~=0
if isempty(findstr(filename,'pgm'))
[M2,ma] = imread([pathname, filename]);
if isind(M2) & ~isempty(ma)
M2 = 256*double(ind2gray(M2,ma));
else
if isgray(M2)
M2 = double(M2);
else
M2 = double(rgb2gray(M2));
end;
end;
else
cesta=strrep([pathname, filename],'.pgm','');
M2=readpgm(cesta);
end;
data.input2reference = M2;
data.input2 = M2;
data.input2_windowed = window2d(size(M2,1),size(M2,2),data.windowType).*M2;
set(gcbf,'Userdata',data);
updateImage(2,0);
data = get(gcbf,'Userdata');
vel=size(M2);
set(findobj(gcbf,'Tag','Sens_im_c'),'String',[filename ', ' int2str(vel(1)) ' x ' int2str(vel(2))],'ForegroundColor','k');
data.pathname = pathname;
set(gcbf,'CurrentAxes',findobj(gcbf,'Tag','Axes2'));
data.h2 = findobj(gcbf,'Tag','Axes2');
dispTag('Sens_im','k');
data.filename2 = filename;
set(gcbf,'Userdata',data);
dispText('','b');
set(findobj(gcbf,'Tag','RotInput2'),'String',num2str(0)); % set the rotate input2 value to ZERO
set(findobj(gcbf,'Tag','SclInput2'),'String',num2str(1)); % set the scale input2 value to ONE
set(findobj(gcbf,'Tag','CropInput2'),'String',[num2str(100) '%']); % set the crop % input2 value to 100
end;
case('SetRotInterp')
data = get(gcbf,'Userdata');
rotStrings = get(findobj(gcbf,'Tag','RotInterp'),'String');
rotInterp = rotStrings(get(findobj(gcbf,'Tag','RotInterp'),'Value'),:); % this is a character array possibly with spaces in
rotInterp(rotInterp==' ') = ''; % get rid of any spaces
data.RotInterp = rotInterp;
set(gcbf,'Userdata',data);
case('SetSclInterp')
data = get(gcbf,'Userdata');
sclStrings = get(findobj(gcbf,'Tag','SclInterp'),'String');
sclInterp = sclStrings(get(findobj(gcbf,'Tag','SclInterp'),'Value'),:); % this is a character array with 8 characters in it
sclInterp(sclInterp==' ') = ''; % get rid of any spaces
data.SclInterp = sclInterp;
set(gcbf,'Userdata',data);
case('SetLogPolInterp')
data = get(gcbf,'Userdata');
set(findobj(gcbf,'Tag','Pushbutton1'),'String','please wait...');
lpStrings = get(findobj(gcbf,'Tag','LogPolInterp'),'String');
lpInterp = lpStrings(get(findobj(gcbf,'Tag','LogPolInterp'),'Value'),:); % this is a character array with 8 characters in it
lpInterp(lpInterp==' ') = ''; % get rid of any spaces
data.LogInterp = lpInterp;
set(gcbf,'Userdata',data);
updateImage(1,1); % only update the log-polar plots and related plots...
updateImage(2,1);
if data.performanceLevel==1
set(findobj(gcbf,'Tag','Pushbutton1'),'String',['REGISTER (' num2str(data.performanceLevel) 'peak)']);
else
set(findobj(gcbf,'Tag','Pushbutton1'),'String',['REGISTER (' num2str(data.performanceLevel) 'peaks)']);
end
case('autocrop')
data = get(gcbf,'Userdata');
data.autocrop = get(findobj(gcbf,'Tag','cb_autocrop'),'Value');
set(gcbf,'Userdata',data);
case('SelectWindow')
data = get(gcbf,'Userdata');
windowStrings = get(findobj(gcbf,'Tag','FFTwindow'),'String');
windowSel = windowStrings(get(findobj(gcbf,'Tag','FFTwindow'),'Value'),:); % this is a character array with 8 characters in it
windowSel(windowSel==' ') = ''; % get rid of any spaces
data.windowType = windowSel;
set(gcbf,'Userdata',data);
case('windowScale')
data = get(gcbf,'Userdata');
data.windowScale = get(findobj(gcbf,'Tag','cb_windowScale'),'Value');
set(gcbf,'Userdata',data);
case('RotateScaleCropInput2')
data = get(gcbf,'Userdata');
filename = data.filename2;
set(findobj(gcbf,'Tag','Pushbutton1'),'String','please wait...');
% parse the rotation input
rotateVal = str2num(get(findobj(gcbf,'Tag','RotInput2'),'String'));
if (rotateVal>=360) % then map back to an angle between 0 and 360
rotateVal = rotateVal - (360*floor(rotateVal/360));
set(findobj(gcbf,'Tag','RotInput2'),'String',num2str(rotateVal));
elseif (rotateVal<360)
rotateVal = rotateVal - (360*floor(rotateVal/360));
set(findobj(gcbf,'Tag','RotInput2'),'String',num2str(rotateVal));
elseif (rotateVal<0)
rotateVal = rotateVal + 360;
set(findobj(gcbf,'Tag','RotInput2'),'String',num2str(rotateVal));
end
% parse the scale input
scaleVal = str2num(get(findobj(gcbf,'Tag','SclInput2'),'String'));
if (scaleVal>5) % 5 is currently the performance limit (increase if algorithm is improved!!)
scaleVal = 5;
set(findobj(gcbf,'Tag','SclInput2'),'String',num2str(scaleVal));
elseif (scaleVal<0.2)
scaleVal = 0.2;
set(findobj(gcbf,'Tag','SclInput2'),'String',num2str(scaleVal));
end
if (size(data.input2reference,1)>0)&(size(data.input2reference,2)>0) % can only perform if the second image actually exists
in1ref = data.input1reference;
if ((rotateVal==0)&(scaleVal==1)) % then reset the image to the original loaded one
rotsclIm = data.input2reference;
%[data.input1,data.input2] = zeropad(in1ref,rotsclIm,1); % zero-pad the images for display
in1_windowed = window2d(size(in1ref,1),size(in1ref,2),data.windowType).*in1ref;
rs_windowed = window2d(size(rotsclIm,1),size(rotsclIm,2),data.windowType).*rotsclIm;
[data.input1_windowed,data.input2_windowed] = zeropad(in1_windowed,rs_windowed,1);
else % apply the rotation and scale
rotsclIm = imrotate(data.input2reference,rotateVal,data.RotInterp,'crop'); % apply the rotation and don't change size compared to original
rotsclIm = imresize(rotsclIm,scaleVal,data.SclInterp); % apply the scale, the image size will now have changed
% now need to zero-pad image1 or image2 depending on what's happened to the image sizes
if (~data.autocrop) % then zero-pad the images so that they become the same size
if ((size(data.input1reference,1)>0)&(size(data.input1reference,2)>0)) % i.e., can only zero-pad if image1 exists
%[data.input1,data.input2] = zeropad(data.input1reference,rotsclIm,1); % zero-pad the images for display
data.input2 = rotsclIm;
in1_windowed = window2d(size(data.input1reference,1),size(data.input1reference,2),data.windowType).*data.input1reference; % window the images and zero-pad for use in fourier_mellin
rs_windowed = window2d(size(rotsclIm,1),size(rotsclIm,2),data.windowType).*rotsclIm;
[data.input1_windowed,data.input2_windowed] = zeropad(in1_windowed,rs_windowed,1); % only zero=pad with respect to the original version of input1
end
else % then perform cropping on the larger image
size_in1 = size(data.input1reference); size_rs = size(rotsclIm);
if ((size(data.input1reference,1)>1)&(size(data.input1reference,2)>0)) % only crop if input1 exists
if (size_rs(1)>size_in1(1))&(size_rs(2)>size_in1(2)) % ...then crop rotsclIm
sht = (size_rs(1)-size_in1(1))/2; swd = (size_rs(2)-size_in1(2))/2;
rotsclIm = imcrop(rotsclIm,[ceil(swd) ceil(sht) size_in1(2)-1 size_in1(1)-1]);
data.input2 = rotsclIm; data.input2_windowed = window2d(size(rotsclIm,1),size(rotsclIm,2),data.windowType).*rotsclIm;
data.input1 = in1ref; data.input1_windowed = window2d(size(in1ref,1),size(in1ref,2),data.windowType).*in1ref;
elseif (size_rs(1)<size_in1(1))&(size_rs(2)<size_in1(2)) % ...then crop input1
sht = (size_in1(1)-size_rs(1))/2; swd = (size_in1(2)-size_rs(2))/2;
newInput1 = imcrop(data.input1reference,[ceil(swd) ceil(sht) size_rs(2)-1 size_rs(1)-1]);
data.input1 = newInput1; data.input1_windowed = window2d(size(newInput1,1),size(newInput1,2),data.windowType).*newInput1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -