lung tumour segmentation U-net

조회 수: 7 (최근 30일)
Christos Papagrigoriou
Christos Papagrigoriou 2022년 3월 30일
댓글: Christos Papagrigoriou 2022년 3월 30일
Hello,
I use this function to preproccess data for Lung tumour segmentation, but it does not seem to be working. I dont know what is the mistake I make. I aint a matlab pro to be honest but its part of my dissertation thesis.
data too large to attach but available from https://drive.google.com/drive/folders/1HqEgzS8BV2c7xYNrZdEAnrHk7osJJ--2 (task06)
function preprocessLungTSdataset('finallyproccessed','Task06_Lung');
% Crop the data set to a region containing primarily the lung and tumor.
% Then, normalize each 3-D volumetric series independently
% by subtracting the mean and dividing by the standard deviation of the
% cropped brain region. Finally, split the data set into training,
% validation and test sets.
% Copyright 2019 The MathWorks, Inc.
%% Load data
%volLoc = [source filesep 'imagesTr'];
volLoc = fullfile('Task06_Lung', 'imagesTr');
%lblLoc = [source filesep 'labelsTr'];
lblLoc = fullfile('Task06_Lung','labelsTr');
if ~exist(volLoc,'dir') || ~exist(lblLoc,'dir')
error(['Please unzip Task06_Lung file to Task06_Lung'])
end
moveHiddenFiles(Task06_Lung,volLoc,lblLoc);
% If the directory for preprocessed data does not exist, or only a partial
% set of the data files have been processed, process the data.
if ~exist(finallyproccessed,'dir') || proceedWithPreprocessing('finallyproccessed')
mkdir(fullfile('finallyproccessed','imagesTr'));
mkdir(fullfile('finallyproccessed','labelsTr'));
mkdir(fullfile('finallyproccessed','imagesVal'));
mkdir(fullfile('finallyproccessed','labelsVal'));
mkdir(fullfile('finallyproccessed','imagesTest'));
mkdir(fullfile('finallyproccessed','labelsTest'));
labelReader = @(x) (niftiread(x) > 0);
volReader = @(x) niftiread(x);
volds = imageDatastore(volLoc, ...
'FileExtensions','.gz','ReadFcn',volReader);
classNames = ["background","tumor"];
pixelLabelID = [0 1];
pxds = pixelLabelDatastore(lblLoc,classNames, pixelLabelID, ...
'FileExtensions','.gz','ReadFcn',labelReader);
reset(volds);
reset(pxds);
%% Crop relevant region
NumFiles = length(pxds.Files);
id = 1;
while hasdata(pxds)
outL = readNumeric(pxds);
outV = read(volds);
temp = outL>0;
sz = size(outL);
reg = regionprops3(temp,'BoundingBox');
tol = 64;
ROI = ceil(reg.BoundingBox(1,:));
ROIst = ROI(1:3) - tol;
ROIend = ROI(1:3) + ROI(4:6) + tol;
ROIst(ROIst<1)=1;
ROIend(ROIend>sz)=sz(ROIend>sz);
tumorRows = ROIst(2):ROIend(2);
tumorCols = ROIst(1):ROIend(1);
tumorPlanes = ROIst(3):ROIend(3);
tcropVol = outV(tumorRows,tumorCols, tumorPlanes,:);
tcropLabel = outL(tumorRows,tumorCols, tumorPlanes);
% Data set with a valid size for V-Net (multiple of 8)
ind = floor(size(tcropVol)/8)*8;
incropVol = tcropVol(1:ind(1),1:ind(2),1:ind(3),:);
mask = incropVol == 0;
cropVol = channelWisePreProcess(incropVol);
% Set the nonlung region to 0
cropVol(mask) = 0;
cropLabel = tcropLabel(1:ind(1),1:ind(2),1:ind(3));
% Split data into training, validation and test sets. Roughly 82%
% are training, 6% are validation, and 12% are test
if (id < floor(0.83*NumFiles))
imDir = fullfile('finallyproccessed','imagesTr','LungTS');
labelDir = fullfile('finallyproccessed','labelsTr','LungTS');
elseif (id < floor(0.89*NumFiles))
imDir = fullfile('finallyproccessed','imagesVal','LungTS');
labelDir = fullfile('finallyproccessed','labelsVal','LungTS');
else
imDir = fullfile('finallyproccessed','imagesTest','LungTS');
labelDir = fullfile('finallyproccessed','labelsTest','LungTS');
end
save([imDir num2str(id,'%.3d') '.mat'],'cropVol');
save([labelDir num2str(id,'%.3d') '.mat'],'cropLabel');
id=id+1;
end
end
end
function out = channelWisePreProcess(in)
% As input has 4 channels (modalities), remove the mean and divide by the
% standard deviation of each modality independently.
chn_Mean = mean(in,[1 2 3]);
chn_Std = std(in,0,[1 2 3]);
out = (in - chn_Mean)./chn_Std;
rangeMin = -5;
rangeMax = 5;
% Remove outliers
out(out > rangeMax) = rangeMax;
out(out < rangeMin) = rangeMin;
% Rescale the data to the range [0, 1]
out = (out - rangeMin) / (rangeMax - rangeMin);
end
function moveHiddenFiles('Task06_Lung',volLoc,lblLoc)
% The original data set includes hidden files whose filenames begin with
% "._". Move these files out of the training, test, and validation data
% directories.
myLoc = pwd;
hiddenDir = fullfile('Task06_Lung','HiddenFiles');
if ~exist(hiddenDir,'dir')
mkdir(hiddenDir);
cd(volLoc);
!move ._* ../HiddenFiles/
cd(lblLoc)
!move ._* ../HiddenFiles/
end
cd(myLoc)
end
function out = proceedWithPreprocessing('finallyproccessed')
totalNumFiles = 63;
numFiles = 0;
if exist(fullfile('finallyproccessed','imagesTr'),'dir')
tmp1 = dir(fullfile('finallyproccessed','imagesTr'));
numFiles = numFiles + sum(~vertcat(tmp1.isdir));
end
if exist(fullfile('finallyproccessed','imagesVal'),'dir')
tmp1 = dir(fullfile('finallyproccessed','imagesVal'));
numFiles = numFiles + sum(~vertcat(tmp1.isdir));
end
if exist(fullfile('finallyproccessed','imagesTest'),'dir')
tmp1 = dir(fullfile('finallyproccessed','imagesTest'));
numFiles = numFiles + sum(~vertcat(tmp1.isdir));
end
% If total number of preprocessed files is not equal to the number of
% files in the dataset, perform preprocessing. Otherwise, preprocessing has
% already been completed and can be skipped.
out = (numFiles ~= totalNumFiles);
end
  댓글 수: 1
Christos Papagrigoriou
Christos Papagrigoriou 2022년 3월 30일
>> polla
File: preprocessLungTSdataset.m Line: 1 Column: 34
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To
construct matrices, use brackets instead of parentheses.
this is the error that it comes up with

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by