Skip to content

Commit 931b210

Browse files
committed
add rotate function
1 parent 072abc6 commit 931b210

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

src/@Image/rotate.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function res = rotate(obj, angle, varargin)
2+
% Rotate the current image by the specified angle in degrees.
3+
%
4+
% IMG2 = rotate(IMG, ANGLE)
5+
%
6+
% Example
7+
% % Apply a rotation by 30 degrees to the cameraman image
8+
% img = Image.read('cameraman.tif');
9+
% imgRot = rotate(img, 30);
10+
% show(imgRot)
11+
%
12+
% See also
13+
% rotate90
14+
%
15+
16+
% ------
17+
% Author: David Legland
18+
% e-mail: david.legland@inrae.fr
19+
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
20+
% Created: 2020-12-07, using Matlab 9.8.0.1323502 (R2020a)
21+
% Copyright 2020 INRAE.
22+
23+
nd = length(obj.Data);
24+
data = permute(obj.Data, [2 1 3:nd]);
25+
data2 = permute(imrotate(data, -angle, varargin{:}), [2 1 3:nd]);
26+
27+
res = Image('Data', data2, 'Parent', obj);

src/@Image/rotate90.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
% subplot(122);show(rotate90(img));
3131
%
3232
% See also
33-
% flip, permute
33+
% flip, permute, rotate
3434
%
3535

3636
% ------
@@ -105,5 +105,3 @@
105105
% also permute spacing and origin of image
106106
res.Origin = obj.Origin(permDims(1:nd));
107107
res.Spacing = obj.Spacing(permDims(1:nd));
108-
109-

tests/image/test_rotate.m

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function tests = test_rotate
2+
% Test suite for the file rotate.
3+
%
4+
% Test suite for the file rotate
5+
%
6+
% Example
7+
% test_rotate
8+
%
9+
% See also
10+
% rotate
11+
12+
% ------
13+
% Author: David Legland
14+
% e-mail: david.legland@inrae.fr
15+
% Created: 2020-12-07, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2020 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
21+
function test_Simple(testCase) %#ok<*DEFNU>
22+
% Test call of function without argument.
23+
24+
25+
img = Image.read('rice.png');
26+
27+
res = rotate(img, 10);
28+
29+
assertTrue(testCase, isa(res, 'Image'));
30+
31+
32+
function test_OptionCrop(testCase) %#ok<*DEFNU>
33+
% Test call of function without argument.
34+
35+
36+
img = Image.read('rice.png');
37+
38+
res = rotate(img, 10, 'crop');
39+
40+
assertTrue(testCase, isa(res, 'Image'));
41+
assertEqual(testCase, size(res), size(img));

0 commit comments

Comments
 (0)