MITK多个Mask如何取 或集?
MITK多个Mask如何去或集?
最终的解决方案,将多个Mask都导出来,自己写一个matlab脚本取并集
code 路径:
D:\MATLABProject\CTA
部分code内容:
%% 这个脚本的目的是为了:读取用MITK软件标注的Mask,然后将含有斑块的Mask
% 与原始数目分别存下来;
clear all;close all;clc;
addpath('D:\MATLABProject\CTA\NIfTI_20140122');
dataPath = 'D:\Data\CTALabelData';
outputPath = 'D:\Data\CTAMaskAndOriData';%保存的格式和训练Unet网络一样;.png
dirData = dir([dataPath, '\*.nii']);
len = size(dirData,1);
groupNames = {};
for i = 1:len
%do something
tmpName = dirData(i).name;
tmpName = tmpName(1:end-4);
% disp(tmpName);
if ~contains(tmpName,'M')
%do
groupNames{end+1,1} = tmpName;
end
end
GroupNum = size(groupNames,1);
Counter = 0;%用来计数,每一张图片对应一张唯一的编号;
for i = 1:GroupNum
%do something
thisGroupName = groupNames{i,1};
thisGroupOriDataPath = [dataPath '\' thisGroupName '.nii'];
thisGroupOriDataPathDicom = ['D:\Data\CTASourceData\' thisGroupName '\'];
% thisGroupOriDataPath = ['D:\Data\CTASourceData\' thisGroupName '\'];
thisGroupOriDataNii = load_nii(thisGroupOriDataPath);
thisGroupOriData = thisGroupOriDataNii.img;
[m,n,p] = size(thisGroupOriData);
thisGroupMask = zeros(m,n,p);
disp('##########################################');
for j = 1:len
%do something
tmpNameJ = dirData(j).name;
% tmpNameJ = tmpNameJ(1:end-4);
% disp(tmpNameJ);
if contains(tmpNameJ,'M') && contains(tmpNameJ,thisGroupName)
%do
disp(tmpNameJ);
% Read Mask;
tmpMaskNii = load_nii([dataPath '\' tmpNameJ]);
tmpMask = tmpMaskNii.img;
thisGroupMask = or(thisGroupMask, tmpMask);
end
end
thisGroupLayers = size(thisGroupOriData,3);
% Mask = [];
% index = [];
for j = 1:thisGroupLayers
%do something
tmpImg = thisGroupMask(:,:,j);
if(max(tmpImg(:))~= 0)
imageData = dicomread([thisGroupOriDataPathDicom num2str(j)]);%save it;
disp(min(imageData(:)));
labelData = thisGroupMask(:,:,j);%save it;
imwrite(imageData,[outputPath '\image\' num2str(Counter) '.png']);
imwrite(labelData,[outputPath '\label\' num2str(Counter) '.png']);
Counter = Counter + 1;
end
end
end