14 bit grayscale movie/image acquisition

I have a camera which has 8-14 bit-depth. I want to get a grayscale movie and then convert the movie to 14-bit grayscale images. I want to use image acquisition toolbox of MATLAB to acquire the movie and then convert the movie to 14-bit images. My questions are: 1) Do I need to set any parameter in the camera to get 14-bit movie (and subsequently images) or 14 bit parameter should be set when I want to convert the movie to images?
2)How can I convert a movie to 14-bit images in MATLAB?

Answers (2)

Look at the parameters in imaqtool. Do you see anything there about selecting 14 bit mode?

15 Comments

Your hint was very useful. Thanks
In the Logging section of imaqtool GUI, if profile is set to Motion JPEG 2000, and MJ2 Bit Depth is set to 16 bit, it is possible to save 16 bit *.mj2 file. Now my questions are:
(1) I can read the *.mj2 file by the following commands but I do not know how to display it.
xyloObj = VideoReader('16Bit_2.mj2');
vidFrames = read(xyloObj);
(2) Although I set Returned Color Space as gray scale, I vidFrames is X*Y*3 uint16
(3) I do not know how to convert the movie frames to individual images
read() can give you one color frame from the video. Just specify what frame number you want. Then use imshow() to display it. Or read the whole gigantic video like you did, if you have enough memory
oneFrame = vidFrames(:,:,:, 1); % Extract frame #1.
imshow(oneFrame);
Ronaldo
Ronaldo on 4 Oct 2013
Edited: Walter Roberson on 7 Aug 2017
Only one problem remains.
I set Returned Color Space in general tab of imaqtool GUI as gray scale but vidFrames is X*Y*3 uint16. How can I acquire 16-bit grayscale images?
That might be determined by the Video Mode rather than the Returned color space. Call them and ask them. I haven't played around with trying to capture and save live video as gray scale so I can't say for sure. What video modes show up as options to select?
It has the following 3 options:
rgb, grayscale, YCbCr.
I appreciate it if you mention where I should call.
Since I am not an expert in image processing, Do you think whether it is acceptable if I do the following:
a=vidFrames(:,:, 1);
b=vidFrames(:,:, 2);
c=vidFrames(:,:, 3);
imshow((a+b+c)./3)
And did you pick the grayscale option?
The algorithm MATLAB used for rgb2gray is:
rgb2gray converts RGB values to grayscale values by forming a weighted sum of the R, G, and B components:
0.2989 * R + 0.5870 * G + 0.1140 * B
I was wondering if you mention whether this applicable to 16 bit image? Also what do you mean by mentioning "did you pick the grayscale option?"
Let me see your line that says something like:
vidobj = videoinput('winvideo', 1, 'grayscale');
What does your videoinput line look like?
vid = videoinput('winvideo', 1, 'MJPG_1024x768');
src = getselectedsource(vid);
vid.FramesPerTrigger = 1;
preview(vid);
start(vid);
stoppreview(vid);
l1 = getdata(vid);
save('C:\Users\Ronaldo\Desktop\Imanbin.mat', 'l1');
clear l1;
vid.LoggingMode = 'disk';
vid.LoggingMode = 'disk&memory';
vid.LoggingMode = 'disk';
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\ggsa.avi', 'Uncompressed AVI');
vid.DiskLogger = diskLogger;
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\ggsa.mj2', 'Motion JPEG 2000');
vid.DiskLogger = diskLogger;
diskLogger.MJ2BitDepth = 16;
preview(vid);
start(vid);
stoppreview(vid);
vid.FramesPerTrigger = Inf;
vid.ReturnedColorspace = 'grayscale';
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_0001.mj2', 'Motion JPEG 2000');
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
diskLogger.LosslessCompression = true;
preview(vid);
start(vid);
stoppreview(vid);
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_0002.mj2', 'Motion JPEG 2000');
diskLogger.LosslessCompression = 1;
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
stop(vid);
vid.FramesPerTrigger = 1;
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_1.mj2', 'Motion JPEG 2000');
diskLogger.LosslessCompression = 1;
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
preview(vid);
start(vid);
stoppreview(vid);
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_2.mj2', 'Motion JPEG 2000');
diskLogger.LosslessCompression = 1;
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
preview(vid);
start(vid);
stoppreview(vid);
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_3.mj2', 'Motion JPEG 2000');
diskLogger.LosslessCompression = 1;
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
vid.FramesPerTrigger = Inf;
preview(vid);
start(vid);
stoppreview(vid);
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_4.mj2', 'Motion JPEG 2000');
diskLogger.LosslessCompression = 1;
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
stop(vid);
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_5.mj2', 'Motion JPEG 2000');
diskLogger.LosslessCompression = 1;
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
preview(vid);
start(vid);
stoppreview(vid);
diskLogger = VideoWriter('C:\Users\Ronaldo\Desktop\Image acquisiton\16Bit_6.mj2', 'Motion JPEG 2000');
diskLogger.LosslessCompression = 1;
diskLogger.MJ2BitDepth = 16;
vid.DiskLogger = diskLogger;
stop(vid);
The line
vid = videoinput('winvideo', 1, 'MJPG_1024x768');
does not say grayscale. What shows up in the imagqtool command window when you connect a video to the gray scale adapter? That's the line you want to copy to your program.
Unfortunately my device does not support grayscale and I get the following error:
Error using videoinput (line 319)
The FORMAT specified is not supported by this device. IMAQHWINFO(ADAPTORNAME).
obj = videoinput('winvideo', 1);
obj_info = imaqhwinfo(obj)
obj_info =
AdaptorName: 'winvideo'
DeviceName: 'Integrated Webcam'
MaxHeight: 768
MaxWidth: 1024
NativeDataType: 'uint8'
TotalSources: 1
VendorDriverDescription: 'Windows WDM Compatible Driver'
VendorDriverVersion: 'DirectX 9.0'
Do you think that it is correct if I use the following conversion method to convert the acquired images to 16 bit grayscale image.
0.2989 * R + 0.5870 * G + 0.1140 * B
By the way, I sincerely appreciate all your help.
I'm confused. I thought you said these modes were listed: "rgb, grayscale, YCbCr." Is that not correct?
Ronaldo
Ronaldo on 4 Oct 2013
Edited: Ronaldo on 4 Oct 2013
Attached please find a snapshot of my screen. Sorry, if I made you confused.
I did a bad mistake rgb2gray is working for 16 bit images as well.
This is what it says about that:
Setting the Color Space
Use Color Space on the General tabto set the color space for the selected device format. The ReturnedColor Space field has three options: rgb, YCbCr,and grayscale. The setting that is your deviceformat's default color space is shown as the default. You can usethe arrow to select another setting.
Additionally, if the default color space is grayscale,a value of bayer will be available in the ReturnedColor Space field for some devices, and the BayerSensor Alignment field will also be displayed. Use thedrop-down list to select one of the four possible sensor alignments.This feature allows the tool to demosaic Bayer patterns returned bythe hardware and interpolate them into standard RGB color images.For more information about this feature, see the BayerSensorAlignment propertyreference page.
So it appears that if you say grayscale it should be grayscale. If it's not then you'll have to call them. I don't have a camera on this computer so I can't try anything to help you.

Sign in to comment.

Asked:

on 3 Oct 2013

Edited:

on 7 Aug 2017

Community Treasure Hunt

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

Start Hunting!