Introduction à l’informatique et applications à la biologie

VII - Les images

Prof. Patrick E. Meyer

Codage d’un pixel (px)

Le mot Pixel aurait pu venir de “Pic-Cell” mais il s’agit en réalité de “Picture Element”

  • Monochrome 1 bit par px

  • Grayscale: un entier de 8 bits par px, càd combien de niveau de gris?

Codage d’une couleur

Système soustractif,
combiner des couleurs fonce les pixels

  • exemple: cartouches d’imprimante CMYK (Cyan, Magenta, Yellow, Key = Black)

Système additif,
combiner des couleurs éclaircit les pixels

  • exemple: pixels écran rétroéclairé
    RGB (Red, Green, Blue)
  • correspond au trois types de cônes de l’oeil humain

Codage RGB

RGB (Red, Green, Blue):

3 entiers de 8 bits

  • combien de couleurs différentes peut-on coder en rgb?

  • combien d’hexadigits pour coder une seule couleur rgb?

  • \(a:link {color:#00717e}\) dans le code d’une page web?

Codage d’une image

Portable Pixmap (.PPM)

P3: image couleur en décimal

  • Similarité avec la biologie?

  • pourquoi 3 octets pour un px et 3 bases pour un aa?

Les vecteurs

    #include<fstream>
    using namespace std;
    
    const int size = 8;
    ifstream fin("image.ppm");
    
    int main() {
      int rouge[size], vert[size], bleu[size];
      
      ...// lecture d'entête de fichier .ppm
      
      for (int i = 0; i < size; i++) 
          fin >> rouge[i] >> vert[i] >> bleu[i];
      
      ...// suite du programme

Premiers filtres photo

En partant de l’image originale à gauche, qu’a-t-on fait pour obtenir les différents résultats à droite?

  • for (int i = 0; i< size; i++)
         bleu[i] = bleu[i] + 50;

Recadrage

Les matrices

    #include<fstream>
    using namespace std;
    const int nrow = 512;
    const int ncol = 624;
    ifstream fin("image.ppm");
    
    int main() {
      int rouge[nrow][ncol], vert[nrow][ncol], bleu[nrow][ncol];
      ...// lecture d'entête de fichier .ppm
      
      for (int i = 0; i < nrow; i++)
         for (int j = 0; j < ncol; j++) 
            fin >> rouge[i][j] >> vert[i][j] >> bleu[i][j];
            
      ...// suite du programme

Recadrage

    #include<fstream>
    using namespace std;
    const int nrow = 512;
    const int ncol = 624;
    ofstream fout("recadrage.ppm");
    
    int main() {
      int rouge[nrow][ncol], vert[nrow][ncol], bleu[nrow][ncol];
      ...// lecture photo originale
      
      fout << "P3" << endl << 300 << " " << 350 << endl << 255 << endl;
      for (int i = 50; i < 400; i++)
         for (int j = 80; j < 380; j++) 
            fout << rouge[i][j] << vert[i][j] << bleu[i][j];
      ...// suite du programme

Tableaux de taille variable?

    #include<fstream>
    using namespace std;
    const int ncol = 3840; //image en 4K
    const int nrow = 2160; 
    ifstream fin("image.ppm");
    
    int main() {
      int rouge[nrow][ncol], vert[nrow][ncol], bleu[nrow][ncol];
      int ppm[5]; 
      for (int i = 0; i<5; i++)
         fin >> ppm[i];
      for (int i = 0; i < ppm[4]; i++)
         for (int j = 0; j < ppm[3]; j++) 
            fin >> rouge[i][j] >> vert[i][j] >> bleu[i][j];
      ...// suite du programme

Carte graphique

  • En 4K, pixels: 3840 X 2160 \(\approx\) 8.3Mp (en octet?)
  • 8.3*3 \(\approx\) 25Mo (non-compressé)
  • 144hz (144 images par seconde) * 25Mo \(\approx\) 3.6Go/s
  • Hardware dédié aux graphismes (opérations matricielles)

Les chaînes de caractères (string)

  • un mot

  • une phrase

  • une séquence d’adn

  • en C/C++ le dernier caractère d’une chaîne est ‘\0’

  • La classe string (#include<string>) permet de manipuler plus facilement ces vecteurs de lettres

    char mot[50]="Bonjour";
    string s = "Bonjour";