2015-02-07 45 views
0

我有以下代码来读取CIF序列中的Y组件,这是抛出此错误。错误在函数重塑()在matlab

使用重整的错误 要重新设置元素的数量不得更改。

foremanOne中的错误(第12行) img_y = reshape(img_y,nColumn,nRow);

代码

  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'); 

什么可能出现了问题?

回答

0

在你的循环,你不使用i所以看起来你fread打开阵列img_y是尺寸[288, 352, 10]而当你重塑你只提供图像的高度和宽度。 因此,我认为你只需要与循环指数指数img_y(我改变从我到k ...我不是一个好主意,因为它的虚数单位),像这样:

  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'); 

我做了一些其他更改以及使代码更有效一些。

希望有帮助!

+0

感谢您的接受!我只注意到'ImY'被重新塑造成尺寸为[nColumn,nRow]。由于在MATLAB中,行在索引过程中首先出现,所以您可能需要交换它们。 – 2015-02-07 05:26:21

+0

我试图执行代码,但错误仍然是相同的! – Prashanth 2015-02-08 06:06:30

+0

使用重整的错误 重新设置元素的数量不得更改。 foremanOne中的错误(第31行) ImY = reshape(img_y(:,:,k),nColumn,nRow); – Prashanth 2015-02-08 06:06:52