transformで​コントラスト変換した​画像の表示

조회 수: 8 (최근 30일)
拓 青柳
拓 青柳 2022년 10월 23일
답변: Kojiro Saito 2022년 11월 25일
深層学習によるX線画像の2クラス分類を行っております。
以下のコードによりimdsDatastore内の画像に対しコントラスト変換を行い、表示しようとしておりますが、
imshowを実行した際にエラーが発生してしまいます。ご教示ください。変換した画像を見る方法が他にあればそれでも構いません。
in=[0.1 0.9];
out=[];
%%
imdsTrainnew = transform(imdsTrain,@(x) imadjust(x,in,out));
%%
minibatch = read(imdsTrainnew);
%%
imshow(imtile(minibatch.index))
この型の変数ではドット インデックスはサポートされていません。
エラー: untitled3 (10)
imshow(imtile(minibatch.index))
>>
  댓글 수: 1
Atsushi Ueno
Atsushi Ueno 2022년 10월 23일
画像データminibatchにフィールド名は存在せず、minibatch.indexとアクセスする事は出来ません。このindexとは何にアクセスしようとしたのですか?おそらくaugmentedImageDatastore関数の何かと勘違いしていると想定します。
  • ImageDatastoreのreadメソッドで得られる出力は「整数配列(イメージ)」
  • TransformedDatastoreのreadメソッドで得られる出力は「場合により異なる:TransformedDatastore の作成に使用される transform メソッドで指定された変換関数 @fcn の出力と同じ」即ち「imadjust関数の出力:整数配列(調整されたイメージ)」

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

답변 (1개)

Kojiro Saito
Kojiro Saito 2022년 11월 25일
minibatch = read(imdsTrainnew)を実行しているところでminibatchに格納されているのが画像データ(数値配列)になっていて、indexというプロパティが無いのが原因です。
画像全てを一度に読み込んでもメモリーが十分あるなら、readallTransformedDatastoreの中の画像をまとめて読み込んでimshowができます。
%%
in=[0.1 0.9];
out=[];
imdsTrain = imageDatastore({'street1.jpg', 'street2.jpg'});
imdsTrainNew = transform(imdsTrain,@(x) imadjust(x,in,out));
allImg = readall(imdsTrainNew);
imshow(allImg)
imtileではなく、tiledlayoutを使って画像の枚数ごとにreadで読み取ってタイル状に表示することもできます。
%%
in=[0.1 0.9];
out=[];
% ダミー画像
imdsTrain = imageDatastore({'cameraman.tif', 'street1.jpg', 'corn.tif','peppers.png'});
imdsTrainNew = transform(imdsTrain,@(x) imadjust(x,in,out));
% 画像の枚数を取得
numImg = length(imdsTrainNew.UnderlyingDatastores{1, 1}.Files);
% タイル状にプロット
figure
tiledlayout(1,numImg,"TileSpacing","tight");
for n=1:numImg
nexttile
img = read(imdsTrainNew);
imshow(img);
end

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!