DICOMファイルのリサイズにつきまして

5 views (last 30 days)
ssk
ssk on 12 Feb 2019
Edited: Satoshi Kobayashi on 17 Feb 2019
プログラミング初心者です。
現在256*256ピクセルのDICOM画像がございます。
AlexNetで本画像を使用するため、サイズを227 x 227 x 3に変更する必要がございます。
mriVolumeResized = imresize3(mriVolumeOriginal, 0.8867);
sizeR = size(mriVolumeResized);
以上のコードの書き方でよろしいでしょうか。
どうぞよろしくお願いいたします。

Accepted Answer

Satoshi Kobayashi
Satoshi Kobayashi on 13 Feb 2019
mriVolumeOriginalの枚数が不明なので断言はできませんが、
行数、列数および平面数を直接指定した方がよろしいのではないでしょうか。
mriVolumeResized = imresize3(mriVolumeOriginal, [227 227 3]);
  4 Comments
ssk
ssk on 16 Feb 2019
Edited: ssk on 16 Feb 2019
ご回答ありがとうございます。mriVolumeOriginalとして想定しているのは、後者(同じタグの複数枚)です。
imds = imageDatastore(fullfile(currentdirectory, categories),'IncludeSubfolders',true,'FileExtensions','.dcm','LabelSource', 'foldernames','ReadFcn',@(a)imresize3(dicomread(a), [227 227 3]));
頂いた上記コードですと、aのフォルダのDICOM画像10枚のみリサイズされるかと思うのですが、aだけでなく、b、c、d全てのサブフォルダーのDICOM画像のリサイズを考えておりました。後者の場合のコードはどういったものが考えられますでしょうか?
Satoshi Kobayashi
Satoshi Kobayashi on 17 Feb 2019
Edited: Satoshi Kobayashi on 17 Feb 2019
imds = imageDatastore(fullfile(currentdirectory, categories),'IncludeSubfolders',true,'FileExtensions','.dcm','LabelSource', 'foldernames','ReadFcn',@(a)imresize3(dicomread(a), [227 227 3]));
上記コードでaという文字を使ったことに意味はありません。どのフォルダのファイルを読み込む場合も227x227x3として読み込むという意図でした。
本題とは関係ありませんが、imresize3は二次元配列が入力ではエラーとなるので、一枚のときには以下のようにすべきでした。
imds = imageDatastore(fullfile(currentdirectory, categories),'IncludeSubfolders',true,'FileExtensions','.dcm','LabelSource', 'foldernames','ReadFcn',@(a)imresize3(repmat(dicomread(a),1,1,3), [227 227 3]));
さて、本題の全てのサブフォルダーのDICOM画像のリサイズですが、以下のようにして実行可能です。
%path = current directory
currentdirectory = pwd;
% set categories of subdirectory
categories = {'a', 'b', 'c','d'};
imds = imageDatastore(fullfile(currentdirectory, categories),'IncludeSubfolders',true,'FileExtensions','.dcm','LabelSource', 'foldernames','ReadFcn',@dicomread);
T = countEachLabel(imds);
nOfEachLabel = table2array(T(:,2));
mriVolumeResizeds = cell(length(categories),1);
for m = 1:length(categories)
imdsTmp = splitEachLabel(imds,nOfEachLabel(m),'Include',categories{m});
mriVolumeOriginal = cell2mat(permute(readall(imdsTmp),[2,3,1]));
mriVolumeResized = imresize3(mriVolumeOriginal, [227 227 3]);
mriVolumeResizeds{m} = mriVolumeResized;
end
この例では、最終出力をセル配列にしましたが、この後の工程によっては三次元か四次元配列の方がよいのかもしれません。
また、リサイズしたものをファイルとして保存する方がよい場合もあります。

Sign in to comment.

More Answers (0)

Categories

Find more on DICOM Format in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!