Matlab and Aptina ApBaseCOM Integration

2 Ansichten (letzte 30 Tage)
Matías
Matías am 1 Jun. 2014
Beantwortet: Matías am 5 Jun. 2014
Hello,
I have a Micron Camera and I tried to take some images from it and processing them. I am using the ApBase interface from Aptina Software but, when I try to get the image, I received a raw matrix and rgb and I cannot draw the image again.
I based on the guide https://aptina.atlassian.net/wiki/display/DEVS/ApBase+COM+Development+Guide I executed:
apbase = actxserver('apbaseCom.ApBase');
camera = apbase.Create(0);
camera.LoadIniPreset('', '');
raw = camera.GrabFrame;
rgb = camera.ColorPipe(raw);
i = reshape(rgb,2592,1944);
I attached a capture about the workspace. I do not know how interpret the values of the matrix i and when I use imshow(i) on it I am not getting the image.
The guide said that the output is normally 32 bits per pixel with B – G – R – X byte order. What is mean the "X"?
Regards, Matías.

Akzeptierte Antwort

Image Analyst
Image Analyst am 2 Jun. 2014
It's a 32 bit (4 byte) image with the red, green, and blue values packed into the lower 3 bytes and the 4th byte unused and probably zero. You're going to have to mask and shift the value to extract the individual color channels. To mask, use the & operator to "AND" the array with 000000ff, 0000ff00, and 00ff0000. Then divide the upper byte images by 256 and 65536 to bring then down into the 0-255 range of uint8. But they may still be int32 or double at that point so you need to explicitly cast them to uint8 with the uint8() function.
  3 Kommentare
Image Analyst
Image Analyst am 2 Jun. 2014
Try this:
% Pack 200 in the lowest byte, 175 in the next lowest byte,
% 150 in byte 3, and the highest byte will be all zeros
int32Bit = uint32(150 * 2^16 + 175 * 2^8 + 200)
inBinary = dec2bin(int32Bit) % Just to show you the binary version
% Now recover the numbers from the bytes
redValue = bitand(int32Bit, 2^8-1)
greenValue = bitand(int32Bit, 2^16-1) / 2^8 - 1
blueValue = bitand(int32Bit, 2^32-1) / 2^16 - 1
Matías
Matías am 4 Jun. 2014
I do not understand you at all the part "int32Bit = uint32(150 * 2^16 + 175 * 2^8 + 200)" I mean where is my rgb matrix in the code?.
I found something else (because I don't want to bother you with a lot of questions) in the web and I executed:
apbase = actxserver('apbaseCom.ApBase');
camera = apbase.Create(0);
camera.LoadIniPreset('', '');
%camera.SetImageFormat(40,40,'');
raw = camera.GrabFrame;
rgb = camera.ColorPipe(raw);
i = reshape(rgb,2592,1944);
imgR = uint8((255/31)*bitshift(bitand(i,63488),-11));
imgG = uint8((255/63)*bitshift(bitand(i,2016),-5));
imgB = uint8((255/31)*bitand(i,31));
imgRGB = cat(3,imgR,imgG,imgB);
imshow(imgRGB)
And the output was the next image:
  1. Why I got those colors? I want to get the real image with real colors.
  2. Why used (255/31),(255/63),(255/31) on the uint8?
I don't know if I can share the link where I saw the example, so I didn't included it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matías
Matías am 5 Jun. 2014
I could do it.
apbase = actxserver('apbaseCom.ApBase');
camera = apbase.Create(0);
camera.LoadIniPreset('', '');
%camera.SetImageFormat(40,40,'');
raw = camera.GrabFrame;
rgb = camera.ColorPipe(raw);
i = reshape(rgb,2592,1944);
imgB = uint8(bitshift(bitand(i,2^32-1),-16));
imgG = uint8(bitshift(bitand(i,65535),-8));
imgR = uint8(bitand(i,255));
imgRGB = cat(3,imgR,imgG,imgB);
imshow(imgRGB)
Here is the result:
I am really thankful.

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by