Code covered by the BSD License  

Highlights from
CONTRAST CONTROLLER

image thumbnail
from CONTRAST CONTROLLER by Divakar Roy
Contrast Adjustment of Images

contrast_controller(input_img_filename,low_limit,high_limit,output_img_filename)
function contrast_controller(input_img_filename,low_limit,high_limit,output_img_filename)

%CONTRAST_CONTROLLER : Changes the contrast of an image by the low and high
%values.
%
% Example: contrast_controller('pic.jpg',0.008, 0.992,'pic2.jpg');
%
% NOTE:
% (1)'low_limit' and 'high_limit' are the limiters.
% (2)'low_limit'<'high_limit' and both have values ranging between 0 and 1,except 0.

%--------------------------------------------------------------------------
img=imread(input_img_filename);
[m1 n1 r1]=size(img);
img2=double(img);
%--------------------calculation of vmin and vmax--------------------------
for(k=1:r1)
arr=sort(reshape(img2(:,:,k),m1*n1,1));
vmin(k)=arr(ceil(low_limit*m1*n1));
vmax(k)=arr(ceil(high_limit*m1*n1));
end
%--------------------------------------------------------------------------
if(r1==3)
    v_min=rgb2ntsc(vmin);
    v_max=rgb2ntsc(vmax);
end
if(r1==1)
    v_min=vmin;
    v_max=vmax;
end   
%--------------------------------------------------------------------------
for(i=1:m1)
     for(j=1:n1)
         for(k=1:r1)
                img2(i,j,k)=255*(img2(i,j,k)-v_min(1))/(v_max(1)-v_min(1));
         end
     end
end
imwrite(uint8(img2),output_img_filename);
%--------------------------------------------------------------------------

Contact us at files@mathworks.com