Video Display with Histogram

3 次查看(过去 30 天)
Hi,
I want to run at the left side of my figure a video and to show at the right side the corresponding live histogram. First of all, is this possible in Matlab?
I have a code to run the video and one to display the histograms. But it didn't work together. Thanks in advance for every hint!
First code:
% Display video
v = VideoReader('myVideo.avi');
ii = 1;
while hasFrame(v)
mov(ii) = im2frame(readFrame(v));
ii = ii+1;
end
movie(gcf,mov)
Second code:
% Display histograms
v = VideoReader('myVideo.avi');
while hasFrame(v)
thisFrame= readFrame(v); % Get one RGB frame of the color video.
redChannel = thisFrame(:,:,1); % Extract red channel only.
[pixelCounts, grayLevels] = imhist(redChannel); % Get histogram of red channel.
figure(1), subplot (1,2,2),stem(grayLevels, pixelCounts);
end

回答(1 个)

Gaurav Ahuja
Gaurav Ahuja 2017-6-9
I think this should help.
if true
v = VideoReader('SampleVideo_640x360_1mb.mp4');
ii = 1;
while hasFrame(v)
f= readFrame(v);
mov(ii) = im2frame(f);
ii = ii+1;
subplot (1,2,1)
imshow (f)
thisFrame= f; % Get one RGB frame of the color video.
redChannel = thisFrame(:,:,1); % Extract red channel only.
[pixelCounts, grayLevels] = imhist(redChannel); % Get histogram of red channel.
figure(1), subplot (1,2,2),stem(grayLevels, pixelCounts);
drawnow;
end
end
  1 个评论
Gholamreza Jahangiri
Hi,
I need this code with some modifiation. I want to make each frame to gray scale, and then get the minimum value for each pixel in the video and build a hisogram to apply that histogram to the video. So, I have a video with no changing in brighness, just need the movements of pixels.
Thanks
Reza

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by