Putri Ranati
Putri Ranati

Reputation: 47

Auto-brightening images

I found this code for auto-brightening images to an optimum level.

% AUTOBRIGHTNESS  
%        -->Automatically adjusts brightness of images to optimum level.
%    e.g. autobrightness('Sunset.jpg','Output.jpg')

function autobrightness(input_img,output_img)
my_limit = 0.5;
input_image=imread(input_img);
if size(input_image,3)==3 
    a=rgb2ntsc(input_image);
else     
    a=double(input_image)./255;
end
mean_adjustment = my_limit-mean(mean(a(:,:,1)));
a(:,:,1) = a(:,:,1) + mean_adjustment*(1-a(:,:,1));
if size(input_image,3)==3    
    a=ntsc2rgb(a);
end
imwrite(uint8(a.*255),output_img);
  1. I want to ask, why the value of my_limit is 0.5?
  2. How we determine that value?
  3. Why use the 'ntsc' colorspace instead of another colorspace like hsv, lab or yCbCr?

Upvotes: 0

Views: 89

Answers (1)

Nirvedh Meshram
Nirvedh Meshram

Reputation: 469

I want to ask, why the value of my_limit is 0.5? How we determine that value?

The color space NTSC ranges from 0 to 1 for each of its channel. So essentially 0.5 is the center. This is equivalent of choosing 127 for RGB space

Why use the 'ntsc' colorspace instead of another colorspace like hsv, lab or yCbCr?

I believe ntsc provides 100% coverage of the color space and so the author of the code choose it. However most modern systems wont display in this color space and hence we use standard RGB for display. I used this website to come to this conclusion NTSC color space

Also, as pointed by Cris in this wikipedia page. NTSC stores Luminance and Chrominance and the author of the code is adjusting the Lumiance(brightness). I am including a modified script I used to come to these conclusions

input_img='lena_std.tif'
output_img='lena2.tif'
my_limit = 0.5;
input_image=imread(input_img);
if size(input_image,3)==3 
    a=rgb2ntsc(input_image);
    k=rgb2ntsc(input_image);
else     
    a=double(input_image)./255;
end
mean_adjustment = my_limit-mean(mean(a(:,:,1)));
a(:,:,1) = a(:,:,1) + mean_adjustment*(1-a(:,:,1));
if size(input_image,3)==3    
    a=ntsc2rgb(a);
end
imwrite(uint8(a.*255),output_img);
output=uint8(a.*255);
imwrite(uint8(k.*255),'test.tif');
ntscoutput=uint8(k.*255);

Upvotes: 1

Related Questions