The reshape function used in the code below

조회 수: 9 (최근 30일)
Rohit S
Rohit S 2015년 2월 9일
댓글: Star Strider 2015년 2월 9일
file = 'foreman.cif';
nFrame = 10;
[fid,message]= fopen(file,'rb');
nRow = 288;
nColumn = 352;
img_y = uint8(fread(fid, nRow * nColumn, 'uchar'));
for k = 1:nFrame
ImY = reshape(img_y(:,:,k), nRow, nColumn);
ImY = ImY';
imshow(ImY);
pause(0.5)
end
fclose(fid);
disp('OK');
Error is
Error using reshape
To RESHAPE the number of elements must not change.
Error in cifTry (line 31)
img_y = reshape(img_y, nColumn, nRow);

답변 (2개)

Star Strider
Star Strider 2015년 2월 9일
Try:
ImY = reshape(squeeze(img_y(:,:,k)), nRow, nColumn);
or:
ImY = reshape(img_y(:,:,k), nRow, nColumn, []);
depending on what you want to do. No promises, since I can’t run your code.
  댓글 수: 2
Rohit S
Rohit S 2015년 2월 9일
Your first solution :
ImY = reshape(squeeze(img_y(:,:,k)), nRow, nColumn);
Resulted in the same error as above
Error using reshape
To RESHAPE the number of elements must not change.
Error in foremanOne (line 12)
ImY = reshape(squeeze(img_y(:,:,k)), nRow, nColumn);
The second solution
also throwed error
Error using '
Transpose on ND array is not defined.
Error in foremanOne (line 13)
ImY = ImY';
Am trying to extract the Y component..Is there any other solution??
Star Strider
Star Strider 2015년 2월 9일
I don’t have a .cif image to experiment with, and I do not have yours, so I can only suggest untested possibilities.
I would follow Roger’s suggestion, and be certain that ‘nRow’ and ‘nColumn’ are actually the dimensions of your array. The mismatch between them and the dimensions of your data would certainly throw the error you are seeing.

댓글을 달려면 로그인하십시오.


Roger Stafford
Roger Stafford 2015년 2월 9일
I would advise you to place the line
display(size(img_y))
immediately after the line
img_y = uint8(fread(fid, nRow * nColumn, 'uchar'));
to see if it has the size of dimensions you apparently expect it to have. Your error message suggests that it does not, and if so, you should make the appropriate changes in your code.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by