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

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

 Risposta accettata

Satoshi Kobayashi
Satoshi Kobayashi il 13 Feb 2019

2 voti

mriVolumeOriginalの枚数が不明なので断言はできませんが、
行数、列数および平面数を直接指定した方がよろしいのではないでしょうか。
mriVolumeResized = imresize3(mriVolumeOriginal, [227 227 3]);

4 Commenti

ssk
ssk il 13 Feb 2019
ご回答ありがとうございます。頂いたコードをもとに自身のコードを書いてコンパイルしてみました。
%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);
mriVolumeResized = imresize3(imds, [227 227 3]);
すると、以下のエラーが出てしまいます。
Error using imresize3
Expected input number 1, V, to be one of these types:
single, double, int8, int16, int32, uint8, uint16, uint32
Instead its type was matlab.io.datastore.ImageDatastore.
こちらの解決方法につきまして何かご示唆がございましたらご教示の程、どうぞよろしくお願いいたします。
Satoshi Kobayashi
Satoshi Kobayashi il 16 Feb 2019
imresize3はデータストアを受け付けません。
データストアに保存されているのは一枚のデータの集合ですが、今作ろうとなさっているのは三枚のデータです。
mriVolumeOriginalとして想定しているのは、一枚でしょうか。それとも同じタグの複数枚でしょうか。
前者なら、
imds = imageDatastore(fullfile(currentdirectory, categories),'IncludeSubfolders',true,'FileExtensions','.dcm','LabelSource', 'foldernames','ReadFcn',@dicomread);
を以下のように置換するという解決法があります。
imds = imageDatastore(fullfile(currentdirectory, categories),'IncludeSubfolders',true,'FileExtensions','.dcm','LabelSource', 'foldernames','ReadFcn',@(a)imresize3(dicomread(a), [227 227 3]));
後者なら、imresize3を使うためには、データストアを使って画像を読み込んだ後でimresize3を使うという方法しか思いつきません。
ssk
ssk il 16 Feb 2019
Modificato: ssk il 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 il 17 Feb 2019
Modificato: Satoshi Kobayashi il 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
この例では、最終出力をセル配列にしましたが、この後の工程によっては三次元か四次元配列の方がよいのかもしれません。
また、リサイズしたものをファイルとして保存する方がよい場合もあります。

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!