Capturing Lossless Images with Image Acquisition Toolbox (getsnasphot)

19 views (last 30 days)
Hello everyone,
This is a follow-up to an earlier question I had asked about capturing lossless images with Matlab. Earlier, I was using USB Webcam Package's snapshot() function to capture, yet it seemed that there was some compression going on possibly because it was not possible to access YUY2 (I am not sure if this is relevant as I want to capture images rather than recording videos). Now I have moved on to use the Image Acquisition Toolbox and the interface generated the following code to capture images:
v = videoinput("winvideo", 1, "YUY2_3840x2160"); % Video device
v.ReturnedColorspace = "RGB";
src = getselectedsource(v);
src.Exposure = 0; % Camera parameters
image1 = getsnapshot(v); % Capturing the image
filename = "snapshot1.bmp"; % I changed the code to save the image as .bmp
imwrite(image1, filename, "bmp"); % Saving the file
Now the code is using the getsnapshot() function instead. Should this apply any additional compression on Matlab's side of things? I know that the camera may do something but I want to ensure that Matlab does not.

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jan 2025 at 12:38

YUY2_3840x2160 is already compressed with a lossy compression compared to rgb. Each 1x2 rgb block is represented by 8 bits of gray, then 8 bits of one kind of color information, then 8 bits of gray, and then 8 bits of a different kind of color information. You need one gray and the two color components to create one rgb pixel, so each pair of pixels shares the color information but has independent brightness.

The lossy compression is not spatial, but rather the loss of independent colour information between pairs of pixels.

The matlab drivers create rgb pixels as best possible from the YUY2 components. The matlab drivers do not compress the resulting image.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!