Assignment has more non-singleton rhs dimensions than non-singleton subscripts
4 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Matt Fig
on 23 Oct 2012
Edited: Matt Fig
on 23 Oct 2012
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 Comments
Walter Roberson
on 23 Oct 2012
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 Comments
See Also
Categories
Find more on C4ISR in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!