how to increase the brightness of an image?
201 views (last 30 days)
Show older comments
how to increase the brightness of an image?
0 Comments
Accepted Answer
KSSV
on 5 Jul 2017
Read the image using imread, to the output add any number, it will increase the brightness. There are other methods to do this, adding number is one of the method.
I = imread('peppers.png') ;
I1 = I+50 ;
figure(1) ; imshow(I) ;
figure(2) ; imshow(I1) ;
0 Comments
More Answers (1)
DGM
on 15 Apr 2022
Edited: DGM
on 5 Apr 2023
KSSV already gave the answer that most people need, but I like to throw (somewhat) generalized reference answers on old questions.
Let's say we have an image:
A = imread('peppers.png');
Simple addition is the basic "brightness" adjustment. So long as data truncation does not occur, global and local contrast are preserved. Scale is class-dependent, so you'll need to pay attention to the input class when selecting the adjustment value.
B = A+25;
montage({A B})
That said, there are many other things that may be done to adjust brightness, but may also influence other color/contrast characteristics. Such behavior may be either beneficial or undesirable, depending on the case. A preface to the most basic brightness/contrast controls can be found in this discussion and the demo I included therein:
Barring rudimentary programmatic approaches (i.e. doing the class handling and math yourself), consider the following image adjustment tools. Some of these tools are part of Image Processing Toolbox (IPT). Other tools are part of MIMT (available on the File Exchange).
This simple tool can adjust brightness/contrast/gamma as one might in an image manipulation environment. Default brightness control is purely additive, but optional GIMP-compatibility mode is not. While the method used by GIMP is not purely additive and will decrease global contrast, it preserves local contrast near extrema by preventing data truncation.
% raise brightness (purely additive like first example)
B = imbcg(A,'b',0.1);
% raise brightness (GIMP method)
C = imbcg(A,'b',0.1,'gimp');
This tool can adjust input levels, output levels, and gamma.
% increase brightness by raising output black point (also reduces global contrast)
B = imadjust(A,[0 1],[0.1 1]);
% increase brightness by lowering input white point (also increases global contrast)
C = imadjust(A,[0 0.9],[0 1]);
% increase brightness by applying gamma < 1
% (also increases contrast in dark regions; reduces contrast in bright regions)
D = imadjust(A,[0 1],[0 1],0.8);
This can do the same things as imadjust(), but it offers some extra functionality. Consider repeating the first imadjust() example:
% raise output black point (I/RGB)
B = imlnc(A,'independent','out',[0.1 1]);
% raise output black point (L in HSL)
C = imlnc(A,'hsl','out',[0.1 1]);
% raise output black point (L in LCHab)
D = imlnc(A,'lchab','out',[0.2 1]);
This is an arbitrary intensity adjustment tool and is probably overkill if all you need is to bump brightness. To put it in perspective, most of the other tools in this list can be seen as different ways of reducing the same process to a small set of control parameters so as to address certain properties. This reduction trades flexibility for simplicity of use.
- MATLAB brighten() offers only 1 parameter to control the intensity transfer function curve
- IPT imcontrast() offers 2 parameters
- MIMT imbcg() offers 3 parameters
- IPT imadjust() & MIMT imadjustFB() offer 5 parameters
- MIMT imlnc() offers 6 parameters
- MIMT imcurves() allows any number of points to specify an arbitrary curve.
% simple brightness increase + minor gamma
in = [0 0.4 0.9];
out = [0.1 0.5 1];
B = imcurves(A,in,out);
This is an interactive GUI tool, and acts as an interface to a handful of MIMT tools, including imlnc() and imtweak(), I'll probably add imbcg() and imcurves() to it eventually.
B = immodify(A);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/965095/image.png)
This is more of a color adjustment tool, but may be of use if color adjustments also need to be made. Using the legacy syntax, the adjustment of brightness components are zero-centered and multiplicative (similar to an 'exposure' control), so global contrast is also increased. The current version of imtweak() allows a 6-term specification including both scaling factors and offsets, so separability of brightness and contrast is improved.
B = imtweak(A,'rgb',[1.1 1.1 1.1]);
C = imtweak(A,'ypbpr',[1.1 1 1]); % choose any one of many color models
C = imtweak(A,'ypbpr',[1 1 1; 0.1 0 0]); % [ky kb kr; osy osb osr]
This replicates the behavior of GIMP's hue/saturation tool (HSL). Similar to imtweak(), this is primarily for color adjustment but might be of use.
B = ghlstool(A,[0 10 0]);
This is an interactive GUI tool, but isn't very capable or convenient:
- can only adjust the input black/white points
- only works on grayscale images
- only works on image data displayed in a figure, not in the workspace
Agray = rgb2gray(A); % can't do RGB
hi = imshow(Agray); % shove it in a figure
imcontrast(gca); % run imcontrast()
% adjust levels, click "Adjust Data", close
Bgray = hi.CData; % extract the CData from the figure
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/965090/image.png)
This is meant strictly to work on colormaps, not images. Though not practically convenient, any RGB image could be reshaped to work with it. Contrary to the name, this is actually just a gamma adjustment tool.
Acmap = reshape(im2double(A),[],3); % integer inputs are not supported!
Bcmap = brighten(Acmap,0.5);
B = reshape(im2uint8(Bcmap),size(A));
Please don't take this as a suggestion. I'm only including this because the webdocs actually link this when looking for image adjustment. It would actually be more efficient and convenient to just do the exponentiation yourself.
There are also other tools on the File Exchange besides MIMT.
Turning back to the rudimentary programmatic approaches, anyone who wants to perform similar adjustments in a more direct manner can always open up the corresponding file (e.g. imbcg.m) and see how it works.
3 Comments
User79
on 5 Apr 2023
Bur these two are the same:
% raise brightness (purely additive like first example)
B = imbcg(A,'b',0.1);
% raise brightness (GIMP method)
C = imbcg(A,'b',0.1);
DGM
on 5 Apr 2023
Edited: DGM
on 5 Apr 2023
Oof. I'm really good at screwing up in incredibly obvious ways sometimes. Fixed it in the answer, but I suppose I could elaborate since I never actually provided outputs in the examples.
A = imread('cameraman.tif'); % test image
bk = 0.4; % brightness parameter
% raise brightness (purely additive like first example)
B = imbcg(A,'b',bk);
% raise brightness (GIMP method)
C = imbcg(A,'b',bk,'gimp');
imshow([B C])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1346884/image.png)
While the typical brightness control is implemented as addition/subtraction, the GIMP implementation is akin to a screen/multiply blend. When raising brightness, it has less influence over bright regions than it does over dark regions. When lowering brightness, it has less influence over dark regions than it does over bright regions.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!