Adjust brightness and contrast

29 visualizaciones (últimos 30 días)
jchris14
jchris14 el 30 de Jul. de 2014
Comentada: aswathy pavithran el 29 de Oct. de 2019
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

Respuesta aceptada

Ben11
Ben11 el 30 de Jul. de 2014
Editada: Ben11 el 30 de Jul. de 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 comentarios
jchris14
jchris14 el 30 de Jul. de 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 el 30 de Jul. de 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 :)

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 30 de Jul. de 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 comentarios
Image Analyst
Image Analyst el 30 de Jul. de 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 el 29 de Oct. de 2019
thank you sir

Iniciar sesión para comentar.


Rodrigo Souza
Rodrigo Souza el 28 de En. de 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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by