我正在尝试从intel realsense相机发送一个帧到matlab。 d通过imshow(...)或图像(...)显示图像没有成功,因为图像是rgba图像... 我已将图像作为对象从C#发送:
matlab.Feval("getImage", 1, out result, bitmap_data);
是否有可以显示框架的功能?
答案 0 :(得分: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.使用alpha channel
%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
数组进行处理。可能有一种更有效的方式来编写这段代码,但我希望尽可能清晰易懂,希望这有帮助