Adjust brightness and contrast
128 views (last 30 days)
How do I write a command in a script so that as soon as i run it and enter imread('image'), this command will automatically set the brightness and contrast to a predetermined level. The images im mainly focusing on are grayscale images.
Ben11 on 30 Jul 2014
Edited: Ben11 on 30 Jul 2014
You are probably looking for the imadjust command. As you can see in the documentation the basic syntax for imadjust is
OutputImage = imadjust(InputImage,[low_in; high_in],[low_out; high_out])
where low_in,high_in,low_out and high_out are between 0 and 1. Hence you could assign predetermined values to those and run imadjust on your images. There also a gamma parameter which you can add in you call to imadjust. This factor is used to enhance in a non-linear fashion low or high intensity signals. More info here
If you have the Image Processing Toolbox take a look at the Image Viewer App
Hope that helps get you started!
More Answers (2)
Image Analyst on 30 Jul 2014
If the "predetermined level" is just 0 to 255 so that it can display on a video monitor with the maximum possible dynamic range, just do
That will scale the min (whatever that is) to 0 and the max (whatever that happens to be) to 255. If you want specific gray levels other than 0-255, use imadjust() like Ben11 said.
Rodrigo Souza on 28 Jan 2019
I have put together three scripts/functions for calculating (mean and SD), matching or normalizing luminance of colored images (using HSV and CIE Lab color spaces).
They may be specially useful for pupillometry measures of infant research.
The scripts and their descriptions are available at my OSF page: https://osf.io/auzjy/
Hope it helps.