How can I avoid artifacts when I use im2frame to convert black-and-white images to frames for a video?

4 visualizzazioni (ultimi 30 giorni)
My function creates a series of 2D black-and-white uint8 images. These display perfectly as individual images, but when I try to make a video with them using im2frame, the lines in the frames are enclosed in salt-and-pepper squares that I assume are some king of artifiact:

Risposta accettata

Stuart Smith
Stuart Smith il 4 Feb 2022
I was able to get clean black-and-white line images with this code:
function y = linedrwg( inpict )
img = rgb2gray( inpict ) ;
binimg = not( imbinarize( edgemap( img ) ) ) ;
binimg = bwmorph( binimg , 'clean' ) ;
[ r , c ] = size( binimg ) ;
y = zeros( r , c , 3 ) ;
y( : , : , 1 : 3 ) = binimg ;
end

Più risposte (1)

Benjamin Thompson
Benjamin Thompson il 1 Feb 2022
If you are using VideoWriter to write out the video file with frames you get from im2frame, use an uncompressed or lossless compression profile. The default 'Motion JPEG AVI' profile and any MPEG-4 profile will have a quality parameter that typically allows for improved compression at the expense of artifacts or blurring of edges.
'Archival'
Motion JPEG 2000 file with lossless compression
'Motion JPEG AVI'
AVI file using Motion JPEG encoding
'Motion JPEG 2000'
Motion JPEG 2000 file
'MPEG-4'
MPEG-4 file with H.264 encoding (systems with Windows 7 or later, or macOS 10.7 and later)
'Uncompressed AVI'
Uncompressed AVI file with RGB24 video
'Indexed AVI'
Uncompressed AVI file with indexed video
'Grayscale AVI'
Uncompressed AVI file with grayscale video
  1 Commento
Stuart Smith
Stuart Smith il 2 Feb 2022
I tried all of the profiles listed above. 'Archival' and 'Motion JPEG 2000' produce the error 'unsupported data type double for the chosen file type.' The other profiles produce video with the same artifiacts as in my original post.
Should the images I'm using to make frames be indexed or truecolor, or doesn't it matter?
Thanks for your help.

Accedi per commentare.

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by