Import color video as grayscale?
6 views (last 30 days)
Show older comments
Hi,
I am using the image processing toolbox and wonder if there is a smarter way to import color video as grayscale rather than looping over the color frames with the RGB2GRAY function (see below).
colorVidFrames = read(videoObj, [startFrame endFrame]);
for f = startFrame:endFrame
J = rgb2gray(colorVidFrames(:,:,:,f)); % CONVERT COLOR TO GRAY
gFrames(:,f) = J(:); % GRAY FRAMES
end
clear colorVidFrames
While the RGB2GRAY loop method does provide the desired end result, it is quite computationally expensive for my application. I understand that the computational rigor could be alleviated via parallel computing, but I'm really looking to avoid the conversion loop altogether if possible.
Thanks, -Jeff
1 Comment
DGM
on 19 Jul 2024
Edited: DGM
on 19 Jul 2024
It's likely that the video file is somehow luma-chroma encoded. That is, the workflow is YCbCr -> RGB -> Y, when all conversions could possibly be avoided by just extracting Y directly.
That's an assumption in itself, but it reveals the compromise we're making. We can choose to use high-level tools to read the file as converted RGB data, but those conveniences don't give us direct access to the file contents in their native format.
Even 12 years layer, I don't know of a convenient, format-agnostic way to just grab Y while avoiding redundant conversions and allowing the selection of arbitrary frame ranges. To be fair, I'm not remotely familiar in every video format. Note that the 'grayscale' videoformat property is a purely descriptive read-only property. We can't use it to change the output of read().
This isn't at all an answer, but perhaps someone with a simply-formatted file could put together some low-cost code to extract luma content. The question is whether it's worth the time and effort to spare the CPU time for what is likely a single project.
Answers (0)
See Also
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!