Skip to content
Snippets Groups Projects
Commit d8a73024 authored by Yoann Guilhem's avatar Yoann Guilhem Committed by Nicola Vigano
Browse files

Cleanup some old and redundant functions

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@792 4c865b51-4357-4376-afb4-474e03ccb993
parent c1cc25cc
No related branches found
No related tags found
No related merge requests found
function gtApplyDrifts(first, last, copymode, dirpath, scanname, parameterfile)
% FUNCTION gtApplyDrifts(first, last, copymode, dirpath, scanname, parameterfile)
%
% Shifts edf images in the 'dirpath' with a value given in the parameterfile corresponding to the edf number. folder OverwritesCopies, corrects and undistorts full images online.
%
% INPUT
% copymode = 'online' or 'parallel'
% dirpath = full path of the folder containing edf-s
% scanname = name of scan
% parameterfile = full path and name of the parameterfile (drifts has to be stored as
% parameters.prep.ydrifts, parameters.prep.zdrifts)
%
%% Extract parameters
if ~exist(dirpath,'dir')
gtError('Cannot find directory!')
end
if ~exist(parameterfile,'file')
gtError('Cannot find parameterfile!')
end
if isdeployed
global GT_DB
global GT_MATLAB_HOME
load('workspaceGlobal.mat');
first=str2num(first);
last=str2num(last);
end
disp(' ')
disp('Shifting and overwriting images with the following filenames...')
disp(' - ref*.edf')
disp(sprintf(' - %s*.edf',scanname))
disp(' shifted = true/false field is added to edf header')
disp(' /dark images are not modified/')
disp(' ')
%% Copymode online
if strcmpi(copymode,'online')
disp('Online version is not yet implemented...')
return
% % read drifts from parameterfile first (or get in from a function),
% % by that time those files must exist, so just overwrite them
% check if pfWaitToRead(fname) is ever needed
% filesdone=[];
% counter=0;
%
% while counter<250
% sfiles=dir([dirname '/*']);
% n=1;
% while n<=length(sfiles)
% sfname=sfiles(n).name;
% if strcmp('.',sfname(1)) || ~strcmp('.edf',sfname(end-3:end))
% sfiles(n)=[];
% else
% n=n+1;
% end
% end
%
%
% if found==1
% counter=0;
% else
% counter=counter+1;
% disp('Sleeping')
% pause(5)
% end
%% Copymode parallel - do all from first to last
elseif strcmpi(copymode,'parallel')
load(parameterfile)
yshift=parameters.prep.ydrift; % !! im0000 -> yshift(0001) , etc.
zshift=parameters.prep.zdrift; % !! im0000 -> zshift(0001) , etc.
if isempty(yshift)
gtError('parameters.prep.ydrift is empty, check parameter file!')
end
if isempty(zshift)
gtError('parameters.prep.zdrift is empty, check parameter file!')
end
% Images
ims=dir([dirpath '/' scanname '*.edf']);
for i=first:last
fname=[dirpath '/' ims(i).name];
disp(sprintf('Shifting %s',fname))
fnum=ims(i).name;
fnum=str2num(fnum(end-7:end-4));
if length(yshift)>=fnum+1
sfOverwrite(fname,yshift(fnum+1),zshift(fnum+1)); % !! im0000 -> yshift(0001) , etc.
else
%disp(sprintf('File: %s',fname))
gtError('No drift(s) are specified for this image.')
end
% Refs with the same number if exists
refs=dir(sprintf('%s/ref*%0.4d.edf',dirpath,fnum));
if ~isempty(refs)
for j=1:length(refs)
fname=[dirpath '/' refs(j).name];
disp(sprintf('Shifting %s',fname))
sfOverwrite(fname,yshift(fnum+1),zshift(fnum+1)); % !! im0000 -> yshift(0001) , etc.
end
end
end
else
disp('Copymode must be either "online" or "parallel".')
gtError('Copymode is not recognized!')
end % copymode
end % of function
%% Sub-functions
function sfOverwrite(fname, yshift, zshift)
im=edf_read(fname); % pfWaitToRead(fname);
info=edf_info(fname);
%if isfield(info,'istranslated')
%yshift=yshift-info.yshift;
%zshift=zshift-info.zshift;
%end
%info.yshift=info.yshift+yshift;
%info.zshift=info.zshift+zshift;
info.istranslated=true;
im=gtShift(im,yshift,zshift); % gtShift(im,x(horizontal_right),y(vertical_downwards))
edf_write(im,fname,info);
end
function im=gtGetDifImage(ndx,struct_id)
%returns the full image requested, cropped to the specified difspot bounding box
global difspot
if isempty(difspot)
disp('Loading difspot file')
load('2_difspot/difspot.mat');
end
im = edf_read(sprintf('1_preprocessed/full/full%04d.edf',ndx),difspot(struct_id).BoundingBox);
function im=gtGetDifImage(ndx,struct_id)
%returns the full image requested, cropped to the specified difspot bounding box
%global difspot
gtDBconnect
% if isempty(difspot)
% disp('Loading difspot file')
% load('2_difspot/difspot.mat');
% end
% im = edf_read(sprintf('1_preprocessed/full/full%04d.edf',ndx),difspot(struct_id).BoundingBox);
im=mysqlcmd(sprintf('1_preprocessed/full/full%04d.edf',ndx),'select BoundingBoxXorigin, BoundingBoxYorigin, BoundingBoxXsize, BoundingBoxYsize from %sdifspot where difspotID=%d',parameters.acq.name, struct_id)
\ No newline at end of file
function spot=gtGetSummedDifSpot_360(pair_id)
%returns the summed difspot image (saved as difspot%05d.edf)
%for 360 datasets, given a pair ID it returns the A difspot, if one exists,
%else the B difspot
parameters=[];
if isempty(parameters)
disp('Loading parameter file')
load('parameters.mat');
end
acq=parameters.acq;
%get the root of the pair name
pair_name=parameters.acq.pair_tablename;
pair_name(end-8:end)=[];
%is there an A difspot in the pair table?
mysqlcmd = sprintf(['select !isnull(difAID), ifnull(difAID,difBID) from %s where pairID=%d'],...
acq.pair_tablename,pair_id);
[A,difID]=mym(mysqlcmd);
if A %if the first half of the scan
name=parameters.acq.difA_name;
disp('reading difspot from A')
else
name=parameters.acq.difB_name;
disp('reading difspot from B')
end
path=sprintf('../%s/',name);
spot=edf_read(sprintf('%s2_difspot/difspot/difspot%05d.edf',path,difID));
end
function im=gtShift(imorig,x,y)
xpad=zeros(size(imorig,1),abs(x));
ypad=zeros(abs(y),size(imorig,2));
if x>0
tmp=[xpad imorig];
im=tmp(:,1:size(imorig,2));
else
tmp=[imorig xpad];
im=tmp(:,abs(x)+1:end);
end
if y>0
tmp=[ypad;im];
im=tmp(1:size(imorig,1),:);
else
tmp=[im;ypad];
im=tmp(abs(y)+1:end,:);
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment