複数枚の画像をfor文を使って処理したいです
26 views (last 30 days)
Show older comments
複数枚の画像(ファイルにある全ての画像)をfor文を使って処理がしたいです.
以下のような処理をしましたが,画像ファイルを指定できていないので,エラーが出ます.
for n = 1:100
I = imshow('n.jpg');
[nrows,ncols] = size(get(I,'CData'));
xdata = get(I,'XData');
xlength = xdata(1,2)
ylength = ydata(1,2)
pixcelsize =xlength *ylength
end
0 Comments
Accepted Answer
Kenta
on 29 May 2019
clear;clc
im_list= dir('*.jpg');
list_tbl=struct2table(im_list);
im_name=list_tbl.name;
for i=1:size(im_name,1)
I=imread(im_name{i});
%以下、操作を加える
end
このように、~.jpgというファイルをリスト化して、それを1つずつ読み取るとよいと思います。
imds = imageDatastore(pwd);
for i=1:numel(imds.Files)
I=read(imds);
%以下操作を加える
end
また、jpgファイルをイメージデータストアに格納して、1から読んでいくのもよいかもしれません。
ちなみに、上のfor文内での操作は、何を意図されていますでしょうか。
2 Comments
Kenta
on 30 May 2019
im_name{1}は、1.jpgとなっていますか?ループ内は通常通り画像を読んでいるだけなのでとくに大きな差はないように感じます。
[tate, yoko, ~]=size(I);
pixel_num=tate*yoko;
それと、画像サイズとピクセル数なら上のコードで読み込めます。ご確認ください。
More Answers (1)
See Also
Categories
Find more on イメージ算術 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!