Adjust brightness and contrast
조회 수: 29 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
Hope that helps get you started!
댓글 수: 2
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
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
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);
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!