Matrix multiplication within a function not working
显示 更早的评论
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 个评论
Image Analyst
2021-9-19
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
2021-9-19
Image Analyst
2021-9-19
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
2021-9-19
回答(2 个)
Sulaymon Eshkabilov
2021-9-19
There is an err, here is how it is to be:
lutlum = HL.'*lutlum; % creates 2 - by - 256
Sulaymon Eshkabilov
2021-9-19
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
类别
在 帮助中心 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!