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

4 Ansichten (letzte 30 Tage)
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 !!!

Antworten (2)

Matt Fig
Matt Fig am 23 Okt. 2012
Bearbeitet: Matt Fig am 23 Okt. 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...)

Walter Roberson
Walter Roberson am 23 Okt. 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(:));

Kategorien

Mehr zu C4ISR finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by