Clear Filters
Clear Filters

Video Display with Histogram

4 views (last 30 days)
Veilchen1900
Veilchen1900 on 6 Jun 2017
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

Answers (1)

Gaurav Ahuja
Gaurav Ahuja on 9 Jun 2017
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 Comment
Gholamreza Jahangiri
Gholamreza Jahangiri on 4 Feb 2020
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!