Borrar filtros
Borrar filtros

Import color video as grayscale?

6 visualizaciones (últimos 30 días)
Jeff
Jeff el 9 de Jul. de 2012
Editada: DGM el 19 de Jul. de 2024
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 comentario
DGM
DGM el 19 de Jul. de 2024
Editada: DGM el 19 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by