Assignment has more non-singleton rhs dimensions than non-singleton subscripts

조회 수: 1 (최근 30일)
My program get an error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" in line 21, which is "S (i, j, k) = Temp;" but I do not know how to fix it. My program is shown below:
function J = EE4206_Assignment3_Q1_StretchContrast (filename, MinGray, MaxGray)
A = filename;
I = imread (A);
I = im2double(I)*255;
[r c k] = size (I);
MinInput = min(min(I));
MaxInput = max(max(I));
S = ones (r, c, 3);
for i = 1 :r
for j = 1 : c
for k = 1 :3
Temp = (MaxGray - MinGray).*(I(i, j, k) - MinInput)./(MaxInput - MinInput) + MinGray;
S (i, j, k) = Temp;
end
end
end
J = image (S);
imshow (J);
Thank you !!!

답변 (2개)

Matt Fig
Matt Fig 2012년 10월 23일
편집: Matt Fig 2012년 10월 23일
Please do not use this awful construct to find the global minimum:
MinInput = min(min(I)); % This is the cause of your problem.
MaxInput = max(max(I));
Use this instead:
MinInput = min(I(:));% Global min no matter how many dims!
MaxInput = max(I(:));
(What you would have had to do is call MIN a third time...)

Walter Roberson
Walter Roberson 2012년 10월 23일
You are assuming that imread() is returning a 3D array (you index it that way), but you are only applying two levels of max() and min() so you are going to be getting vector results for max() and min().
I suggest you recode
MinInput = min(I(:));
MaxInput = max(I(:));

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by