Skip to content

Commit ff893ac

Browse files
amitantonywahln
andauthored
generate body contour (#768)
* Function to generate body contour for imported patient cases thet do not have one * Checking for image processing toolbox * move body contour generation to util as it might be useful within matRad itself * some reformatting to body contour generator * test of body contour generator --------- Co-authored-by: Niklas Wahl <[email protected]>
1 parent fba6f41 commit ff893ac

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function cst = matRad_generateBodyContour(ct,cst,thresholdHU)
2+
% function to create a BODY contour for imported patient cases that do not have one
3+
%
4+
% call
5+
% cst = matRad_generateBodyContour(ct,cst,thresholdHU)
6+
%
7+
% input
8+
% ct: matrad ct structure
9+
% cst: matrad cst structure
10+
% thresholdHU: HU thresholding value (optional) default = -500 HU
11+
%
12+
%
13+
% output
14+
% cst: matRads cst struct with inserted BODY contour
15+
%
16+
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17+
%
18+
% Copyright 2024 the matRad development team.
19+
%
20+
% This file is part of the matRad project. It is subject to the license
21+
% terms in the LICENSE file found in the top-level directory of this
22+
% distribution and at https://github.com/e0404/matRad/LICENSE.md. No part
23+
% of the matRad project, including this file, may be copied, modified,
24+
% propagated, or distributed except according to the terms contained in the
25+
% LICENSE file.
26+
%
27+
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28+
29+
matRad_cfg = MatRad_Config.instance();
30+
% dicom import needs image processing toolbox -> check if available
31+
available = matRad_checkEnvDicomRequirements(matRad_cfg.env);
32+
33+
if ~available
34+
matRad_cfg.dispError('Image processing toolbox / packages not available!');
35+
end
36+
37+
if nargin < 3
38+
thresholdHU = -500;
39+
end
40+
% visualize Histogram
41+
% figure,
42+
% histogram(ct.cubeHU{1});
43+
% hold on
44+
% scatter(-500,100,'x')
45+
% hold off
46+
% xlabel('HU')
47+
% ylabel('#')
48+
49+
% Thresholding on HU
50+
mask = zeros(ct.cubeDim);
51+
mask(ct.cubeHU{1}>thresholdHU) = 1;
52+
filledIm= imfill(mask);
53+
54+
% Write to cst
55+
pos = size(cst,1);
56+
cst{pos+1,1} = pos;
57+
cst{pos+1,2} = 'BODY';
58+
cst{pos+1,3} = 'OAR';
59+
cst{pos+1,4}{1} = find(filledIm);
60+
cst{pos+1,5}.Priority = 99;
61+
cst{pos+1,5}.alphaX = 0.1;
62+
cst{pos+1,5}.betaX = 0.05;
63+
cst{pos+1,5}.Visible = 1;
64+
cst{pos+1,5}.visibleColor = [0.7,0.3,0.1];
65+
cst{pos+1,6} = [];
66+
67+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function test_suite = test_generateBodyContour
2+
%The output should always be test_suite, and the function name the same as
3+
%your file name
4+
5+
%% Header
6+
% The header is required to be in this format for automatic test collection
7+
% by MOxUnit
8+
9+
%To collect all tests defined below, this is needed in newer Matlab
10+
%versions. test_functions will collect function handles to below test
11+
%functions
12+
test_functions=localfunctions();
13+
14+
% This will initialize the test suite, i.e., take the functions from
15+
% test_functions, check if they contain "test", convert them into a MOxUnit
16+
% Test Case, and add them to the test-runner
17+
initTestSuite;
18+
19+
%% Custom Tests
20+
% Tests use assert*-like Functions to check outputs etc:
21+
% assertTrue(a) - a is true
22+
% assertFalse(a) - a is false
23+
% assertEqual(a,b) - a and be are equal (isequal)
24+
% assertElementsAlmostEqual(a,b) - numerical test for all vector / matrix elements. Has Additional arguments for absolute / relative tolerance
25+
% assertVectorsAlmostEqual(a,b) - numerical test using vector norm
26+
% assertExceptionThrown(f,id) - test if exception of id is thrown. Take care of Octave issues with exception id (or don't provide id)
27+
% Check MOxUnit for more information or look at other tests
28+
29+
function test_boxphantom_contour
30+
load BOXPHANTOM.mat
31+
cstNew = matRad_generateBodyContour(ct,cst);
32+
voxIxGenerated = cstNew{end,4}{1};
33+
voxIxExisting = cstNew{1,4}{1};
34+
35+
assertEqual(numel(voxIxGenerated),numel(voxIxExisting));
36+
assertEqual(sort(voxIxGenerated),sort(voxIxExisting));
37+
38+
function test_boxphantom_contour_withThreshold
39+
load BOXPHANTOM.mat
40+
cstNew = matRad_generateBodyContour(ct,cst,10);
41+
voxIxGenerated = cstNew{end,4}{1};
42+
assertTrue(isempty(voxIxGenerated));
43+
44+

0 commit comments

Comments
 (0)