動画をグレースケールに変更するやり方
    3 views (last 30 days)
  
       Show older comments
    
動画をグレースケールに変更して再生したいのですがやり方が分かりません。お願いします。
I = VideoReader('IMG_2017.2.mp4')
get(I)
implay('IMG_2017.2.mp4');
nframes = I.NumberOfFrames;
R = read(I, 1);
Z = zeros([size(R,1) size(R,2) 3 nframes], class(R));
for k = 1 : nframes
 SF = read(I, k);
 RG = rgb2gray(SF);
end
implay(RG);
0 Comments
Answers (1)
  Kei Otsuka
    
 on 21 Nov 2017
        ループ文の中でグレースケールに変更するところまでは既にできているようなので、 あとは可視化してあげれば完成です。imshowでも良いですし、ビデオプレーヤーオブジェクトを使用しても可視化できます。
v = VideoReader('IMG_2017.2.mp4');
p = vision.VideoPlayer;
while hasFrame(v)
  vidFrame = readFrame(v);
  gray = rgb2gray(vidFrame);
  p(gray)
end
2 Comments
  Kei Otsuka
    
 on 21 Nov 2017
				for文にしたい理由はインデックスを使いたいということでしょうか。
v = VideoReader('ecolicells.avi');
p = vision.VideoPlayer;
nframe = round(v.Duration*v.FrameRate);
for i = 1:nframe
vidFrame = readFrame(v);
gray = rgb2gray(vidFrame);
p(gray)
end
のように使うか、while文のままでもインデックスを表す変数を作れば使えると思います。
v = VideoReader('IMG_2017.2.mp4');
p = vision.VideoPlayer;
idx = 1;
while hasFrame(v)
vidFrame = readFrame(v);
gray = rgb2gray(vidFrame);
p(gray)
idx = idx + 1;
end
imcrop利用時のエラーは、どのような使い方をしているかわからないので コメントが難しいです。 少なくともエラーメッセージを添付するか、現在試されているスクリプトを添付しないと 良い回答は得られないですよ。
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!
