ループ文での画像ファイルの移動

imageDatastoreを使って画像を読み込んで、一つ一つの画像の大きさを調べて、 20pixel以下の時には、その画像ファイルを移動させるものを作りたいのです。 しかし、ループ文中でのmovefileの『’k.jpg’』部分が間違っていることは分かったのですが、 画像ファイルを指定する方法がわかりません。 どのようにするのが、ベストか教えてください。 よろしくお願いします。
numfiles = length(dir('*.jpg'));
ImTrain = imageDatastore('./','IncludeSubfolders',false,'FileExtensions','.jpg','LabelSource','foldernames') ;
Tx=readall(ImTrain);
for k = 1:numfiles
[w,h,z]=size(Tx{k});
if (w<20)&& (h<20)
movefile('k.jpg','\Documents\MATLAB\Zostera\');
end
end

댓글 수: 1

Walter Roberson
Walter Roberson 2017년 9월 20일
Approximate translation:
I'd like to read images using imageDatastore, examine the size of each image, and when creating images below 20 pixels, I would like to create an image that moves the image file. However, I understood that the '' k.jpg '' part of movefile in the loop statement is wrong, but I do not know how to specify the image file. Please tell me how to do the best. Thank you.

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

답변 (1개)

michio
michio 2017년 9월 20일

2 개 추천

例えば
ImTrain.Files{1}
とすると1枚目の画像へのパスが表示されるので確認できますが、imageDatastore のプロパティの1つ Files にファイルへの絶対パス情報がありますので、これを使うのも手かと思います。
movefile(ImTrain.Files{k},'\Documents\MATLAB\Zostera\');
への変更でうまくいくでしょうか?

댓글 수: 1

KENji
KENji 2017년 9월 20일
条件式を変え、教えて頂いたコードを試すと上手くいきました!! ありがとうございます。

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

카테고리

도움말 센터File Exchange에서 ファイルの操作에 대해 자세히 알아보기

질문:

2017년 9월 20일

댓글:

2017년 9월 20일

Community Treasure Hunt

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

Start Hunting!