If your gray-scale level image is in uint8 format, it wont allow values greater than 255. For example,
I = uint8(rand(5)*255);
I(1,1) = I(1,1) + 300;
% value of I(1,1) will be 255, i.e. the max allowed value in uint8.
Pergunta
I need to add intensity values to a grayscale image . However this assumes that I must make a check that my values remain in the range 0...255
How can i ensure that my result values are remain in the range?
How am i supposed to perform the afformentioned operation in matlab??
Solução
If your gray-scale level image is in uint8 format, it wont allow values greater than 255. For example,
I = uint8(rand(5)*255);
I(1,1) = I(1,1) + 300;
% value of I(1,1) will be 255, i.e. the max allowed value in uint8.
Outras dicas
If I understand you correctly, you want to increase the intensity of all the image pixels with the brightest one being 255. You can do this by
J = I .* (255/max(max(J)));
This will "scale" the brightness of your image so that the brightest part in the image will have a value of 255.