l'image de fond

fr       en

Traitements d'Images Couleurs

Saturation et désaturation

Méthode

La désaturation est une réduction uniforme des couleurs RGB. Pour ce faire, on pondère la différence entre une couleur et la luminance d'un facteur f. On a :

[ R ' G ' B ' ] [ Y Y Y ] + f [ R - Y G - Y B - Y ]

Pour la désaturation 0 f < 1 , pour la saturation 1 < f . Un f=0 donnera l'image en niveau de gris (luminance) et un f=1 ne changera pas l'image d'origine.

Programme

 function desaturation
clear all;
close all;
figure(  'Name','Desaturation Saturation',...
            'NumberTitle','off',...
            'color',[0.3137 0.3137 0.5098]);
       
a(1)=axes('units','normalized',...
    'position',[0.05 0.35 0.45 0.45]);
a(2)=axes('units','normalized',...
    'position',[0.5 0.35 0.45 0.45]);
 
uicontrol(  'style','pushbutton',...
            'string','load',...
            'Position', [10 10 50 20],...
            'callback',@loadimage);
uicontrol(  'style','Slider',...
            'Position', [180 10 100 20],...
            'Min',0,'Max',10,'Value',0.5,...
            'SliderStep',[0.001 0.01], ...
            'callback',@saturation);
       
text(1)=uicontrol(  'style','text',...
            'string','facteur de saturation: 0.5',...
            'Position', [150 30 160 20]);
%parametre initial
setappdata(gcf,'img',1);
setappdata(gcf,'f',0.5);

     
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')

    img = double(imread(filename));
    setappdata(1,'img',img);
    axes(a(1))
    imshow(uint8(img))
    title('original image')

   
end
function saturation(hObj,~)
     f = get(hObj,'Value');
     img = getappdata(1,'img');    
     R=img(:,:,1);
     G=img(:,:,2);
     B=img(:,:,3);
     %Luminance
     wr=0.299;
     wg=0.587;
     wb=0.114;
     img_L = ( R * wr + G * wg + B * wb );
     %hueless
     img_hueless = cat(3, img_L, img_L, img_L);
     %saturation
     img_D = img_hueless + f * cat(3, R-img_L, G-img_L, B-img_L);
     axes(a(2))
     imshow(uint8(img_D))
     if f<1
         title('desaturation')
     else
         title('saturation')
     end
     set( text(1), 'String', strcat('facteur de saturation: ',num2str(f)));
end

end

Exemple

désaturation avec f=0,5
desaturation
saturation avec f=2
saturation

Copyright © 2010-2014, tous droits réservés, contact : operationpixel@free.fr