Bonjour,

j'utilise la librairie CImg pour faire du traitement d'image. J'aimerais modifier une partie du code suivant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Constructor that computes statistics of an input image \p img.
    /**
        \param img The input image.
        \param compute_variance If true, the \c variance field is computed, else it is set to 0.
    **/
    template<typename T> CImgStats(const CImg<T>& img, const bool compute_variance=true) {
      assign(img,compute_variance);
    }

    //! In-place version of the previous constructor.
    template<typename T> CImgStats& assign(const CImg<T>& img, const bool compute_variance=true) {
      if (!img)
        throw CImgArgumentException("CImgStats::CImgStats() : Specified input image (%u,%u,%u,%u,%p) is empty.",
                                    img.width,img.height,img.depth,img.dim,img.data);
      mean = variance = 0;
      lmin = lmax = -1;
      T pmin=img[0], pmax=pmin, *ptrmin=img.data, *ptrmax=ptrmin;
      cimg_for(img,ptr,T) {
        const T& a=*ptr;
        mean+=(double)a;
        if (a<pmin) { pmin=a; ptrmin = ptr; }
        if (a>pmax) { pmax=a; ptrmax = ptr; }
        if (a>230) {je voudrais stocker les a dans un vecteur ou une liste ainsi que les pointeurs ptr}
      }
      mean/=img.size();
      min=(double)pmin;
      max=(double)pmax;
      unsigned long offmin = (unsigned long)(ptrmin-img.data), offmax = (unsigned long)(ptrmax-img.data);
      const unsigned long whz = img.width*img.height*img.depth, wh = img.width*img.height;
      vmin = offmin/whz; offmin%=whz; zmin = offmin/wh; offmin%=wh; ymin = offmin/img.width; xmin = offmin%img.width;
      vmax = offmax/whz; offmax%=whz; zmax = offmax/wh; offmax%=wh; ymax = offmax/img.width; xmax = offmax%img.width;
      if (compute_variance) {
        cimg_for(img,ptr,T) { const double tmpf=(*ptr)-mean; variance+=tmpf*tmpf; }
        const unsigned int siz = img.size();
        if (siz>1) variance/=(siz-1); else variance=0;
      }
      return *this;
    }

En fait, ce code garde en mémoire UN SEUL maximum et UN SEUL minimum de l'image.
Je voudrais modifier le code pour en garder plusieurs.
Les deux lignes qui ne gardent qu'un max et qu'un min sont celles en vert.
Je voudrais rajouter la ligne en rouge qui dit que tous les pixels dont l'intensité est supérieure à 230 doivent être mis dans un vecteur ou dans une liste ainsi que les pointeurs correspondants (ptr dans le code). Comment puis-je écrire cette ligne car je n'arrive pas à trouver la syntaxe exacte, je suis débutant en C++.

Ensuite, les éléments du vecteur créé subiraient le même traitement que ptrmin et ptrmax (en rose) et mon but final est d'avoir les valeurs vmin, zmin, ymin, xmin, vmax, zmax, ymax, xmax pour les autres maximums trouvés.

Merci de votre aide