{"text": "function [sourcemodel, cfg] = ft_prepare_leadfield(cfg, data)\n\n% FT_PREPARE_LEADFIELD computes the forward model for many dipole locations\n% on a regular 2D or 3D sourcemodel and stores it for efficient inverse modelling\n%\n% Use as\n% [sourcemodel] = ft_prepare_leadfield(cfg, data)\n%\n% It is necessary to input the data on which you want to perform the inverse\n% computations, since that data generally contain the gradiometer information and\n% information about the channels that should be included in the forward model\n% computation. The data structure can be either obtained from FT_PREPROCESSING,\n% FT_FREQANALYSIS or FT_TIMELOCKANALYSIS. If the data is empty, all channels will be\n% included in the forward model.\n%\n% The configuration should contain\n% cfg.channel = Nx1 cell-array with selection of channels (default = 'all'),\n% see FT_CHANNELSELECTION for details\n%\n% The positions of the sources can be specified as a regular 3-D\n% sourcemodel that is aligned with the axes of the head coordinate system\n% cfg.xgrid = vector (e.g. -20:1:20) or 'auto' (default = 'auto')\n% cfg.ygrid = vector (e.g. -20:1:20) or 'auto' (default = 'auto')\n% cfg.zgrid = vector (e.g. 0:1:20) or 'auto' (default = 'auto')\n% cfg.resolution = number (e.g. 1 cm) for automatic sourcemodel generation\n%\n% Alternatively the position of a few sources at locations of interest can\n% be specified, for example obtained from an anatomical or functional MRI\n% cfg.sourcemodel.pos = N*3 matrix with position of each source\n% cfg.sourcemodel.inside = N*1 vector with boolean value whether sourcemodel point is inside brain (optional)\n% cfg.sourcemodel.dim = [Nx Ny Nz] vector with dimensions in case of 3-D sourcemodel (optional)\n%\n% The volume conduction model of the head should be specified as\n% cfg.headmodel = structure with volume conduction model, see FT_PREPARE_HEADMODEL\n%\n% The EEG or MEG sensor positions can be present in the data or can be specified as\n% cfg.elec = structure with electrode positions or filename, see FT_READ_SENS\n% cfg.grad = structure with gradiometer definition or filename, see FT_READ_SENS\n%\n% Optionally, you can modify the leadfields by reducing the rank (i.e. remove the\n% weakest orientation), or by normalizing each column.\n% cfg.reducerank = 'no', or number (default = 3 for EEG, 2 for MEG)\n% cfg.backproject = 'yes' or 'no', determines when reducerank is applied whether the\n% lower rank leadfield is projected back onto the original linear\n% subspace, or not (default = 'yes')\n% cfg.normalize = 'yes' or 'no' (default = 'no')\n% cfg.normalizeparam = depth normalization parameter (default = 0.5)\n% cfg.weight = number or Nx1 vector, weight for each dipole position to compensate\n% for the size of the corresponding patch (default = 1)\n%\n% Depending on the type of headmodel, some additional options may be\n% specified.\n%\n% For OPENMEEG based headmodels:\n% cfg.openmeeg.batchsize = scalar (default 1e4), number of dipoles\n% for which the leadfield is computed in a\n% single call to the low-level code. Trades off\n% memory efficiency for speed.\n% cfg.openmeeg.dsm = 'no'/'yes', reuse existing DSM if provided\n% cfg.openmeeg.keepdsm = 'no'/'yes', option to retain DSM (no by default)\n% cfg.openmeeg.nonadaptive = 'no'/'yes'\n%\n% For SINGLESHELL based headmodels:\n% cfg.singleshell.batchsize = scalar or 'all' (default 1), number of dipoles\n% for which the leadfield is computed in a\n% single call to the low-level code. Trades off\n% memory efficiency for speed.\n%\n% To facilitate data-handling and distributed computing you can use\n% cfg.inputfile = ...\n% If you specify this option the input data will be read from a *.mat\n% file on disk. This mat files should contain only a single variable named 'data',\n% corresponding to the input structure.\n%\n% See also FT_SOURCEANALYSIS, FT_DIPOLEFITTING, FT_PREPARE_HEADMODEL, FT_PREPARE_SOURCEMODEL\n\n% Undocumented local options:\n% cfg.feedback\n% cfg.sel50p = 'no' (default) or 'yes'\n% cfg.lbex = 'no' (default) or a number that corresponds with the radius\n% cfg.mollify = 'no' (default) or a number that corresponds with the FWHM\n\n% Copyright (C) 2004-2013, Robert Oostenveld\n%\n% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org\n% for the documentation and details.\n%\n% FieldTrip is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% FieldTrip is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with FieldTrip. If not, see .\n%\n% $Id$\n\n% these are used by the ft_preamble/ft_postamble function and scripts\nft_revision = '$Id$';\nft_nargin = nargin;\nft_nargout = nargout;\n\n% do the general setup of the function\nft_defaults\nft_preamble init\nft_preamble debug\nft_preamble loadvar data\nft_preamble provenance data\n\n% the ft_abort variable is set to true or false in ft_preamble_init\nif ft_abort\n return\nend\n\n% the data can be passed as input arguments or can be read from disk\nhasdata = exist('data', 'var');\n\nif ~hasdata\n % the data variable will be passed to the prepare_headmodel function below\n % where it would be used for channel selection\n data = [];\nelse\n % check if the input data is valid for this function\n data = ft_checkdata(data);\nend\n\n% check if the input cfg is valid for this function\ncfg = ft_checkconfig(cfg, 'forbidden', {'channels'}); % prevent accidental typos, see issue 1729\ncfg = ft_checkconfig(cfg, 'renamed', {'hdmfile', 'headmodel'});\ncfg = ft_checkconfig(cfg, 'renamed', {'vol', 'headmodel'});\ncfg = ft_checkconfig(cfg, 'renamed', {'grid', 'sourcemodel'});\ncfg = ft_checkconfig(cfg, 'renamed', {'om', 'openmeeg'});\ncfg = ft_checkconfig(cfg, 'renamed', {'elecfile', 'elec'});\ncfg = ft_checkconfig(cfg, 'renamed', {'gradfile', 'grad'});\ncfg = ft_checkconfig(cfg, 'renamed', {'optofile', 'opto'});\ncfg = ft_checkconfig(cfg, 'deprecated', {'patchindx', 'patchsize'});\n\n% set the defaults\ncfg.lbex = ft_getopt(cfg, 'lbex', 'no');\ncfg.sel50p = ft_getopt(cfg, 'sel50p', 'no');\ncfg.feedback = ft_getopt(cfg, 'feedback', 'text');\ncfg.mollify = ft_getopt(cfg, 'mollify', 'no');\ncfg.patchsvd = ft_getopt(cfg, 'patchsvd', 'no');\n\ncfg = ft_checkconfig(cfg, 'renamed', {'tightgrid', 'tight'}); % this is moved to cfg.sourcemodel.tight by the subsequent createsubcfg\ncfg = ft_checkconfig(cfg, 'renamed', {'sourceunits', 'unit'}); % this is moved to cfg.sourcemodel.unit by the subsequent createsubcfg\n\n% put the low-level options pertaining to the sourcemodel in their own field\ncfg = ft_checkconfig(cfg, 'createsubcfg', {'sourcemodel'});\n% move some fields from cfg.sourcemodel back to the top-level configuration\ncfg = ft_checkconfig(cfg, 'createtopcfg', {'sourcemodel'});\n\n% this code expects the inside to be represented as a logical array\ncfg.sourcemodel = ft_checkconfig(cfg.sourcemodel, 'renamed', {'pnt' 'pos'});\ncfg = ft_checkconfig(cfg, 'inside2logical', 'yes');\n\nif strcmp(cfg.sel50p, 'yes') && strcmp(cfg.lbex, 'yes')\n ft_error('subspace projection with either lbex or sel50p is mutually exclusive');\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% collect and preprocess the electrodes/gradiometer and head model\n[headmodel, sens, cfg] = prepare_headmodel(cfg, data);\n\n% construct the sourcemodel for which the leadfield will be computed\ntmpcfg = keepfields(cfg, {'sourcemodel', 'mri', 'headshape', 'symmetry', 'smooth', 'threshold', 'spheremesh', 'inwardshift', 'xgrid' 'ygrid', 'zgrid', 'resolution', 'tight', 'warpmni', 'template', 'showcallinfo', 'trackcallinfo', 'trackusage', 'trackdatainfo', 'trackmeminfo', 'tracktimeinfo', 'checksize'});\ntmpcfg.headmodel = headmodel;\nif ft_senstype(sens, 'eeg')\n tmpcfg.elec = sens;\nelseif ft_senstype(sens, 'meg')\n tmpcfg.grad = sens;\nend\nsourcemodel = ft_prepare_sourcemodel(tmpcfg);\n\n% find the indices of all sourcemodel points that are inside the brain\ninsideindx = find(sourcemodel.inside);\n\n% check whether units are equal (NOTE: this was previously not required,\n% this check can be removed if the underlying bug is resolved. See\n% http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=2387\nif ~isfield(headmodel, 'unit') || ~isfield(sourcemodel, 'unit') || ~isfield(sens, 'unit')\n ft_warning('cannot determine the units of all geometric objects required for leadfield computation (headmodel, sourcemodel, sensor configuration). THIS CAN LEAD TO WRONG RESULTS! (refer to http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=2387)');\nelse\n if ~strcmp(headmodel.unit, sourcemodel.unit) || ~strcmp(sourcemodel.unit, sens.unit)\n ft_error('geometric objects (headmodel, sourcemodel, sensor configuration) are not expressed in the same units (this used to be allowed, and will be again in the future, but for now there is a bug which prevents a correct leadfield from being computed; see http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=2387)');\n end\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% construct the low-level options for the leadfield computation as key-value pairs, these are passed to FT_COMPUTE_LEADFIELD\nleadfieldopt = {};\nleadfieldopt = ft_setopt(leadfieldopt, 'reducerank', ft_getopt(cfg, 'reducerank'));\nleadfieldopt = ft_setopt(leadfieldopt, 'backproject', ft_getopt(cfg, 'backproject'));\nleadfieldopt = ft_setopt(leadfieldopt, 'normalize', ft_getopt(cfg, 'normalize'));\nleadfieldopt = ft_setopt(leadfieldopt, 'normalizeparam', ft_getopt(cfg, 'normalizeparam'));\nleadfieldopt = ft_setopt(leadfieldopt, 'weight', ft_getopt(cfg, 'weight'));\n\nif ft_headmodeltype(headmodel, 'openmeeg')\n \n ft_hastoolbox('openmeeg', 1); % add to path (if not yet on path)\n \n cfg.openmeeg = ft_getopt(cfg, 'openmeeg', []);\n batchsize = ft_getopt(cfg.openmeeg, 'batchsize', 1e4); % number of voxels per DSM batch; set to e.g. 1000 if not much RAM available\n keepdsm = ft_getopt(cfg.openmeeg, 'keepdsm', 'no'); % retain DSM\n \n leadfieldopt = ft_setopt(leadfieldopt, 'dsm', ft_getopt(cfg.openmeeg, 'dsm')); % reuse existing DSM if provided\n leadfieldopt = ft_setopt(leadfieldopt, 'nonadaptive', ft_getopt(cfg.openmeeg, 'nonadaptive', 'no'));\n \n % repeated system calls to the openmeeg executable makes it rather slow, calling it once is much more efficient\n fprintf('calculating leadfield for %d positions at a time, this may take a while...\\n', batchsize);\n \n % a dsm in the input cfg currently assumes that the 'content' of the dsm matches\n % exactly the positions that were passed in sourcemodel.pos. This is not guaranteed\n % of course. If anything, it would make sense to represent the dsm in the input\n % sourcemodel, so that the pos, and dsm are bound together. Still no guarantee, but\n % better than nothing. This means that the cfg.openmeeg.dsm option should be\n % deprecated\n \n ndip = length(insideindx);\n numchunks = ceil(ndip/batchsize);\n dippos = sourcemodel.pos(insideindx,:);\n \n if(numchunks > 1)\n if istrue(keepdsm)\n ft_warning('Keeping DSM output not supported when the computation is split into batches')\n end\n keepdsm = false;\n end\n \n % DSM computation is computationally intensive: As it can be reused with same voxel\n % sourcemodel (i.e. if voxels are defined in MRI coordinates rather than MEG\n % coordinates), optionally save result. Dense voxel grids may require several\n % gigabytes of RAM, so optionally split into smaller batches\n dsm = ft_getopt(leadfieldopt, 'dsm');\n if istrue(keepdsm) && ~isempty(dsm)\n % dsm needs to be computed outside ft_compute_leadfield, because it needs to be passed on in the output\n dsm = ft_sysmat_openmeeg(dippos, headmodel, sens, ft_getopt(leadfieldopt, 'nonadaptive'));\n leadfieldopt = ft_setopt(leadfieldopt, 'dsm', dsm);\n end\n \n sourcemodel.leadfield = cell(size(sourcemodel.pos,1),1);\n ft_progress('init', cfg.feedback, 'computing leadfield');\n for k = 1:numchunks\n ft_progress(k/numchunks, 'computing leadfield %d/%d\\n', k, numchunks);\n diprange = (((k-1)*batchsize + 1):(min(k*batchsize,ndip)));\n tmp = ft_compute_leadfield(dippos(diprange,:), sens, headmodel, leadfieldopt{:});\n % distribute the columns of the leadfield matrix over the individual dipole positions\n % avoid using the options reducerank and backproject, see https://github.com/fieldtrip/fieldtrip/issues/1410#issuecomment-646994620\n [m, n] = size(tmp);\n sourcemodel.leadfield(insideindx(diprange)) = mat2cell(tmp, m, repmat(n/numel(diprange), 1, numel(diprange)));\n end\n ft_progress('close');\n \n if istrue(keepdsm)\n % retain DSM in cfg if desired -> FIXME this should not be kept in\n % the cfg. If anything, it is sourcemodel specific, so it should be\n % retained in the output sourcemodel\n cfg.openmeeg.dsm = dsm;\n end\n \nelseif ft_headmodeltype(headmodel, 'singleshell')\n cfg.singleshell = ft_getopt(cfg, 'singleshell', []);\n batchsize = ft_getopt(cfg.singleshell, 'batchsize', 1);\n if ischar(batchsize) && strcmp(batchsize, 'all')\n batchsize = length(insideindx);\n end\n \n dippos = sourcemodel.pos(insideindx,:);\n ndip = length(insideindx);\n numchunks = ceil(ndip/batchsize);\n \n sourcemodel.leadfield = cell(size(sourcemodel.pos,1),1);\n ft_progress('init', cfg.feedback, 'computing leadfield');\n for k = 1:numchunks\n ft_progress(k/numchunks, 'computing leadfield %d/%d\\n', k, numchunks);\n diprange = (((k-1)*batchsize + 1):(min(k*batchsize,ndip)));\n tmp = ft_compute_leadfield(dippos(diprange,:), sens, headmodel, leadfieldopt{:});\n % distribute the columns of the leadfield matrix over the individual dipole positions\n % avoid using the options reducerank and backproject, see https://github.com/fieldtrip/fieldtrip/issues/1410#issuecomment-646994620\n [m, n] = size(tmp);\n sourcemodel.leadfield(insideindx(diprange)) = mat2cell(tmp, m, repmat(n/numel(diprange), 1, numel(diprange)));\n end\n ft_progress('close');\n \nelseif ft_headmodeltype(headmodel, 'duneuro')\n% ft_hastoolbox('duneuro', 1); %does not look necessary here? check\n % repeated system calls to the duneuro executable makes it rather slow\n % calling it once for all dipoles is much more efficient\n \n % find the indices of all grid points that are inside the brain\n insideindx = find(sourcemodel.inside);\n \n ft_progress('init', cfg.feedback, 'computing leadfield');\n % compute the leadfield on all grid positions inside the brain\n lf = ft_compute_leadfield(sourcemodel.pos(insideindx,:), sens, headmodel, 'reducerank', cfg.reducerank, 'normalize', cfg.normalize, 'normalizeparam', cfg.normalizeparam, 'backproject', cfg.backproject);\n lf = mat2cell(lf, size(lf,1), repmat(3,1,size(lf,2)/3));\n sourcemodel.leadfield(sourcemodel.inside) = lf;\n for i=1:length(insideindx)\n thisindx = insideindx(i);\n if isfield(cfg, 'grid') && isfield(cfg.grid, 'mom')\n % multiply with the normalized dipole moment to get the leadfield in the desired orientation\n sourcemodel.leadfield{thisindx} = sourcemodel.leadfield{thisindx} * sourcemodel.mom(:,thisindx);\n end\n end % for all grid locations inside the brain\n\nelseif ft_headmodeltype(headmodel, 'interpolate')\n\n lf = ft_compute_leadfield(sourcemodel.pos(insideindx,:), sens, headmodel, leadfieldopt{:});\n sourcemodel.leadfield(insideindx) = mat2cell(lf, 3, 3.*ones(1,numel(insideindx)));\n \nelse\n ft_progress('init', cfg.feedback, 'computing leadfield');\n for i=1:length(insideindx)\n % compute the leadfield on all sourcemodel positions inside the brain\n ft_progress(i/length(insideindx), 'computing leadfield %d/%d\\n', i, length(insideindx));\n thisindx = insideindx(i);\n sourcemodel.leadfield{thisindx} = ft_compute_leadfield(sourcemodel.pos(thisindx,:), sens, headmodel, leadfieldopt{:});\n end % for all sourcemodel locations inside the brain\n ft_progress('close');\nend\n\nif isfield(cfg, 'sourcemodel') && isfield(cfg.sourcemodel, 'mom')\n for i=1:length(insideindx)\n % multiply with the normalized dipole moment to get the leadfield in the desired orientation\n % FIXME mom and ori seem to be mixed up here, see https://github.com/fieldtrip/fieldtrip/issues/1399\n thisindx = insideindx(i);\n sourcemodel.leadfield{thisindx} = sourcemodel.leadfield{thisindx} * sourcemodel.mom(:,thisindx);\n end\nend\n\n% represent the leadfield for positions outside the brain as empty array\nsourcemodel.leadfield(~sourcemodel.inside) = {[]};\n\n% add the label of the channels\nsourcemodel.label = sens.label;\nsourcemodel.leadfielddimord = '{pos}_chan_ori';\n\n% mollify the leadfields\nif ~isequal(cfg.mollify, 'no')\n sourcemodel = mollify(cfg, sourcemodel);\nend\n\n% combine leadfields in patches and do an SVD on them\nif ~isequal(cfg.patchsvd, 'no')\n sourcemodel = patchsvd(cfg, sourcemodel);\nend\n\n% compute the 50 percent channel selection subspace projection\nif ~isequal(cfg.sel50p, 'no')\n sourcemodel = sel50p(cfg, sourcemodel, sens);\nend\n\n% compute the local basis function expansion (LBEX) subspace projection\nif ~isequal(cfg.lbex, 'no')\n sourcemodel = lbex(cfg, sourcemodel);\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% do the general cleanup and bookkeeping at the end of the function\nft_postamble debug\nft_postamble previous data\nft_postamble provenance sourcemodel\nft_postamble history sourcemodel\nft_postamble savevar sourcemodel\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/ft_prepare_leadfield.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165085228825, "lm_q2_score": 0.2782567937024021, "lm_q1q2_score": 0.14672940092792267}} {"text": "function ct = matRad_importDicomCt(ctList, resolution, dicomMetaBool, grid, visBool)\n% matRad function to import dicom ct data\n% \n% call\n% ct = matRad_importDicomCt(ctList, resolution, dicomMetaBool)\n% ct = matRad_importDicomCt(ctList, resolution, dicomMetaBool, grid)\n% ct = matRad_importDicomCt(ctList, resolution, dicomMetaBool, visBool)\n% ct = matRad_importDicomCt(ctList, resolution, dicomMetaBool, grid, visBool)\n%\n% input\n% ctList: list of dicom ct files\n% resolution: \tresolution of the imported ct cube, i.e. this function\n% will interpolate to a different resolution if desired\n% dicomMetaBool: store complete dicom information if true\n% grid: optional: a priori grid specified for interpolation\n% visBool: optional: turn on/off visualization\n%\n% output\n% ct: matRad ct struct. Note that this 3D matlab array \n% contains water euqivalent electron denisities.\n% Hounsfield units are converted using a standard lookup\n% table in matRad_calcWaterEqD\n%\n% References\n% -\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Copyright 2015 the matRad development team. \n% \n% This file is part of the matRad project. It is subject to the license \n% terms in the LICENSE file found in the top-level directory of this \n% distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part \n% of the matRad project, including this file, may be copied, modified, \n% propagated, or distributed except according to the terms contained in the \n% LICENSE file.\n%\n% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nmatRad_cfg = MatRad_Config.instance();\n\nmatRad_cfg.dispInfo('\\nimporting ct-cube...');\n\n%% processing input variables\nif ~exist('visBool','var')\n visBool = 0;\nend\n\n% creation of ctInfo list\nnumOfSlices = size(ctList,1);\nmatRad_cfg.dispInfo('\\ncreating info...')\n\nsliceThicknessStandard = true;\nfor i = 1:numOfSlices\n\n if verLessThan('matlab','9')\n tmpDicomInfo = dicominfo(ctList{i,1});\n else\n tmpDicomInfo = dicominfo(ctList{i,1},'UseDictionaryVR',true);\n end\n \n % remember relevant dicom info - do not record everything as some tags\n % might not been defined for individual files\n ctInfo(i).PixelSpacing = tmpDicomInfo.PixelSpacing;\n ctInfo(i).ImagePositionPatient = tmpDicomInfo.ImagePositionPatient;\n ctInfo(i).SliceThickness = tmpDicomInfo.SliceThickness;\n ctInfo(i).ImageOrientationPatient = tmpDicomInfo.ImageOrientationPatient;\n ctInfo(i).PatientPosition = tmpDicomInfo.PatientPosition;\n ctInfo(i).Rows = tmpDicomInfo.Rows;\n ctInfo(i).Columns = tmpDicomInfo.Columns;\n ctInfo(i).Width = tmpDicomInfo.Width;\n ctInfo(i).Height = tmpDicomInfo.Height;\n ctInfo(i).RescaleSlope = tmpDicomInfo.RescaleSlope;\n ctInfo(i).RescaleIntercept = tmpDicomInfo.RescaleIntercept;\n \n %Problem due to some CT files using non-standard SpacingBetweenSlices\n \n if isempty(ctInfo(i).SliceThickness)\n %Print warning ocne\n if sliceThicknessStandard\n matRad_cfg.dispWarning('Non-standard use of SliceThickness Attribute (empty), trying to overwrite with SpacingBetweenSlices');\n sliceThicknessStandard = false;\n end\n ctInfo(i).SliceThickness = tmpDicomInfo.SpacingBetweenSlices;\n end\n \n if i == 1\n completeDicom = tmpDicomInfo;\n end\n \n matRad_progress(i,numOfSlices);\nend\n\n% adjusting sequence of slices (filenames may not be ordered propperly....\n% e.g. CT1.dcm, CT10.dcm, CT100zCoordList = [ctInfo.ImagePositionPatient(1,3)]';.dcm, CT101.dcm,...\nCoordList = [ctInfo.ImagePositionPatient]';\n[~, indexing] = sort(CoordList(:,3)); % get sortation from z-coordinates\n\nctList = ctList(indexing);\nctInfo = ctInfo(indexing);\n\n%% check data set for consistency\nif size(unique([ctInfo.PixelSpacing]','rows'),1) > 1\n matRad_cfg.dispError('Different pixel size in different CT slices');\nend\n\ncoordsOfFirstPixel = [ctInfo.ImagePositionPatient];\nif numel(unique(coordsOfFirstPixel(1,:))) > 1 || numel(unique(coordsOfFirstPixel(2,:))) > 1\n matRad_cfg.dispError('Ct slices are not aligned');\nend\nif sum(diff(coordsOfFirstPixel(3,:))<=0) > 0\n matRad_cfg.dispError('Ct slices not monotonically increasing');\nend\nif numel(unique([ctInfo.Rows])) > 1 || numel(unique([ctInfo.Columns])) > 1\n matRad_cfg.dispError('Ct slice sizes inconsistent');\nend\n\n\n%% checking the patient position\n% As of now, the matRad treatment planning system is only valid for\n% patients in a supine position. Other orientations (e.g. prone, decubitus\n% left/right) are not supported.\n% Defined Terms:\n% HFP Head First-Prone (not supported)\n% HFS Head First-Supine (supported)\n% HFDR Head First-Decubitus Right (not supported)\n% HFDL Head First-Decubitus Left (not supported)\n% FFDR Feet First-Decubitus Right (not supported)\n% FFDL Feet First-Decubitus Left (not supported)\n% FFP Feet First-Prone (not supported)\n% FFS Feet First-Supine (supported)\n\nif isempty(regexp(ctInfo(1).PatientPosition,{'S','P'}, 'once'))\n matRad_cfg.dispError(['This Patient Position is not supported by matRad.'...\n ' As of now only ''HFS'' (Head First-Supine), ''FFS'''...\n ' (Feet First-Supine), '... \n '''HFP'' (Head First-Prone), and ''FFP'''...\n ' (Feet First-Prone) can be processed.']) \nend\n\n%% creation of ct-cube\nmatRad_cfg.dispInfo('reading slices...')\norigCt = zeros(ctInfo(1).Height, ctInfo(1).Width, numOfSlices);\nfor i = 1:numOfSlices\n currentFilename = ctList{i};\n [currentImage, map] = dicomread(currentFilename);\n origCt(:,:,i) = currentImage(:,:); % creation of the ct cube\n \n % draw current ct-slice\n if visBool\n if ~isempty(map)\n image(ind2rgb(uint8(63*currentImage/max(currentImage(:))),map));\n xlabel('x [voxelnumber]')\n ylabel('y [voxelnumber]')\n title(['Slice # ' int2str(i) ' of ' int2str(numOfSlices)])\n else\n image(ind2rgb(uint8(63*currentImage/max(currentImage(:))),bone));\n xlabel('x [voxelnumber]')\n ylabel('y [voxelnumber]')\n title(['Slice # ' int2str(i) ' of ' int2str(numOfSlices)])\n end\n axis equal tight;\n pause(0.1);\n end\n matRad_progress(i,numOfSlices);\nend\n\n%% correction if not lps-coordinate-system\n% when using the physical coordinates (ctInfo.ImagePositionPatient) to\n% arrange the slices in z-direction, there is no more need for mirroring\n% in the z-direction\nmatRad_cfg.dispInfo('\\nz-coordinates taken from ImagePositionPatient\\n')\n\n% The x- & y-direction in lps-coordinates are specified in:\n% ImageOrientationPatient\nxDir = ctInfo(1).ImageOrientationPatient(1:3); % lps: [1;0;0]\nyDir = ctInfo(1).ImageOrientationPatient(4:6); % lps: [0;1;0]\nnonStandardDirection = false;\n\n% correct x- & y-direction\n% \n% if xDir(1) == 1 && xDir(2) == 0 && xDir(3) == 0\n% matRad_cfg.dispInfo('x-direction OK\\n')\n% elseif xDir(1) == -1 && xDir(2) == 0 && xDir(3) == 0\n% matRad_cfg.dispInfo('\\nMirroring x-direction...')\n% origCt = flip(origCt,1);\n% matRad_cfg.dispInfo('finished!\\n')\n% else\n% nonStandardDirection = true;\n% end\n% \n% if yDir(1) == 0 && yDir(2) == 1 && yDir(3) == 0\n% matRad_cfg.dispInfo('y-direction OK\\n')\n% elseif yDir(1) == 0 && yDir(2) == -1 && yDir(3) == 0\n% matRad_cfg.dispInfo('\\nMirroring y-direction...')\n% origCt = flip(origCt,2);\n% matRad_cfg.dispInfo('finished!\\n')\n% else\n% nonStandardDirection = true;\n% end\n\nif nonStandardDirection\n matRad_cfg.dispInfo(['Non-standard patient orientation.\\n'...\n 'CT might not fit to contoured structures\\n'])\nend\n\n%% interpolate cube\nmatRad_cfg.dispInfo('\\nInterpolating CT cube...');\nif exist('grid','var')\n ct = matRad_interpDicomCtCube(origCt, ctInfo, resolution, grid);\nelse\n ct = matRad_interpDicomCtCube(origCt, ctInfo, resolution);\nend\nmatRad_cfg.dispInfo('finished!\\n');\n\n%% remember some parameters of original dicom\nct.dicomInfo.PixelSpacing = ctInfo(1).PixelSpacing;\n tmp = [ctInfo.ImagePositionPatient];\nct.dicomInfo.SlicePositions = tmp(3,:);\nct.dicomInfo.SliceThickness = [ctInfo.SliceThickness];\nct.dicomInfo.ImagePositionPatient = ctInfo(1).ImagePositionPatient;\nct.dicomInfo.ImageOrientationPatient = ctInfo(1).ImageOrientationPatient;\nct.dicomInfo.PatientPosition = ctInfo(1).PatientPosition;\nct.dicomInfo.Width = ctInfo(1).Width;\nct.dicomInfo.Height = ctInfo(1).Height;\nct.dicomInfo.RescaleSlope = ctInfo(1).RescaleSlope;\nct.dicomInfo.RescaleIntercept = ctInfo(1).RescaleIntercept;\nif isfield(completeDicom, 'Manufacturer')\nct.dicomInfo.Manufacturer = completeDicom.Manufacturer;\nend\nif isfield(completeDicom, 'ManufacturerModelName')\nct.dicomInfo.ManufacturerModelName = completeDicom.ManufacturerModelName;\nend\nif isfield(completeDicom, 'ConvolutionKernel')\nct.dicomInfo.ConvolutionKernel = completeDicom.ConvolutionKernel;\nend\n\n% store patientName only if user wants to\nif isfield(completeDicom,'PatientName') && dicomMetaBool == true\n ct.dicomInfo.PatientName = completeDicom.PatientName;\nend\nif dicomMetaBool == true\n ct.dicomMeta = completeDicom;\nend\n\nct.timeStamp = datestr(clock);\n\n% convert to Hounsfield units\nmatRad_cfg.dispInfo('\\nconversion of ct-Cube to Hounsfield units...');\nct = matRad_calcHU(ct);\nmatRad_cfg.dispInfo('finished!\\n');\n\nend\n", "meta": {"author": "e0404", "repo": "matRad", "sha": "0a03aee5ef4a100dbc4bef8927db41b59f44946e", "save_path": "github-repos/MATLAB/e0404-matRad", "path": "github-repos/MATLAB/e0404-matRad/matRad-0a03aee5ef4a100dbc4bef8927db41b59f44946e/dicom/matRad_importDicomCt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5117166047041652, "lm_q2_score": 0.26894141551050293, "lm_q1q2_score": 0.1376217880093667}} {"text": "%%Ex. 2 The meaning of \"a = b\"\n\n\n%In Matlab and in any programming language, the statement \"a = b\" does not mean\n%\"a equals b\". Instead, it prompts the action of replacing the content of a by the\n%content of b.\na = 3;\nb = a;\nb\n\n%Output:3\n", "meta": {"author": "TheAlgorithms", "repo": "MATLAB-Octave", "sha": "e150b77ad256de46c1ce3815c3d7945ac4fc28dc", "save_path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave", "path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave/MATLAB-Octave-e150b77ad256de46c1ce3815c3d7945ac4fc28dc/matlab_for_beginners/part_1(learn_basic_programing)/equal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. NO\n2. NO\n\n", "lm_q1_score": 0.4455295350395727, "lm_q2_score": 0.28140561345566495, "lm_q1q2_score": 0.12537451212042813}}