Permalink
Browse files

changes for PT export

  • Loading branch information...
adityaapte committed Aug 30, 2018
1 parent 0745ccb commit 06001a486337c280c8e1df30ffb9ae5e048aba33
@@ -82,6 +82,9 @@
case 'ct_image'
tagS = CT_image_module_tags;
export_function = @export_CT_image_module_field;
case 'pt_image'
tagS = PT_image_module_tags;
export_function = @export_PT_image_module_field;
case 'mr_image'
tagS = MR_image_module_tags;
export_function = @export_MR_image_module_field;
@@ -120,6 +120,8 @@
%data = 1;
%data = scanInfoS.rescaleSlope;
data = args.data{3}; %APA: factor for conversion to uint16 for modalities other than CT
bools = [scanS.scanInfo.zValue] == scanInfoS.zValue;
data = data(bools);
el = template.get(tag);
el = ml2dcm_Element(el, data);
@@ -179,7 +179,8 @@
data = scanS.scanArray(:,:,sliceNum);
%Convert to unsigned 16-bit integer if scanArray is single
scaleFactor = args.data{4};
scaleFactorV = args.data{4};
scaleFactor = scaleFactorV(sliceNum);
data = uint16(data/scaleFactor);
data = data';
@@ -57,6 +57,8 @@
tagS = image_pixel_module_tags;
case 'ct_image'
tagS = CT_image_module_tags;
case 'pt_image'
tagS = PT_image_module_tags;
case 'mr_image'
tagS = MR_image_module_tags;
case 'sop_common'
@@ -5,47 +5,81 @@
% Number of Gray levels
nL = 4;
voxelOffset = 1;
dirFlag = 1;
% Random n x n x n matrix
n = 10;
testM = rand(n,n,n);
testM = imquantize_cerr(testM,nL);
maskBoundingBox3M = testM .^ 0;
% Structure from planC
global planC
indexS = planC{end};
scanNum = 1;
structNum = 16;
[rasterSegments, planC, isError] = getRasterSegments(structNum,planC);
[mask3M, uniqueSlices] = rasterToMask(rasterSegments, scanNum, planC);
scanArray3M = getScanArray(planC{indexS.scan}(scanNum));
% % Structure from planC
% global planC
% indexS = planC{end};
% scanNum = 1;
% structNum = 16;
%
% [rasterSegments, planC, isError] = getRasterSegments(structNum,planC);
% [mask3M, uniqueSlices] = rasterToMask(rasterSegments, scanNum, planC);
% scanArray3M = getScanArray(planC{indexS.scan}(scanNum));
%
% SUVvals3M = mask3M.*double(scanArray3M(:,:,uniqueSlices));
% [minr, maxr, minc, maxc, mins, maxs]= compute_boundingbox(mask3M);
% maskBoundingBox3M = mask3M(minr:maxr,minc:maxc,mins:maxs);
% volToEval = SUVvals3M(minr:maxr,minc:maxc,mins:maxs);
% volToEval(maskBoundingBox3M==0) = NaN;
%
% testM = imquantize_cerr(volToEval,nL);
SUVvals3M = mask3M.*double(scanArray3M(:,:,uniqueSlices));
[minr, maxr, minc, maxc, mins, maxs]= compute_boundingbox(mask3M);
maskBoundingBox3M = mask3M(minr:maxr,minc:maxc,mins:maxs);
volToEval = SUVvals3M(minr:maxr,minc:maxc,mins:maxs);
volToEval(maskBoundingBox3M==0) = NaN;
testM = imquantize_cerr(volToEval,nL);
% % CERR texture
% flagS.energy = 1;
% flagS.entropy = 1;
% flagS.corr = 1;
% flagS.haralickCorr = 1;
% flagS.clustShade = 1;
% flagS.clustProm = 1;
% flagS.contrast = 1;
% flagS.invDiffMoment = 1;
% flagS.sumAvg = 1;
glcmFlagS.energy = 1;
glcmFlagS.jointEntropy = 1;
glcmFlagS.jointMax = 1;
glcmFlagS.jointAvg = 1;
glcmFlagS.jointVar = 1;
glcmFlagS.contrast = 1;
glcmFlagS.invDiffMoment = 1;
glcmFlagS.sumAvg = 1;
glcmFlagS.corr = 1;
glcmFlagS.clustShade = 1;
glcmFlagS.clustProm = 1;
glcmFlagS.haralickCorr = 1;
glcmFlagS.invDiffMomNorm = 1;
glcmFlagS.invDiff = 1;
glcmFlagS.invDiffNorm = 1;
glcmFlagS.invVar = 1;
glcmFlagS.dissimilarity = 1;
glcmFlagS.diffEntropy = 1;
glcmFlagS.diffVar = 1;
glcmFlagS.diffAvg = 1;
glcmFlagS.sumVar = 1;
glcmFlagS.sumEntropy = 1;
glcmFlagS.clustTendency = 1;
glcmFlagS.autoCorr = 1;
glcmFlagS.invDiffMomNorm = 1;
glcmFlagS.firstInfCorr = 1;
glcmFlagS.secondInfCorr = 1;
% CERR texture
flagS.energy = 1;
flagS.entropy = 1;
flagS.corr = 1;
flagS.haralickCorr = 1;
flagS.clustShade = 1;
flagS.clustProm = 1;
flagS.contrast = 1;
flagS.invDiffMoment = 1;
flagS.sumAvg = 1;
tic
cooccurType = 2; % generates separate cooccurrance matrix for each direction.
offsetsM = getOffsets(1);
offsetsM = getOffsets(dirFlag) * voxelOffset;
offsetsM = offsetsM(1:2,:);
cooccurM = calcCooccur(testM, offsetsM, nL, cooccurType);% Note: cooccurM is
% ... of size (nLxnL, number of directions)
featureS = cooccurToScalarFeatures(cooccurM, flagS);
featureS = cooccurToScalarFeatures(cooccurM, glcmFlagS);
toc
%% ITK texture
@@ -78,21 +112,23 @@
% run ITK's textutre calculation
cd(globalGlcmDir)
tic
system([fullfile(globalGlcmDir,'GlobalGlcmFeatures'), ' ', scanFileName, ' 4 1 4 ', maskFileName])
% system([fullfile(globalGlcmDir,'GlobalGlcmFeatures'), ' ', scanFileName, ' 4 1 4 ', maskFileName])
system([fullfile(globalGlcmDir,'GlobalGlcmFeatures'), ' ', scanFileName, ' ',...
num2str(nL), ' ', num2str(1), ' ', num2str(nL), ' ', maskFileName])
toc
fileC = file2cell('GlobalGlCMfeatures.txt');
% feature order from ITK:
% Energy, Entropy, Correlation, InverseDifferenceMoment, Inertia, ClusterShade
% ClusterProminence, HaralickCorrelation
featuresM = [];
for off = 1:13
for off = 1:size(offsetsM,1)
featuresM(off,:) = strread(fileC{off*2});
end
orderV = [11, 13, 10, 12, 5, 8, 9, 7, 6, 4, 1, 2, 3]; % map direction order ...
% ... between CERR and ITK.
maxEnergyDiff = max(abs((featuresM(orderV,1) - featureS.energy')./featureS.energy'*100));
maxEntropyDiff = max(abs((featuresM(orderV,2) - featureS.entropy')./featureS.entropy'*100));
maxEntropyDiff = max(abs((featuresM(orderV,2) - featureS.jointEntropy')./featureS.jointEntropy'*100));
maxInvDiffMomDiff = max(abs((featuresM(orderV,4) - featureS.invDiffMom')./featureS.invDiffMom'*100));
maxContrastDiff = max(abs((featuresM(orderV,5) - featureS.contrast')./featureS.contrast'*100));
maxClustShadeDiff = max(abs((featuresM(orderV,6) - featureS.clustShade')./featureS.clustShade'*100));

0 comments on commit 06001a4

Please sign in to comment.