Assignment has more non-singleton rhs dimensions than non-singleton subscripts
4 次查看(过去 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 !!!
0 个评论
回答(2 个)
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...)
0 个评论
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(:));
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!