Adjust brightness and contrast

조회 수: 29 (최근 30일)
jchris14
jchris14 2014년 7월 30일
댓글: aswathy pavithran 2019년 10월 29일
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

채택된 답변

Ben11
Ben11 2014년 7월 30일
편집: Ben11 2014년 7월 30일
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
jchris14
jchris14 2014년 7월 30일
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 2014년 7월 30일
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 :)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2014년 7월 30일
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
Image Analyst
Image Analyst 2014년 7월 30일
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 2019년 10월 29일
thank you sir

댓글을 달려면 로그인하십시오.


Rodrigo Souza
Rodrigo Souza 2019년 1월 28일
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