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

4 次查看(过去 30 天)
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:

采纳的回答

Stuart Smith
Stuart Smith 2022-2-4
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

更多回答(1 个)

Benjamin Thompson
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 个评论
Stuart Smith
Stuart Smith 2022-2-2
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.

请先登录,再进行评论。

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by