} ?> Operation Pixel Images Processing

# Color Processing

## Saturation et desaturation

### Method

The desaturation is a uniform reduction of RGB colors. To make it, we weight the difference between a color and the luminance by a factor f. As:

$\left[\begin{array}{c}R\text{'}\\ G\text{'}\\ B\text{'}\end{array}\right]←\left[\begin{array}{c}Y\\ Y\\ Y\end{array}\right]+f\cdot \left[\begin{array}{c}R-Y\\ G-Y\\ B-Y\end{array}\right]$

For the desaturation $0\le f<1$ , for the saturation $1 . An f=0 will give a grayscale image (luminance) and an f=1 doesn't change the original image.

### Program

``` 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```

### Example

desaturation with f=0.5

saturation with f=2