Why some of my colored videos load as gray-scale in MATLAB

Hi, I downloaded a bunch of videos from youtube. I then load them to matlab to extract/process 10 randomly selected clips. Most of my videos load perfectly fine, however, a lot of them load as a weird gray-scale version of the video. I load the videos using:
vidObj = VideoReader(filename);
duration = vidObj.Duration ;
clips_indx = duration * rand(10,1);
for i = 1 : 10
vidObj.CurrentTime = clips_indx(i);
im = readFrame(vidObj);
end
This is how the clips look like, tilted and gray!
While the video looks normal like:
I would appreciate any input.
Thanks a lot.

Réponses (2)

Walter Roberson
Walter Roberson le 16 Mai 2016
1) It is possible for videos to be pseudocolor; in such a case when you retrieve the frame, the map field will be non-empty and the data field will be 2D.
2) With a shear like that, it is plausible that the video is in YCrCb 4:2:2 or 4:2:0 and needs to be converted to RGB.

7 commentaires

Thanks a lot for your answer Walter. I am not sure about if the videos are pseudocolored. If so, how to approach this? As for the shear, I tried to use
ycbcr2rgb(im)
but it still doesn't fix the problem. Appreciate your help, but do you have any more suggestions?
Please save one of the frames to a .mat file and attach it.
But in the meantime, try configuring http://www.mathworks.com/help/vision/ref/vision.videofilereader-class.html#bse_tfx-3 ImageColorSpace for VideoReader
Mona
Mona le 19 Mai 2016
Modifié(e) : Mona le 20 Mai 2016
Thanks a lot for trying to help me out. Attached is a frame of the video.
Also, I tried to use the vision video reader. So I used:
%
vidObj = vision.VideoFileReader(filename);
im=step(vidObj);
imshow(im)
And the image I get is fine, colored and not sheared/tilted. Only if I know how to extract specific frames of the video using step/vision.VideoFileReader
Also, looking at more examples, I now know the video frames don't even load as grayscale. It's another format that I cannot interpret! Take a look at the example below:
Thanks again
Could you show us the output of aviinfo applied to the file?
It's not an avi file, so I used:
vidObj = VideoReader(filename);
vidObj.VideoFormat
The returned format is RGB24
Thanks a lot again. You've been so helpful.

Connectez-vous pour commenter.

Mona
Mona le 6 Juin 2016
Modifié(e) : Mona le 6 Juin 2016
Hi, I wasn't able to resolve this problem. However, I just had to find a way to go around it. So my very inefficient way is to : - Read the file using vision.VideoFileReader
vidObj = vision.VideoFileReader(filename);
Then convert the video using vision.VideoFileWriter to a .avi file
videoFWriter = vision.VideoFileWriter([filename,'.avi'],'FrameRate',videoFReader.info.VideoFrameRate);
while ~isDone(videoFReader)
videoFrame = step(videoFReader);
step(videoFWriter, videoFrame);
end
release(videoFReader);
release(videoFWriter);
The .avi file now can be perfectly read in the correct format by VideoReader, and I cant choose which frames to process.

Produits

Question posée :

le 16 Mai 2016

Modifié(e) :

le 6 Juin 2016

Community Treasure Hunt

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

Start Hunting!

Translated by