How do I determine RGB values for a single column of an image?
Show older comments
I have a video with over 2000 frames (1080x1920x3) and I want to determine the RGB values of all the frames at column 600.
I need to have 3 matrix with size [1080(rows), 2000(numberofFrames)] for red , green, and blue.
The following is my code. The matrix dimensions do not match and I don't know how to resolve it.
clc;
close all;
imtool close all;
clear;
workspace;
fontSize = 22;
folder = fileparts(which('pan-head.mp4'));
movieFullFileName = fullfile(folder, 'pan-head.mp4');
if ~exist(movieFullFileName, 'file')
strErrorMessage = sprintf('File not found:\n%s\nYou can choose a new one, or cancel', movieFullFileName);
response = questdlg(strErrorMessage, 'File not found', 'OK - choose a new movie.', 'Cancel', 'OK - choose a new movie.');
if strcmpi(response, 'OK - choose a new movie.')
[baseFileName, folderName, FilterIndex] = uigetfile('*.avi');
if ~isequal(baseFileName, 0)
movieFullFileName = fullfile(folderName, baseFileName);
else
return;
end
else
return;
end
end
videoObject = VideoReader(movieFullFileName)
numberOfFrames = videoObject.NumberOfFrames;
vidHeight = videoObject.Height;
vidWidth = videoObject.Width;
numberOfFramesWritten = 0;
figure;
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
promptMessage = sprintf('Do you want to save the individual frames out to individual disk files?');
button = questdlg(promptMessage, 'Save individual frames?', 'Yes', 'No', 'Yes');
if strcmp(button, 'Yes')
writeToDisk = true;
[folder, baseFileName, extentions] = fileparts(movieFullFileName);
folder = pwd; % Make it a subfolder of the folder where this m-file lives.
outputFolder = sprintf('%s/Movie Frames from %s', folder, baseFileName);
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
else
writeToDisk = false;
end
for frame = 1 : numberOfFrames
thisFrame = read(videoObject, frame);
hImage = subplot(2, 2, 1);
image(thisFrame);
caption = sprintf('Frame %4d of %d.', frame, numberOfFrames);
title(caption, 'FontSize', fontSize);
drawnow; %refresh the window.
% Write the image array to the output file
%if writeToDisk
% Construct an output image file name.
outputBaseFileName = sprintf('Frame %4.4d.png', frame);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
frameWithText = getframe(gca);
imwrite(frameWithText.cdata, outputFullFileName, 'png');
end
m = [vidHeight, numberOfFrames, 3]
for i = 1:1:numberOfFrames;
red(i) = reshape(m(:,600,1),1,[]);
green(i) = reshape(m(:,600,1),1,[]);
blue (i) = reshape(m(:,600,1),1,[]);
end
Can anyone explain what the exact problem is?
Is there any other approach that I can adopt?
Thanks a lot :)
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!