複数ファイルに対してコマンド実行

14 vues (au cours des 30 derniers jours)
Egoshi
Egoshi le 27 Sep 2021
Commenté : Egoshi le 28 Sep 2021
n = 12;
for i = 1:n
data = ['32deg_cam1_ (', num2str(i),').jpg'];
pic = imread(data);
gray = rgb2gray(pic);
bw = imbinarize(gray);
bw2 = bwareaopen(bw,30);
boundaries = bwboundaries(bw2,'noholes');
imshow(bw2);
hold on
for k = 1:n
b = boundaries{k};
plot(b(:,2),b(:,1),'g','LineWidth',2);
end
end
複数のイメージ(12枚の写真)に対してのコマンドです.途中までは12枚すべてに処理がなされているのですが,hold on 以下を追加すると1枚目にしかプログラムが適用されませんでした.エラーはなかったのですが,どう変えればよいのでしょうか.

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 27 Sep 2021
hold on により現在の座標軸のプロットを保持したまま他の描画を上書きする事が出来ますが、imshowはfigureの全画素を更新するのでhold onの効果がありません。画面を12枚用意して、それぞれの画像に境界線を描画すれば目的を果たせるのではないでしょうか?
n = 6; % 都合上数字を変更しました
for i = 1:n
data = ['office_', num2str(i),'.jpg']; % 都合上画像を変更しました
pic = imread(data);
gray = rgb2gray(pic);
bw = gray > 55; % imbinarize(gray); % 都合上二値化の具合を変更しました
bw2 = bwareaopen(bw,100);
boundaries = bwboundaries(bw2,'noholes');
figure; % <<<<==== ここで新しいfigureを用意する
imshow(bw2);
hold on;
for k = 1:n
b = boundaries{k};
plot(b(:,2),b(:,1),'g','LineWidth',2);
end
end
Index exceeds the number of array elements. Index must not exceed 4.
  1 commentaire
Egoshi
Egoshi le 28 Sep 2021
すべてに適用できました,figureの使い方がよくわかっていなかったので勉強します.
ありがとうございました.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!