how to read and write a gray AVI video file in 16 bit

18 ビュー (過去 30 日間)
Boissonneau
Boissonneau 2024 年 1 月 24 日
回答済み: Boissonneau 2024 年 1 月 24 日
I want save a grayscale matrix in a videofile without lost information.
And i want to read this file to compare it.
I try this :
% Create and save
Fmt = 'Grayscale AVI';
% Fmt = 'Uncompressed AVI';
vidObj = VideoWriter('video16.avi',Fmt);
open(vidObj);
for i = 1:100
gray_img = rand(480, 640) * 2^16;
writeVideo(vidObj, double(gray_img./2^16));
end
close(vidObj);
figure;imagesc(gray_img);colormap gray;impixelinfo;
disp( mean2(gray_img) );
% Read and show
vidObj = VideoReader('video16.avi');
for k = 1 : vidObj.NumFrames
frame = read(vidObj, k);
imshow(frame);
end
figure;imagesc(frame);colormap gray;impixelinfo;
disp( mean2(frame) );
but my read frames are always in 8 bit format
Any help should be appreciate
Thanks

回答 (2 件)

ScottB
ScottB 2024 年 1 月 24 日
The command VideoWriter has an attribute called "VideoBitsPerPixel" which is the number of bits per pixel in each output frame.

Boissonneau
Boissonneau 2024 年 1 月 24 日
Thanks, for this answer but :
for the both format i have a error message
"Unable to set the 'VideoBitsPerPixel' property of class 'VideoWriter' because it is read-only."
Fmt = 'Grayscale AVI';
% Fmt = 'Uncompressed AVI';
vidObj = VideoWriter('video16.avi',Fmt);
vidObj.VideoBitsPerPixel = 16;
Unable to set the 'VideoBitsPerPixel' property of class ''VideoWriter'' because it is read-only.
thank but i can't use this solution...

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by