Adjust brightness and contrast

25 visualizzazioni (ultimi 30 giorni)
jchris14
jchris14 il 30 Lug 2014
Hello,
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.
thanks

Risposta accettata

Ben11
Ben11 il 30 Lug 2014
Modificato: Ben11 il 30 Lug 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!
  2 Commenti
jchris14
jchris14 il 30 Lug 2014
are the low,high in,out commands just asking for the intensity but normalized to a value between 0 and 1?
the problem here is that, the code must accept an image regardless of the brightness or contrast. So, I don't know what the low_in and high_in values are for this incoming image. so would I just leave that as an empty bracket []? or am I understanding this all wrong?
thanks for the help
Ben11
Ben11 il 30 Lug 2014
In general you will use [] for the low_out/high_out parameters (based on my very modest experience but of course you can play around to see how it changes the output image), since you want the output image pixels to span the entire range of possible values, i.e. from "relative" 0 to 1, so normalized as you mentioned. By default Matlab makes the higher and lower 1% of the pixels saturated if you simply call imadjust(Image).
As for the low_in/high_in, this is what you want to play with since the pixel distribution in the output image is calculated from the range defined by low_in and high_in. If you need to automatically select a range, you could obtain the pixel histogram distribution (e.g. imhist) and write some code to select the appropriate range based on the distribution. One important thing being that all your input images must be of the same class (eg. uint8,uint16,etc.).
I hope my explanations were clearer than they are in my head :)

Accedi per commentare.

Più risposte (2)

Image Analyst
Image Analyst il 30 Lug 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
imshow(grayImage, []);
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.
  3 Commenti
Image Analyst
Image Analyst il 30 Lug 2014
Of course not. If you have A and B, you just do
B = A;
If A is a completely different image and you want to match their histograms, you use can do
C = imhistmatch(B, A);
aswathy pavithran
aswathy pavithran il 29 Ott 2019
thank you sir

Accedi per commentare.


Rodrigo Souza
Rodrigo Souza il 28 Gen 2019
Hi all,
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by