Steve Hatcher
Steve Hatcher

Reputation: 715

Convert RGB to Grayscale while keeping maximum quality

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

Upvotes: 0

Views: 1338

Answers (2)

Dima
Dima

Reputation: 39389

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.

Upvotes: 2

nivag
nivag

Reputation: 573

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.

Upvotes: 2

Related Questions