Hi, can you help me to correct this error
[p C]=size(lab) lchan=lab(:,:,1); L=60; Lr = L .* ones(p, C);
??? Error using ==> times Matrix dimensions must agree.
Error in ==> lab at 60 Lr = L .* ones(p, C);
No products are associated with this question.
What are p and C?
L = 60; Lr = L .* ones(3, 5); % No error...(the .* is not necessary)
You have a variable named lab and a function named lab?? This is a very bad idea and may (somehow) be at the root of your problem....
Your RGB image is 3 dimensional, not 2 dimensional. Row, Column, Color-plane. Your lab equivalent of the RB is 3 dimensional as well. When you take the size() of a 3 dimensional array, you need to have either only 1 output or else 3 or more outputs. If you only have two outputs as in
then p will be assigned the number of rows (as expected) but C will be assigned the product of all the remaining dimensions, and so will be columns times number of color planes.
Like Walter said, your problem is (partially) that your C is the number of columns TIMES the number of color channels (which is 3). You should be doing it this way, as you'll notice that I ALWAYS do it in code I post, even when I suspect the image is gray level:
[rows columns numberOfColorChannels] = size(lab);
If you do it this way:
[rows columns] = size(lab);
as you did, then columns will not be the number of columns in the image but will be columns * numberOfColorChannels. Please see this blog entry by Steve Eddins for further discussion: http://blogs.mathworks.com/steve/2011/03/29/even-more-information-about-the-size-function/
But like Matt said, that wouldn't cause an error if L was just some number like 60. So, I suspect that you actually did something like
L = lab(:, :, 1); % Extract the L color channel.
and then L would have the size rows*columns, but your ones() function would return an array rows*columns*numberOfColorChannels. Hence the sizes don't match up. So I don't know why you said L was 60 when it was not, but that's your problem. I speculate that you'd like to construct a constant luminance image. In that case, you set
Lr = 60 * ones(size(L));
and then you invert the transform to get back to RGB.