MATLAB: Multible Pixel Values Doesn’t Allow Bigger Than 255

image processing

Hey there,
I want to make a project about image processing and i have a problem.I want to multiple pixel images and matlab result is not be bigger than 255.
Here is formula :
Here is my code(k is constant,Yout and yinv is my images)
for index1= 1 : m
for index2 = 1 : n
Ymix(index1,index2) = Yout(index1,index2)*yinv(index1,index2)*k;
end
end

Best Answer

Ymix = zeros(m, n);
dYout = double(Yout);
dyinv = double(yinv);
dk = double(k);
for index1= 1 : m
for index2 = 1 : n
Ymix(index1,index2) = dYout(index1,index2)*dyinv(index1,index2)*dk;
end
end
The results can be greater than 255. You have to then figure out what that means and how you want to display the image.
Because Ymix will be double precision (needed to allow arbitrarily large or small values since your values could be greater than 1 or could be negative), if you were to image(Ymix) or imshow(Ymix) it would notice that the data was double precision and it would assume that the minimum value to display was 0.0 and that the maximum value to display was 1.0, and it would color any negative values the same as it colored 0.0 and it would color all values > 1.0 the same as it colored 1.0. That is how graphics on double precision values is defined.
You can use imagesc(Ymix) or imshow(Ymix, []) . That would tell it to examine Ymix and use the minimum value it found as being the first color and the maximum value it found as being the last color and to scale everything linearly between those. That can be useful, but it is not consistent between matrices: if in one matrix the maximum value was (say) 300 and in another matrix the maximum value happened to be (say) 350, then the value "128" that was originally half intensity would come out as 43% intensity in the first of the two matrices but would come out as 37% intensity in the second matrix. That would make it impossible to compare the two matrices by color.
Basically, doing this kind of pixel manipulation in double precision is only useful for intermediate matrices that will you will then multiply again by something that you are sure will scale them back to the range 0 to 255, at which point you would uint8() on the matrix to get something that can be displayed.