0
votes

I have a program that requires grayscale format videos.

The correct video format that I require looks like this when imported with VideoReader

enter image description here

I have received a video file that imports with VideoReader as follows:

enter image description here

So I want to change the VideoFromat to Grayscale. I found this code and ran it:

http://www.mathworks.com/matlabcentral/answers/102367-how-do-i-convert-my-video-2-gb-to-uncompressed-avi-grayscale-in-matlab-7-12-r2011a

and while it does output a Grayscale video, the quality has been severely reduced (a lot of the detail is 'blurred' together and there looks like a lot of artifacts in the video). A part of the same frame shows what I mean:

enter image description here

I have also loaded the original video file into ImageJ as Grayscale and saved it as "Uncompressed AVI", and the same kind of thing happens.

So my question is

(a) why is this occurring?

(b) what would be the best way to perform the conversion I am after?

Thanks

2
Why are your two movies different resolutions (pixel dimensions), different frame rates, and different numbers of frames? What codec is the original AVI? It's hard to answer this without the actual code use and a short sample file. The brightness change could be due to a difference in gamma values. - horchler
Hi, thanks for your comment. The resolution and number of frame differences are fine. I should have been clear that the important bits of the desired format (first screenshot), are the BitsPerPixel and VideoFormat fields. I will upload a short sample, thanks. I am not sure about the gamma value change, but the converted video definitely looks vastly reduced in quality. - Steve Hatcher
@SteveHatcher it's quality is reduced BECUASE the degradation is spatial resolution (1024x1024 ->520x696) and frame rate. - Shai
If you're concerned about quality then if you're changing resolution, frame rate, etc. that will certainly impact quality and result in blurring. - horchler
Hi, thanks for the comments. Sorry I must not be clear in my original description. The new video I have received comes as 520x696 (in this case), and I converted it to a Grayscale using the mathworks link provided, which keeps the same resolution. Again the first pic was just to highlight the VideoFormat and BitsPerPixel fields. - Steve Hatcher

2 Answers

2
votes

The issue here is that your image has a depth of 24 bits but you convert it to an 8 bit grey-scale using the solution you linked. I presume ImageJ does the same thing by default.

I think you can fix this by replacing 255 with (2^24)-1 in the line

map = [(0:255)' (0:255)' (0:255)']/255;

and uint8 to uint32 on the next line.

2
votes

The image degradation in your image does not look like it was caused by conversion to grayscale... It looks more like compression or sub-sampling artifacts. VideoWriter uses compressed Motion JPEG format by default. Are you sure you are using 'Uncompressed Avi'?

Also, one of the options for PROFILE parameters of VideoWriter is Grayscale AVI. Try using that. You may not even have to call rgb2gray.