Reputation: 715
I have a program that requires grayscale format videos.
The correct video format that I require looks like this when imported with VideoReader
I have received a video file that imports with VideoReader as follows:
So I want to change the VideoFromat to Grayscale. I found this code and ran it:
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:
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
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
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