1

我正在尝试将帧从英特尔实感相机发送到 matlab。d通过 imshow(...) 或 image(...) 显示图像没有成功,因为图像是 rgba 图像...我已将图像作为对象从 C# 发送:

matlab.Feval("getImage", 1, out result, bitmap_data);

有没有可以显示框架的功能?

4

1 回答 1

0

您将不得不使用确切的 Feval 实现,但如果您要直接在 matlab 中执行它,则有两种选择

1.简单地忽略alpha通道

%this says show all rows, all cols, for channels 1 through 3 or R,G,B
imshow(rgba_im(:,:,1:3));

2.使用阿尔法通道

%this says show all rows, all cols, for channels 1 through 3 or R,G,B
%also saves the handle to the newly drawn image
hndl = imshow(rgba_im(:,:,1:3));

%isolates alpha channel
alpha = rgba_im(:,:,4);

%displays alpha channel
set(hndl , 'AlphaData', alpha);

编辑

现在我知道您的数据不是标准的 rgba 格式,这里是修复它的代码,注释应该告诉您您需要的一切

[num_rows,num_cols_x4]=size(rgba_matrix);

%we have to transpose the array to get it to unfold properly, which is
%first by columns, then rows
at = rgba_matrix.';

%converts data from [r1 g1 b1 a1 r2 g2 b2 a2 r3 g3 b3 a3....] to 
% red_chan   = [r1 r2 r3...]
% green_chan = [g1 g2 g3...]
% blue_chan  = [b1 b2 b3...]
% alpha_chan = [a1 a2 a3...] 
% it says start at some index and grab every 4th element till the end of the
% matrix
red_chan = at(1:4:end);
grn_chan = at(2:4:end);
blu_chan = at(3:4:end);
alp_chan = at(4:4:end);

% reshape each channel from one long vector into a num_rows x (num_cols_x4/4)
red_chan = reshape(red_chan, num_cols_x4/4, num_rows).';
grn_chan = reshape(grn_chan, num_cols_x4/4, num_rows).';
blu_chan = reshape(blu_chan, num_cols_x4/4, num_rows).';
alp_chan = reshape(alp_chan, num_cols_x4/4, num_rows).';

% we concatenate the channels into a num_rows x (num_cols_x4/4) x 4 matrix
standard_rgba = cat(3,red_chan,grn_chan,blu_chan,alp_chan);

从这一点开始,您可以使用standard_rgba数组进行我建议的处理。可能有一种更有效的方法来编写此代码,但我想让它尽可能清晰易懂,希望这会有所帮助

于 2015-06-16T00:07:09.417 回答