Skip to content

Commit 4295f0d

Browse files
committed
add orthogonalProjection.m
1 parent d0307f6 commit 4295f0d

File tree

6 files changed

+112
-7
lines changed

6 files changed

+112
-7
lines changed

src/@Image/Image.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ function copyFields(obj, that)
293293
nc = obj.DataSize(4);
294294
switch lower(typeName)
295295
case 'binary', if nc ~= 1, tf = false; end
296-
case 'grayscale', if nc ~= 1, tf = false; end
296+
case 'grayscale', if nc ~= 1 || isfloat(obj.Data), tf = false; end
297297
case 'intensity', if nc ~= 1, tf = false; end
298298
case 'color', if nc ~= 3, tf = false; end
299299
case 'label', if nc ~= 1, tf = false; end

src/@Image/max.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function res = max(obj, varargin)
22
% Compute the maximal value within image.
33
%
4-
% M = mean(IMG);
4+
% M = max(IMG);
55
%
66
% Example
77
% img = Image.read('rice.png');
@@ -10,7 +10,7 @@
1010
% 204
1111
%
1212
% See also
13-
% mean, median, min
13+
% mean, median, min, orthogonalProjection
1414
%
1515

1616
if isempty(varargin)

src/@Image/mean.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
% 111.2468
1111
%
1212
% See also
13-
% median
13+
% median, min, max, orthogonalProjection
1414
%
1515

1616
res = mean(double(obj.Data(:)));

src/@Image/min.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
function res = min(obj, varargin)
22
% Compute the minimal value within image.
33
%
4-
% M = mean(IMG);
4+
% M = min(IMG);
55
%
66
% Example
77
% img = Image.read('rice.png');
8-
% max(img)
8+
% min(img)
99
% ans =
1010
% 40
1111
%
1212
% See also
13-
% mean, median, max
13+
% mean, median, max, orthogonalProjection
1414
%
1515

1616

src/@Image/orthogonalProjection.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function res = orthogonalProjection(obj, dir, opName)
2+
% Project image intensities along one of the main directions..
3+
%
4+
% PROJ = orthogonalProjection(IMG, DIR, OP)
5+
% Project the intensities of the image IMG in the direction given by DIR.
6+
% The operation OP applied on the values can be one of 'Max' (default),
7+
% 'Min', or 'Mean'.
8+
%
9+
% Example
10+
% img = Image.read('mri.tif');
11+
% projXY = orthogonalProjection(img, 3, 'Mean');
12+
% figure; show(projXY);
13+
%
14+
% See also
15+
% slice, min, max, mean
16+
%
17+
18+
% ------
19+
% Author: David Legland
20+
% e-mail: david.legland@inrae.fr
21+
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
22+
% Created: 2021-01-27, using Matlab 9.8.0.1323502 (R2020a)
23+
% Copyright 2021 INRAE.
24+
25+
if strcmpi(opName, 'max')
26+
data = max(obj.Data, [], dir);
27+
elseif strcmpi(opName, 'min')
28+
data = min(obj.Data, [], dir);
29+
elseif strcmpi(opName, 'mean')
30+
data = mean(obj.Data, dir);
31+
else
32+
error('Unknown operation name: %s', opName)
33+
end
34+
35+
% create projected image
36+
newName = createNewName(obj, '%s-proj');
37+
res = Image('Data', data, 'Parent', obj, 'Name', newName);
38+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function tests = test_orthogonalProjection
2+
% Test suite for the file orthogonalProjection.
3+
%
4+
% Test suite for the file orthogonalProjection
5+
%
6+
% Example
7+
% test_orthogonalProjection
8+
%
9+
% See also
10+
% orthogonalProjection
11+
12+
% ------
13+
% Author: David Legland
14+
% e-mail: david.legland@inrae.fr
15+
% Created: 2021-01-27, using Matlab 9.8.0.1323502 (R2020a)
16+
% Copyright 2021 INRAE - BIA-BIBS.
17+
18+
tests = functiontests(localfunctions);
19+
20+
21+
function test_Proj_Z(testCase) %#ok<*DEFNU>
22+
% Test call of function without argument.
23+
24+
img = createTestImage3d();
25+
26+
projXY = orthogonalProjection(img, 3, 'max');
27+
28+
assertEqual(testCase, size(projXY), [30 20]);
29+
30+
31+
32+
function test_Proj_Z_mean(testCase) %#ok<*DEFNU>
33+
% Test call of function without argument.
34+
35+
img = createTestImage3d();
36+
37+
projXY = orthogonalProjection(img, 3, 'mean');
38+
39+
assertEqual(testCase, size(projXY), [30 20]);
40+
41+
42+
function test_Proj_Y(testCase) %#ok<*DEFNU>
43+
% Test call of function without argument.
44+
45+
img = createTestImage3d();
46+
47+
projXZ = orthogonalProjection(img, 2, 'max');
48+
49+
assertEqual(testCase, size(projXZ), [30 1 10]);
50+
51+
52+
function test_Proj_X(testCase) %#ok<*DEFNU>
53+
% Test call of function without argument.
54+
55+
img = createTestImage3d();
56+
57+
projYZ = orthogonalProjection(img, 1, 'max');
58+
59+
assertEqual(testCase, size(projYZ), [1 20 10]);
60+
61+
62+
function img = createTestImage3d
63+
% Create an image with size 30x20x10 containing a 20x10x5 cuboid.
64+
65+
data = zeros([30 20 10], 'uint8');
66+
data(6:25, 6:15, 3:7) = 100;
67+
img = Image('Data', data);

0 commit comments

Comments
 (0)