# Gray Level Image Processing

## Contrast

Modify the contrast of an image is to multiply each pixel value by a factor. if P(l,c) is the image then:

$Pcontrast\left(l,c\right)=p\left(l,c\right)*f$

where f is the contrast factor applied ($f<0$ ).

## Brightness

Modify the brightness of an image is to sum each pixel's value by a factor. if P(l,c) is the image then:

$Pbrillance\left(l,c\right)=p\left(l,c\right)+f$

where f is the brightness factor applied.

## Gamma Correction

This correction applies a non linear transformation on each pixel. The gamma factor define the non linear curve which be apply. we have:

On this graph, we have normelized pixels value between 0 and 1. To apply those curves, the image must be normalized before. Then after the gamma correction done the results must be denormalized. We use the next equation:

$Pgamma\left(l,c\right)={\left(\genfrac{}{}{0.1ex}{}{p\left(l,c\right)}{\mathrm{pmax}}\right)}^{\gamma }×\mathrm{pmax}$

We can inverse the gamma correction by inverting the gamma factor. $\gamma \text{'}=1/\gamma$

## Automatic Correction of Contrast

The goal of this correction is to use the entire range of possible value. The smallest value is bring to 0 and the biggest to 255 (for 8 bits images). we use:

$Pautocorr\left(l,c\right)=\left(p\left(l,c\right)-Pbas\right)×\genfrac{}{}{0.1ex}{}{255}{Phaut-Pbas}$

Where Pbas is the smallest balue and Phaut the biggest.

## Program

```function guicontbrill clear all; close all; figure(  'Name','translation',...             'NumberTitle','off',...             'color',[0.3137 0.3137 0.5098]);         a(1)=axes('units','normalized',...     'position',[0.05 0.4 0.4 0.4]); a(2)=axes('units','normalized',...     'position',[0.5 0.4 0.4 0.4]); uicontrol(  'style','pushbutton',...             'string','load',...             'Position', [10 10 50 20],...             'callback',@loadimage); uicontrol(  'style','popup',...             'string','contrast|auto contrast|brillance|gamma',...             'Min',0,'Max',4,...             'Position', [70 10 100 20],...             'callback',{@choix,'type'});         uicontrol(  'style','edit',...             'string','1',...             'Position', [180 10 100 20],...             'callback',{@facteuredit,'facteur'}); uicontrol(  'style','pushbutton',...             'string','executer',...             'Position', [290 10 100 20],...             'callback',@executer); text(1)=uicontrol(  'style','text',...             'string','type correction ',...             'Position', [70 30 100 20]); text(2)=uicontrol(  'style','text',...             'string','facteur ',...             'Position', [180 30 100 20]); %parametre initial setappdata(gcf,'x',1); setappdata(gcf,'type',0); setappdata(gcf,'facteur',1);       function loadimage(~,~)     % appeler quand appui check box     [filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...           '*.*','All Files' },'mytitle',...           'C:\Work\myfile.jpg')     x = imread(filename);     if (length(size(x))>2)         x=x(:,:,1);% on prend une seul plan image noir et blanc chaque plan sont egaux     end     k = whos('x');     if k.class == 'uint8'         k=8;     end     setappdata(1,'k',k);     setappdata(1,'x',x);     axes(a(1))     imshow(x)     axes(a(2))     imshow(x)     end function executer(hObj,~,Name)      type = getappdata(1,'type');      img = getappdata(1,'x');      facteur = getappdata(1,'facteur');            [ligne colonne]=size(img);      img = double(img);      img2=zeros(ligne,colonne);      if type==0 || type==1          img2=img.*facteur;      elseif type==2          amin = min(min(img));          amax = max(max(img));          facteur = 0 + (img - amin).*((255 - 0 )/(amax - amin));          img2=facteur;      elseif type==3          img2=img+facteur;      else          amax = max(max(img));          img2 = ((img./amax).^facteur).*amax;      end                axes(a(2))      imshow(uint8(img2))       end function choix(hObj,~,Name)     % Called when user activates popup menu     val = get(hObj,'Value'); %0|1=ligne, 2=colonne, 3=croix, 4=carre     setappdata(1,Name,val); end function facteuredit(hObj,~,Name)     % Called when user activates popup menu     val = str2num(get(hObj,'String')); %0|1=ligne, 2=colonne, 3=croix, 4=carre     setappdata(1,Name,val); end end```