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

2 ビュー (過去 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
Benjamin Thompson 2022 年 2 月 1 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by