shiftRotateImage.m 3.63 KB
Newer Older
1
function imTransformed = shiftRotateImage(im, shifts, rotAngleDegree, settings)
mtoeppe's avatar
mtoeppe committed
2
% SHIFTROTATEIMAGE applies shifts and/or rotations to a given image.
3
%
4
%    ``imTransformed = shiftRotateImage(im, shifts, rotAngleDegree, settings)``
5
6
7
8
9
%
% Does so in a single operation, such that the loss of image-resolution
% due to interpolation is reduced compared to applying shifts and rotations
% subsequently. The beneficial effect of this can be observed in the provided
% code-example.
10
11
12
% IMPORTANT: the geometrical image-transformations are applied in the following order: 
% (1) rotation
% (2) shift
13
14
15
16
17
18
19
20
%
% Parameters
% ----------
% im : numerical 2d-array
%     image to be shifted and/or rotated
% shifts : 2-tuple of floats
%     shifts to be applied to the image (in units of pixel-lengths) 
% rotAngleDegree : float
21
%     angle of the rotation to be applied to the image (in degrees)
22
23
24
%
% Other Parameters 
% ---------------- 
25
% padVal : Default = 'replicate'
mtoeppe's avatar
mtoeppe committed
26
27
28
%     Determines the type of the padding that is applied to the input image prior to
%     shifting and rotating. Admissible choices are the same as in the
%     MATLAB-function padarray.
29
% interpMethod : Default = 'linear'
mtoeppe's avatar
mtoeppe committed
30
31
%     Interpolation-method used in the image-transformation. Admissible choices are
%     the same as in the MATLAB-function interp2.
32
33
34
35
% invertTransform : Default = false
%     Determines whether to invert the assigned shift-rotation before application.
%     This allows to shift-rotate back and forth without manually computing
%     the inverse shifts and rotation (see code-example)
36
37
38
%
% Returns 
% ------- 
39
% imTransformed : numerical 2d-array
40
41
%    the shifted and/or rotated image
%
42
43
% See also 
% ------- 
44
45
46
47
% functions.imageProcessing.alignment.shiftRotateMagnifyImage
% functions.imageProcessing.alignment.shiftImage
% functions.imageProcessing.alignment.rotateImage
% functions.imageProcessing.alignment.magnifyImage
48
%
mtoeppe's avatar
mtoeppe committed
49
50
% Example
% -------
51
52
53
54
%
% .. code-block:: matlab
%
%     n = 64;
Simon Maretzke's avatar
Simon Maretzke committed
55
56
%     rotAngleDegree = 17.4;
%     shifts = [-9.7, 8.3];
57
58
%     im = padarray(ones(n/2), [n/4,n/4]); 
%     im(n/8+1:n/4,n/4+1:3*n/8) = 1;
59
%     figure('name', 'Original image'); showImage(im);
60
%     
61
62
%     imTransformed1 = shiftRotateImage(im, shifts, rotAngleDegree);
%     figure('name', 'One-step shift-rotated image'); showImage(imTransformed1);
63
%     
Simon Maretzke's avatar
Simon Maretzke committed
64
%     imTransformed2 = shiftImage(rotateImage(im, rotAngleDegree), shifts);
65
%     figure('name', 'Two-step shift-rotated image'); showImage(imTransformed2);
66
%
67
%     settings.invertTransform = true;
68
69
70
%     imTransformedBack = shiftRotateImage(imTransformed1, shifts, rotAngleDegree, settings);
%     figure('name', 'Back and forth shift-rotated image'); showImage(imTransformedBack);
%
71
%
72
% See also SHIFTROTATEMAGNIFYIMAGE, SHIFTIMAGE, ROTATEIMAGE, MAGNIFYIMAGE
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    
% HoloTomoToolbox
% Copyright (C) 2019  Institut fuer Roentgenphysik, Universitaet Goettingen
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.

90
91
92
93
if nargin == 0
    imTransformed = shiftRotateMagnifyImage;
    return
end
94
if nargin < 4
95
    settings = struct;
96
end
97
imTransformed = shiftRotateMagnifyImage(im, shifts, rotAngleDegree, [], settings);
98
99
100

end