shiftRotateImage.m 3.63 KB
 Simon Maretzke committed May 10, 2019 1 ``````function imTransformed = shiftRotateImage(im, shifts, rotAngleDegree, settings) `````` mtoeppe committed Apr 25, 2019 2 ``````% SHIFTROTATEIMAGE applies shifts and/or rotations to a given image. `````` 3 ``````% `````` Simon Maretzke committed May 10, 2019 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. `````` Simon Maretzke committed May 10, 2019 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 `````` Simon Maretzke committed Jun 27, 2019 21 ``````% angle of the rotation to be applied to the image (in degrees) `````` 22 23 24 ``````% % Other Parameters % ---------------- `````` Simon Maretzke committed May 10, 2019 25 ``````% padVal : Default = 'replicate' `````` mtoeppe committed Apr 25, 2019 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 committed Apr 25, 2019 30 31 ``````% Interpolation-method used in the image-transformation. Admissible choices are % the same as in the MATLAB-function interp2. `````` Simon Maretzke committed May 10, 2019 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 % ------- `````` Simon Maretzke committed May 10, 2019 39 ``````% imTransformed : numerical 2d-array `````` 40 41 ``````% the shifted and/or rotated image % `````` Simon Maretzke committed Apr 25, 2019 42 43 ``````% See also % ------- `````` Simon Maretzke committed May 10, 2019 44 45 46 47 ``````% functions.imageProcessing.alignment.shiftRotateMagnifyImage % functions.imageProcessing.alignment.shiftImage % functions.imageProcessing.alignment.rotateImage % functions.imageProcessing.alignment.magnifyImage `````` Simon Maretzke committed Apr 25, 2019 48 ``````% `````` mtoeppe committed Apr 29, 2019 49 50 ``````% Example % ------- `````` 51 52 53 54 ``````% % .. code-block:: matlab % % n = 64; `````` Simon Maretzke committed May 15, 2019 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; `````` Simon Maretzke committed May 10, 2019 59 ``````% figure('name', 'Original image'); showImage(im); `````` 60 ``````% `````` Simon Maretzke committed May 10, 2019 61 62 ``````% imTransformed1 = shiftRotateImage(im, shifts, rotAngleDegree); % figure('name', 'One-step shift-rotated image'); showImage(imTransformed1); `````` 63 ``````% `````` Simon Maretzke committed May 15, 2019 64 ``````% imTransformed2 = shiftImage(rotateImage(im, rotAngleDegree), shifts); `````` Simon Maretzke committed May 10, 2019 65 ``````% figure('name', 'Two-step shift-rotated image'); showImage(imTransformed2); `````` 66 ``````% `````` Simon Maretzke committed Apr 25, 2019 67 ``````% settings.invertTransform = true; `````` Simon Maretzke committed May 10, 2019 68 69 70 ``````% imTransformedBack = shiftRotateImage(imTransformed1, shifts, rotAngleDegree, settings); % figure('name', 'Back and forth shift-rotated image'); showImage(imTransformedBack); % `````` Simon Maretzke committed Apr 25, 2019 71 ``````% `````` Simon Maretzke committed May 10, 2019 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 . `````` 90 91 92 93 ``````if nargin == 0 imTransformed = shiftRotateMagnifyImage; return end `````` 94 ``````if nargin < 4 `````` Simon Maretzke committed Jun 27, 2019 95 `````` settings = struct; `````` 96 ``````end `````` Simon Maretzke committed May 10, 2019 97 ``````imTransformed = shiftRotateMagnifyImage(im, shifts, rotAngleDegree, [], settings); `````` 98 99 100 `````` end ``````