matlab中函数整形()中的错误
我有以下代码来读取CIF序列中的Y分量,这会引发这个错误 使用整形时出错 要重塑形状,元素的数量不得更改 foremanOne中的错误(第12行) img_y=重塑(img_y,n列,nRow) 代码是matlab中函数整形()中的错误,matlab,video-processing,Matlab,Video Processing,我有以下代码来读取CIF序列中的Y分量,这会引发这个错误 使用整形时出错 要重塑形状,元素的数量不得更改 foremanOne中的错误(第12行) img_y=重塑(img_y,n列,nRow) 代码是 clc; file = 'foreman.cif'; nFrame = 10; [fid,message]= fopen(file,'rb'); nRow = 288;
clc;
file = 'foreman.cif';
nFrame = 10;
[fid,message]= fopen(file,'rb');
nRow = 288;
nColumn = 352;
for i = 1: nFrame
%reading Y component
img_y = fread(fid, nRow * nColumn, 'uchar');
img_y = reshape(img_y, nColumn, nRow);
img_y = img_y';
imshow(uint8(img_y));
end
fclose(fid);
disp('OK');
可能出了什么问题?在你的循环中,你没有使用
i
,所以你用fread
打开的数组看起来像是尺寸[288,352,10]
,而当你重塑时,你只提供了图像的高度和宽度。
因此,我认为您只需要使用循环索引对img_y
进行索引(我从I更改为k…I不是一个好主意,因为它是一个虚单位),如下所示:
我还做了一些其他的修改,使代码更加高效
希望有帮助 谢谢接受!我刚刚注意到,
ImY
被重塑为具有维度[nColumn,nRow]
。因为在MATLAB中,在索引过程中,行是第一位的,所以您可能想要交换它们。我试图执行代码,但错误仍然是一样的!!使用“重塑”来重塑元素数量时出错,不得更改。foremanOne(第31行)中的错误ImY=重塑(img_y(:,:,k),n列,nRow);我们会提供更多的信息,因为这里很难猜测。“文件”的大小是多少?请在调用fopen
后显示调用whos
的输出。ThanksName Size Bytes类属性fid 1x1 8双文件1x1 22字符消息0x0 0字符nFrame 1x1 8双错误使用“ND数组上的转置不正确”定义foremanOne中的错误(第14行)ImY=ImY';
clc;
file = 'foreman.cif';
nFrame = 10;
[fid,message]= fopen(file,'rb');
nRow = 288;
nColumn = 352;
%// Use fread once outside the loop and convert right away everything to uint8.
img_y = uint8(fread(fid, nRow * nColumn, 'uchar'));
for k = 1:nFrame
%// reading Y component. I changed the name to avoid confusion
ImY = reshape(img_y(:,:,k), nColumn, nRow); %// Use index here
ImY = ImY';
imshow(ImY);
pause(0.5) %// You might want to pause to see each image individually
end
fclose(fid);
disp('OK');