Matrix multiplication within a function not working
Mostra commenti meno recenti
The following function creates a column vector and an image histogram:
function lutlum = lutlummer(image)
for i = 1:1:265
lutlum(i, 1) = i-1;
end
%multiplying the LUT with the luminescence histogram of the image
%Finding luminance image 'L' (Formula gained from class slides)
L = uint8(sum(bsxfun(@times,double(image),reshape([0.299 0.587 0.114],[1 1 3])),3));
%Finding luminance histogram'HL'
HL = histcounts(L,[0:256])';
lutlum = lutlum*HL;
end
The function is called with an image such that HL is a 1x2 matrix, so multiplying a 265x1 matrix ('lutlum') with a 1x2 matrix should be no problem. however, i still get this message:
Matrix dimensions must agree.
lutlum = lutlum.*HL;
Please do let me know where i am going wrong
thanking yall in advance!! :D
4 Commenti
Image Analyst
il 19 Set 2021
image is a built-in function. Do not use it as the name of an input variable.
What is the size of your image?
Bharath Nagarajan
il 19 Set 2021
Image Analyst
il 19 Set 2021
What is L? Is it the gray scale version of the color image like you'd get from rgb2gray()? If so, why would you multiply the 1-D histogram bin count by a 2-D image?
Bharath Nagarajan
il 19 Set 2021
Risposte (2)
Sulaymon Eshkabilov
il 19 Set 2021
There is an err, here is how it is to be:
lutlum = HL.'*lutlum; % creates 2 - by - 256
1 Commento
Bharath Nagarajan
il 19 Set 2021
Sulaymon Eshkabilov
il 19 Set 2021
There are a couple of errs in the code. Here is the corrected version:
function lutlum = lutlummer(image)
for i = 1:1:256 % Has to be 256 NOT 265. 256 similar to 265 :)
lutlum(i, 1) = i-1;
end
%multiplying the LUT with the luminescence histogram of the image
%Finding luminance image 'L' (Formula gained from class slides)
L = uint8(sum(bsxfun(@times,double(image),reshape([0.299 0.587 0.114],[1 1 3])),3));
%Finding luminance histogram'HL'
HL = histcounts(L,[0:256])'; % Note the size of HL is 256 - by - 1 NOT [1 - by - 2] as you have stated
lutlum = lutlum*HL'; % Transpose is necessary
end
Categorie
Scopri di più su Histograms in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!