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에서 Get Started with Computer Vision Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!