1 / 21

L2 Elaborazione di i mmagini in C/C++

L2 Elaborazione di i mmagini in C/C++. Corso di Visione Artificiale Ing . Luca Mazzei. Formato immagini. Utilizziamo il formato PGM PPM. P5 320 240 255 @. Dimensioni Immagine. P4 = PBM P5 = PGM P6 = PPM. Valore massimo del colore.

Télécharger la présentation

L2 Elaborazione di i mmagini in C/C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. L2 Elaborazione di immagini in C/C++ Corso di VisioneArtificiale Ing. Luca Mazzei

  2. Formatoimmagini • Utilizziamoilformato PGM PPM • P5 • 320 240 • 255 • @ DimensioniImmagine P4 = PBMP5 = PGMP6 = PPM Valoremassimo del colore InformazioniaggiuntiveEs. TimeStamp, velocita’ (0,0) (0,1) … (1,0) … (319,239) PBM, PGM: 1 byte per pixelPPM: 3 byte per pixel VisioneArtificiale

  3. Formato immagini • In memoria il bitmap è un vettore, buffer • Width lunghezza = numero di colonne • Height altezza = numero di righe (0,0) … i = 0 i = w-1 (W,H) Visione Artificiale

  4. Conversioneimmagini • Suite Imagemagick: convert • .jpg .ppm .pgm .png .bmp convert input_img.xxxoutput_img.xxx (con ubuntu) root@mio_pc:~# apt-cache search imagemagick imagemagick - image manipulation programs www.imagemagick.org VisioneArtificiale

  5. Impostazionealgoritmo • Immagine input edimmagineappoggio, 2 buffer • Buffer di unsigned char, p(x,y) ∊ [0, 255] • Doppio for scansione buffer immagine • Scansione per righe -> adiacenze in memoria for(unsigned intjj= 0; jj< height ; ++jj){ //scorre righe for(unsigned intii= 0; ii < width ; ++ii){ //scorre colonne if(input_buffer[(jj*width)+ii] > 70) { output_buffer[(jj*width)+ii] = 255; } else output_buffer[(jj*width)+ii] = 0; } } } VisioneArtificiale

  6. Librerie STL (Standard Template Library) • Libreria standard basatasu template • Riferimentiwww.cppreference.comwww.cplusplus.com • Contenitori, iteratoriedalgoritmi • Utile per operazionisustrutturedati non presentinelC++ base VisioneArtificiale

  7. Librerie STL (Standard Template Library) • Contenitori: vector, list, map, stack … // create a vector of random integers #include <vector> std::vector<int> v; for( int i = 0; i < 10; ++i ) { int num = (int) rand() % 10; v.push_back( num ); } // print elements std::cout << "vector elements: "; for( int i = 0; i < v.size(); ++i ) { std::cout << v[i] << " "; } std::cout << std::endl; Visione Artificiale

  8. Librerie STL (Standard Template Library) • Iterators • Puntatori ad elementi di un container • forward, bidirectional, random access std::vector<int> v1(3, 5); for(std::vector<int>::iterator it = v1.begin(); it != v1.end(); ++it){ std::cout<< *it << std::endl; } Visione Artificiale

  9. Librerie STL (Standard Template Library) • Algorithm • Min, max, swap, count, sort #include <algorithm> #include <vector> std::vector<int> v; v.push_back( 23 ); v.push_back( -1 ); v.push_back( 9999 ); v.push_back( 0 ); v.push_back( 4 ); std::cout << "Before sorting: "; for( unsigned int i = 0; i < v.size(); i++ ) { std::cout << v[i] << " "; } std::cout << std::endl; sort( v.begin(), v.end() ); std::cout << "After sorting: "; for( unsigned int i = 0; i < v.size(); i++ ) { std::cout << v[i] << " "; } std::cout << std::endl; Visione Artificiale

  10. Strumenti a disposizione per programmare • Image.h • main.cpp • main_color.cpp • (usare solo dopo aver provato a farla) • main_color2grey.cpp • Esempi STL VisioneArtificiale

  11. Image.h struct Image { /// geometry unsignedintwidth, height; /// bit per pixel (8 isgreyscale, 24 isrgb color) unsignedintbpp; /// the bitmap unsignedchar *buffer; public: Image(); ~Image(); /// Allocate the inner buffer /// @paramwidth,height the image geometry /// @parambpp Bit Per Pixel (8 grey, 24 color rgb) voidBuild(unsignedintwidth, unsignedintheight, unsignedintbpp); /// Save the image on @a filename boolSave(constchar *filename) const; /// Load the image from @a filename /// and initializewith,height,bpp and buffer field of struct boolLoad(constchar *filename); }; Visione Artificiale

  12. Binarizzazione • Per ogni pixel confronto con unasoglia VisioneArtificiale

  13. Istogramma • Scansionandotuttol’arraydell’immagine per colonne (o righe) accumulo i valori in un vettore … i = 0 i = 255 Possosalvare i valori in un file e ottenereilgrafico con Gnuplot… VisioneArtificiale

  14. ImmagineDifferenza • diff_img = img1 – img2 • Differenzasingoli pixel • Differenza con sogliatura finale image – background = difference Visione Artificiale

  15. Ritaglioimmagine • Selezionoun’area di interessedell’immagine (Bounding Box) • Nuovo buffer contenenteil bounding box • Dimensioni? • Come gestire le coordinate? Visione Artificiale

  16. Rilevamentobordi • Con operazionilocali, mascheranxn • Maschera di Sobel • Sobelorizzontale • Sobelverticale • Laplace? Prewitt roberts • Estrazionebordi + binarizzazione Roberts Sobel verticale orizzontale Prewitt verticale orizzontale Visione Artificiale

  17. Filtroconvolutivo • Filtromediano, operazione locale nxn • Efficienza in base allamaschera • Utilizzostd::vector e algoritmostd::sort 168 Visione Artificiale

  18. Etichettatura (Labelizzazione) • Es. Sull’immaginedifferenza per evidenziare i blob (areedell’immaginedifferenza di forma indefinita) Visione Artificiale

  19. Labelizzazione a macchiad’olio (floodfill) L Nuovo LabelL=L+1 Espansione push Controllo vicinato push pop … vector<punto> Visione Artificiale

  20. Immagini a colori • Come è fattoilvettore bitmap? • Impostazionedoppio for? • Sogliatura? • Rimane per casa… VisioneArtificiale

  21. Assegnamento • Per le immaginipgm: • Copiadell’immagine • Istogramma • Sogliatura, binarizzazione • Abbassamentoluminosita’ • Filtromediano • Estrazionedeicontorni • Differenzatraimmagini • Ritaglio di unaporzionedell’immagine • Labellizzazione a macchiad’olio • Per le immagini a colori: • Copiadell’immagine • Istogramma per ognivalore del pixel RGB • Sogliatura, binarizzazione • Abbassamentoluminosita’ • Filtromediano sui trecanali • Estrazionedeicontorni • Differenzatraimmagini • Ritaglio di unaporzionedell’immagine Visione Artificiale

More Related