# Gray Level Image Processing

## Inversion

### Method

In this section, we will do an inversion of an image. The computation is quite simple because it just have to make ligth pixels into dark and vice versa. The mathematical equation is:

Example, an image of k = 8, then 256 levels of gray, the white which is 255 goes to 0, then 254 -> 1, 253 -> 2 ...

### Pogram

```clear all; close all; [filename, pathname] = uigetfile({'*.jpg;*.tif;*.PNG;*.gif;*.bmp','All Image Files';...           '*.*','All Files' },'mytitle',...           'C:\Work\myfile.jpg') x = imread(filename); % image sur un plan if (length(size(x))>2)     x=x(:,:,1);% on prend une seul plan image noir et blanc chaque plan sont egaux end % nombre de bit info = whos('x'); if strcmp(info.class,'uint8')     k=8; elseif strcmp(info.class,'uint16')     k=16; elseif strcmp(info.class,'uint32')     k=32; elseif strcmp(info.class,'uint64')     k=64; end   %taille de la matrice [ligne colonne]=size(x); % on crée une matrice résultat de la même cast que l'image inverse= zeros(ligne,colonne); if strcmp(info.class,'uint8')     inverse=uint8(inverse); elseif strcmp(info.class,'uint16')     inverse=uint16(inverse); elseif strcmp(info.class,'uint32')     inverse=uint32(inverse); elseif strcmp(info.class,'uint64')     inverse=uint64(inverse); end % algorithme de l'inversion  for i=1:ligne      for j=1:colonne          inverse(i,j) = 2^k - x(i,j);      end  end  % on affiche le résultat  figure(1)  subplot(121)  imshow(x)  subplot(122)  imshow(inverse)```

### Example

We have the next result :