MATLAB: How to Change the brightness of an image by using loops and no loops

brightnessimage processing

Hello,
I'm trying to create a function that will brighten an image by using loops and by not using loops. Can someone pleases help me and check if I'm on the right pathway please?
by not using loop:
function [ outimg ] = makebright_L(inimg, brightness)
outimg = brightness+inimg;
if inimg>255
inimg=255;
end
disp(outimg);
end
However, it appears to be wrong cause I get this error message
Using loops:
I'm kind of stuck. I don't know what to do
Can someone please help

Best Answer

You don't need the if statement for reducing the values to be in the range [1, 255]. The pixel type uint8 cannot go higher than 255. So, you are safe there.
As another advice, you can use imshow for displaying the images:
function outimg = makebright_L(inimg, brightness)
outimg = uint8(brightness + inimg);
subplot(1,2,1), imshow(inimg);
subplot(1,2,2), imshow(outimg);
end