l'image de fond

fr       en

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:

P c o n t r a s t ( l , c ) = p ( l , c ) * f

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


contrast

contrast2

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:

P b r i l l a n c e ( l , c ) = p ( l , c ) + f

where f is the brightness factor applied.


brillance

brillance2

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:
brillance
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:

P g a m m a ( l , c ) = ( p ( l , c ) pmax ) γ × pmax

We can inverse the gamma correction by inverting the gamma factor. γ ' = 1 / γ


gamma

gamma2

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:

P a u t o c o r r ( l , c ) = ( p ( l , c ) - P b a s ) × 255 P h a u t - P b a s

Where Pbas is the smallest balue and Phaut the biggest.
autocontrast

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

Copyright © 2010-2014, all rights reserved, contact: operationpixel@free.fr