5枚の画像データを読み込み、それぞれのデータを記憶していきたいのですが………
Mostrar comentarios más antiguos
5枚の画像をそれぞれ読み込んでデータを記憶させたいのですが、なぜか5枚目のデータしか表示されません。どうしたらよいのか教えていただけませんか?
10 comentarios
添付の MATLAB.txt を転記します。
clear all;
for j=1:5
abc = strcat(num2str(j),'.jpg');
BW=imread(abc);
image(BW)
BW2=rgb2gray(BW)>0;
end
%%regionprops を使用してイメージ内の連結要素の重心を計算します。
s = regionprops(BW2,'centroid');
%%各重心位置計算されたエリアの面積
Areas = regionprops(BW2,'Area');
%%角度計算
Orientations = regionprops(BW2,'Orientation');
%%重心を格納する構造体配列を単一の行列に連結します。
centroids = cat(1, s.Centroid);
centroids2 = cat(1, Areas.Area);
centroids(:,3) = centroids2;
length(centroids)
j=1;
for i=1:length(centroids)
if (centroids(i,3)>1000 && centroids(i,3)<10000)
medaka_index = i;
end
end
%%重心の位置を重ね合わせたバイナリ イメージを表示します。
imshow(BW)
hold on
plot(centroids(medaka_index,1),centroids(medaka_index,2), 'b*')
hold off
Jiro Doke
el 12 de Dic. de 2017
プログラムをよく見ていただくと分かると思いますが、最初のループの実行が終わったら、 BW2 には何が入っているでしょうか。一番最後(5枚目)の画像が白黒に変換されたものですよね。その画像がそれ以降使われているわけです。
要点だけ言いますと、以降の処理を全部最初のループの中に入れてあげればいいと思います。
試してみてください。
Takuya Nagai
el 13 de Dic. de 2017
mizuki
el 13 de Dic. de 2017
こんな感じでインデクスを使ってやればよいのでは。 1枚目から5枚目の 01 行列が並ぶような感じです。
for i = 1:3
BW2(:,:,i) = rgb2gray(BW)>0;
end
Takuya Nagai
el 13 de Dic. de 2017
Jiro Doke
el 13 de Dic. de 2017
もう少しなので頑張ってみましょう!
figure コマンドを紹介しましたが、 imread、 image、 imshow すべてを figure に変える、という事ではありません。もう一度 figure のドキュメンテーションをご覧になり、 figure コマンドの役割を把握してみましょう。
(ドキュメンテーションから)
figure - Figure ウィンドウの作成
Takuya Nagai
el 13 de Dic. de 2017
Jiro Doke
el 13 de Dic. de 2017
figure コマンドは単体で使えます。 BW=figure とやる必要はありません。
最後のデータしか残らないのは、ループが回る度に centroids が更新(上書き)されるからです。もし単に座標データを目で確認したいだけならば、ループの中で centroid をコマンドウィンドウに表示するようにすれば良いと思います。ヒント: disp
Takuya Nagai
el 14 de Dic. de 2017
Respuestas (0)
Categorías
Más información sobre イメージ算術 en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!