コード例 #1
0
Image_t<double>* Transforms::hough2(const Image *image, double angleStep, double rhoStep) {

//    double angleStep = .5;
//    double rhoStep = 1.;


//    double imageDiag = image->getWidth() * sqrt(2.);
    double imageDiag = sqrt(image->getWidth()*image->getWidth() + image->getHeight()*image->getHeight());
    Image_t<double>* resImg = new Image_t<double>(1. + imageDiag / rhoStep, 180. / angleStep + 0.5, image->getNbChannels(), 0.);


    for(unsigned int c = 0; c < image->getNbChannels(); ++c) {

        for(unsigned int j = 0; j < image->getHeight(); ++j) // on parcourt l'image
        {
            for(unsigned int i = 0; i < image->getWidth(); ++i)
            {
                if(image->getPixelAt(i, j, c) == 255)
                {

                    for(double te=0; te < 180; te += angleStep) // on parcourt la matrice
                    {
                        const double coste = cos(te * pi / 180.);
                        double sinte = sin(te * pi / 180.);

    //                    for(double ro = 0; ro < imageDiag; ro += rhoStep)
    //                    {
    //                        // on incrmente la matrice pour l'intervalle de ro correspondant au teta
    //                        if( (ro <= (i*coste+j*sinte) ) && ( (i*coste+j*sinte) < (ro+rhoStep) ) )
    //                        {
    //                            resImg->pixelAt(ro / rhoStep, te / angleStep)++;
    //                        }
    //                    }
                        const double rho = i * coste + j * sinte;
//                        const double start = max(0., delta);
//                        const double end = min(imageDiag, delta + rhoStep);

//                        for(double ro = start; ro < end; ro += rhoStep)
                        if(rho >= 0. && rho < imageDiag)
                        {
                            resImg->pixelAt(rho / rhoStep + 0.5, te / angleStep + 0.5, c)++;
                        }
                    }
                }
            }
        }
    }



//    //Exemple d'affichage de texte dans la fentre "texte"
//    char buffer[455];
//    sprintf( buffer, "Lecture du rsultat :\nLigne du haut : angle=0\nLigne du bas : angle=+180\nColonne de gauche : distance=0\nColonne de droite : distance max (diagonale de l'image)\nPoint de rfrence pour les distances : coin en haut  gauche\nDroite de rfrence pour les angles : axe VERTICAL\nAngles positifs dans le sens trigonomtrique indirect");
//    oh->AddString( buffer );



    return resImg;
}
コード例 #2
0
ファイル: DCT.cpp プロジェクト: eiimage/eiimage
std::string dct16x16(const imagein::Image *img, imagein::Image_t<double> **resImg, imagein::Image **invImg, bool truncMode, int truncLimit, int nBitInit, double slope)
{
    string returnval;
/*----------------------------------------------------------------------
*
*     OUVERTURE ET LECTURE DU FICHIER IMAGE ORIGINE
*
*----------------------------------------------------------------------*/
    Image_t<double>* tmpImg;
    if(img->getWidth() % 16 != 0 || img->getHeight() % 16!= 0){
        int addcol = 0;
        int addlign = 0;
        if(img->getWidth()  % 16 != 0 )
            addcol = 16 - ( img->getWidth() % 16 );
        if(img->getHeight()  % 16 != 0 )
            addlign = 16 - ( img->getHeight() % 16 );
        
        tmpImg = new Image_t<double>(img->getWidth() + addcol, img->getHeight() + addlign, img->getNbChannels());
        for(unsigned int c = 0; c < tmpImg->getNbChannels(); c++) {
            for(unsigned int i = 0; i < tmpImg->getWidth() ; i++) {
                for(unsigned int j = 0; j < tmpImg->getHeight() ; j++) {
                    
                    tmpImg->setPixel(i, j, c, (double) img->getPixel(min(i, img->getWidth()-1 ), min(j, img->getHeight()-1), c));
                
                }
            }
        }
    }
    else {
       tmpImg = Converter<Image_t<double> >::convert(*img);
    }
/*----------------------------------------------------------------------
*
*     CALCUL DES COEFFICIENTS DE LA MATRICE DE TRANSFORMATION
*
*----------------------------------------------------------------------*/
    double coef[16];
    cosi(coef);
/*----------------------------------------------------------------------
*
*     TRANSFORMATION
*
*----------------------------------------------------------------------*/
    dct(tmpImg, coef);
/*----------------------------------------------------------------------
*
*     CODAGE
*
*----------------------------------------------------------------------*/
    if(truncMode) {
        returnval = tronc(tmpImg, truncLimit);
    }
    else {
        returnval = reduce(tmpImg, nBitInit, slope);
    }

/*----------------------------------------------------------------------
*
*     STOCKAGE DE L'IMAGE TRANSFORMEE DANS UN FICHIER
*
*----------------------------------------------------------------------*/
    *resImg = new Image_t<double>(*tmpImg);

/*----------------------------------------------------------------------
*
*     TRANSFORMATION INVERSE
*
*----------------------------------------------------------------------*/
    idct(tmpImg, coef);

/*----------------------------------------------------------------------
*
*     STOCKAGE DE L'IMAGE RESULTAT DANS UN FICHIER
*
*----------------------------------------------------------------------*/
    *invImg = Converter<Image>::convertAndRound(*tmpImg);
    delete tmpImg;
    return returnval;
}
コード例 #3
0
string hadamard_haar_88( const Image *im, Image_t<double> **resImg, Image **invImg, double *rmat, GrayscaleImage_t<bool> *selection ) {
    if(!( im != NULL && resImg != NULL && invImg != NULL )) {
        char buffer[255];
        sprintf( buffer, "Error in Transforms::hadamard_haar_88:\nim = %p, result = %p, result_inverse = %p", im, resImg, invImg );
        throw buffer;
    }
    // Returns result as the resulting image
    // Returns result_inverse as the inverse of the resulting image
    int idt = 8;
    double res[8];
    string returnval;

/*----------------------------------------------------------------------
*
*     OUVERTURE ET LECTURE DU FICHIER IMAGE ORIGINE
*     ALLOCATION MEMOIRE POUR LES TABLEAUX IMAGES
*
*----------------------------------------------------------------------*/
    Image_t<double>* tmpImg = Converter<Image_t<double> >::convert(*im);

/*---------------------------------------------------------------------
*
*     CALCUL DES COEFFICIENTS DE LA MATRICE DE TRANSFORMATION
*
*---------------------------------------------------------------------*/

    char buffer[100];
    returnval = "\n\nmatrice de transformation utilisee : \n";

    for(int i=0 ; i<idt ; i++)
    {
        for(int j=0 ; j<idt ; j++)
        {
            sprintf( buffer,"%5.2f  ",rmat[i * idt + j]);
            returnval = returnval + buffer;
        }
        returnval = returnval + "\n";
    }

/*----------------------------------------------------------------------
*
*     TRANSFORMATION
*
*----------------------------------------------------------------------*/

    for(unsigned int c = 0; c < tmpImg->getNbChannels(); ++c) {
      for(unsigned int i=0 ; i < tmpImg->getWidth() ; i += idt) {
          for(unsigned int j=0 ; j < tmpImg->getHeight() ; j += idt) {

              double res[8];
              for(int k = 0 ; k < idt ; ++k) res[k] = 0.;


              for(int k = 0; k < idt; ++k) {

                  for(int l = 0; l < idt; ++l) {
                      for(int m=0 ; m<idt ; m++) {
                          res[l] += rmat[l * idt + m] * tmpImg->getPixelAt(i+k, j+m, c);
                      }
                  }

                  for(int l=0 ; l<idt ; l++) {
                      tmpImg->setPixelAt(i+k, j+l, c, res[l]);
                      res[l] = 0.;
                  }
              }

              for(int k = 0; k < idt; ++k) {

                  for(int l=0 ; l<idt ; l++) {
                      for(int m=0 ; m<idt ; m++) {
                          res[l] += rmat[l * idt + m] * tmpImg->getPixelAt(i+m, j+k, c);
                      }
                  }

                  for(int l=0 ; l<idt ; l++) {
                      tmpImg->setPixelAt(i+l, j+k, c, +res[l]);
                      res[l] = 0.;
                  }
              }
          }
      }
    }

/*----------------------------------------------------------------------
*
*     CODAGE
*
*----------------------------------------------------------------------*/

  if(selection != NULL) {
    for(unsigned int c = 0; c < tmpImg->getNbChannels(); ++c) {
      for(unsigned int j = 0; j < tmpImg->getHeight(); ++j) {
          for(unsigned int i = 0; i < tmpImg->getWidth(); ++i) {
              if(!selection->getPixelAt(i % 8, j % 8)) {
                  tmpImg->setPixelAt(i, j, c, 0.);
              }
          }
      }
    }
  }

/*----------------------------------------------------------------------
*
*     STOCKAGE DE L'IMAGE TRANSFORMEE DANS UN FICHIER
*
*----------------------------------------------------------------------*/
  *resImg = new Image_t<double>(*tmpImg);

/*----------------------------------------------------------------------
*
*     TRANSFORMATION INVERSE
*
*----------------------------------------------------------------------*/

for(unsigned int c = 0; c < tmpImg->getNbChannels(); ++c) {
  for(unsigned int i=0 ; i< tmpImg->getHeight() ; i+=idt) {
     for(unsigned int j=0 ; j<tmpImg->getWidth(); j+=idt)
     {
        for(int k=0 ; k<idt ; k++)
          res[k] = 0.;

        for(int k=0 ; k<idt ; k++)
        {
          for(int l=0 ; l<idt ; l++)
             for(int m=0 ; m<idt ; m++)
                res[l] += rmat[m * idt + l] * tmpImg->getPixelAt(i+m, j+k, c);

          for(int l=0 ; l<idt ; l++)
          {
             tmpImg->setPixelAt(i+l, j+k, c, res[l]);
             res[l] = 0.;
          }
        }

        for(int k=0 ; k<idt ; k++)
        {
          for(int l=0 ; l<idt ; l++)
             for(int m=0 ; m<idt ; m++)
                res[l] += rmat[m * idt + l] * tmpImg->getPixelAt(i+k, j+m, c);

          for(int l=0 ; l<idt ; l++)
          {
             tmpImg->setPixelAt(i+k, j+l, c, res[l]);
             res[l] = 0.;
          }
        }
     }
  }
}

/*----------------------------------------------------------------------
*
*     STOCKAGE DE L'IMAGE RESULTAT DANS UN FICHIER
*
*----------------------------------------------------------------------*/
//  Image *tabout = new Image(im->getWidth(), im->getHeight(), tmpImg->getNbChannels());
//  for(unsigned int i=0 ; i<tmpImg->getHeight() ; i++)
//     for(unsigned int j=0 ; j<tmpImg->getWidth() ; j++)
//     {
//        double ftemp = tmpImg->getPixelAt(j, i);
//        if(ftemp < 0)
//          ftemp = 0;
//        if(ftemp > 255)
//          ftemp = 255;
//        tabout->setPixel( j, i, (uint8_t)(ftemp + 0.5) );
//     }

//     *invImg = new Image(tmpImg->getWidth(), tmpImg->getHeight(), tmpImg->getNbChannels());
//    for(unsigned int c = 0; c < tmpImg->getNbChannels(); ++c) {
//        for(unsigned int j = 0; j < tmpImg->getHeight(); ++j) {
//            for(unsigned int i = 0; i < tmpImg->getWidth(); ++i) {
//                double value = tmpImg->getPixelAt(i, j, c);
//                (*invImg)->setPixelAt(i, j, c, value + 0.5);
//            }
//        }
//    }
     *invImg = Converter<Image>::convertAndRound(*tmpImg);


//    delete tabin;
    return returnval;
}
コード例 #4
0
Image_t<double>* Transforms::hough(const GrayscaleImage *image ) {
//    int height = image->getHeight();
//    int width = image->getWidth();
//    const uint8_t* tabim = image->begin();
//    double* itab = new double[ image->size() ];
//    for(unsigned int i = 0; i < image->size(); ++i) itab[i] = 0;
    double diag = sqrt(image->getWidth()*image->getWidth() + image->getHeight()*image->getHeight());
    Image_t<double>* resImg = new Image_t<double>(diag+0.5, 180, 1, 0.);

    for(unsigned int j = 0; j < image->getHeight(); j++) {
        for(unsigned int i = 0; i < image->getWidth(); i++) {

            if(image->getPixelAt(i, j) == 255) {

                int j1 = j;

                for(unsigned int i1 = i+1; i1 < image->getWidth(); i1++) {
                    if(image->getPixelAt(i1, j1) == 255) {
                        const double x0 = i;
                        const double y0 = j;
                        const double x1 = i1;
                        const double y1 = j1;
                        const double l0 = sqrt((double)((y0-y1)*(y0-y1) + (x0-x1)*(x0-x1)));
                        const double l1 = fabs((double)(x0*y1 - x1*y0));
                        const double x2 = l1/l0;
                        double y2;
                        const int i2 = x2 + 0.5;
                        int j2;
//                        if(x1-x0 != 0) {
//                            y2 = atan((y1-y0)/(x1-x0));
//                            j2 = 125 + (int)(y2*124./pid2 + 0.5);
                            y2 = (x1 != x0) ? atan((y1-y0) / (x1-x0)) : y1 > y0 ? pid2 : -pid2;
                            j2 = (y2 / pi) * 180. + 90. + 0.5;
//                            j2 = (x1 != x0) ? 125.5 + atan((y1-y0)/(x1-x0))*124./pid2 : 250;
//                        }
//                        else {
//                            j2 = 250;
//                        }

//                        itab[j2*width+i2]++;
                        resImg->setPixelAt(i2, j2, resImg->getPixelAt(i2, j2) + 1.);
                    }
                }

                for(unsigned int j1 = j+1; j1 < image->getHeight(); j1++) {
                    for(unsigned int i1 = 0; i1 < image->getWidth(); i1++) {
                        if(image->getPixelAt(i1, j1) == 255) {
                            const double x0 = i;
                            const double y0 = j;
                            const double x1 = i1;
                            const double y1 = j1;
                            const double l0 = sqrt((double)((y0-y1)*(y0-y1) + (x0-x1)*(x0-x1)));
                            const double l1 = fabs((double)(x0*y1 - x1*y0));
                            const double x2 = l1/l0;
                            double y2;
                            const int i2 = x2 + 0.5;
                            int j2;
//                            if(x1-x0 != 0) {
//                                y2 = atan((double)(y1-y0)/(x1-x0));
//                                j2 = 125 + (int)(y2*124./pid2 + 0.5);
//                            }
//                            else {
//                                j2 = 250;
//                            }
                            y2 = x1 != x0 ? atan((y1-y0) / (x1-x0)) : y1 > y0 ? pid2 : -pid2;
//                            j2 = (y2 / pi + 0.5) * image->getHeight() + 0.5;
//                            j2 = (y2 * 2. + pi)*100.  + 0.5;
                            j2 = (y2 / pi) * 180. + 90. + 0.5;
//                            j2 = (x1 != x0) ? 125.5 + atan((y1-y0)/(x1-x0))*124./pid2 : 250;

//                            itab[j2*width+i2]++;
                            resImg->setPixelAt(i2, j2, resImg->getPixelAt(i2, j2) + 1.);
                        }
                    }
                }
            }
        }
    }
//    Image_t<double> *returnval = new Image_t<double>(width, height, 1, itab);
//    delete itab;
//    return returnval;
    return resImg;

}
コード例 #5
0
string Transforms::hough2_inverse(const Image_t<double> *image, Image** resImgptr, unsigned int size, unsigned int threshold) {

    Image_t<uint32_t>* resImg = new Image_t<uint32_t>(size, size, image->getNbChannels(), uint32_t(0));

//    int param = 5000 + 20 * image->getWidth() * image->getHeight();

//    char *buffer;
//    buffer=(char *)calloc(param,sizeof(char));


//    char tampon[50];
//    sprintf( buffer, "Valeur Max de la matrice d'entre=%d",(int)(max+0.1));


    double angleStep = 180. / image->getHeight();
    double imageDiag = resImg->getWidth() * sqrt(2.);
    double rhoStep = imageDiag / image->getWidth();

    //Algorithme de traitement

    int cmpt = 0;
    for(unsigned int c = 0; c < image->getNbChannels(); ++c) {
        for(unsigned int j = 0; j < image->getHeight(); ++j) {
            for(unsigned int i = 0; i < image->getWidth(); ++i) {

                int n = image->getPixelAt(i, j, c);
                if(n >= threshold)
                {
                    cmpt++;
                    double angle = angleStep * j / 180. * pi;
                    double rho = rhoStep * i;
                    double sinte = sin(angle);
                    double coste = cos(angle);

    //                sprintf( tampon,"\nniveau=%d\tangle=%1.0f\tdistance=%1.0f",(int)(0.1+tab_image[i+nl*j]),angle/pi*180.,rho);
    //                strcat( buffer, tampon);

                    //Construction de la droite d'quation
                    for(unsigned int jj = 0; jj < size; ++jj) {

    //                    int kk = rho * (cos(angle) + tan(angle) * sin(angle)) - tan(angle)*jj;
                        int kk = (rho - sinte * jj) / coste;
                        if( kk > 0 && kk < size) {
                            resImg->pixelAt(kk, jj, c) += n;
                        }
                    }
                    for(unsigned int ii = 0; ii < size; ++ii) {
    //                    int kk = ( rho * (cos(angle) + tan(angle) * sin(angle)) -ii ) / tan(angle);
                        int kk = (rho - coste * ii) / sinte;
                        if( kk>0 && kk < size) {
                            resImg->pixelAt(ii, kk, c) += n;
                        }
                     }

                }
            }
        }
    }

//        sprintf( tampon,"\nNombre de droites traces=%d",cmpt);
//        strcat( buffer, tampon);
    std::cout << resImg->max() << std::endl;
    Image* resStdImg = new Image(resImg->getWidth(), resImg->getHeight(), resImg->getNbChannels());
    Image_t<uint32_t>::iterator it = resImg->begin();
    Image::iterator jt = resStdImg->begin();
    double max = resImg->max();
    while(it != resImg->end()) {
        *jt = *it * 256. / max + 0.5;
        ++it;
        ++jt;
    }

    *resImgptr = resStdImg;
    return "";
}
コード例 #6
0
ファイル: RandomImgOp.cpp プロジェクト: eiimage/eiimage
void RandomImgOp::operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&) {
    QDialog* dialog = new QDialog(qApp->activeWindow());
    dialog->setWindowTitle(qApp->translate("RandomImgOp", "Parameters"));
    dialog->setMinimumWidth(180);
    QFormLayout* layout = new QFormLayout(dialog);

    QGroupBox* radioGroup = new QGroupBox(qApp->translate("RandomImgOp", "Image type"), dialog);
    QRadioButton* intButton = new QRadioButton(qApp->translate("RandomImgOp", "8-bit integer"));
    QRadioButton* floatButton = new QRadioButton(qApp->translate("RandomImgOp", "Floating point"));
    QHBoxLayout* radioLayout = new QHBoxLayout(radioGroup);
    radioLayout->addWidget(intButton);
    radioLayout->addWidget(floatButton);
    intButton->setChecked(true);
    layout->insertRow(0, radioGroup);

    QSpinBox* widthBox = new QSpinBox(dialog);
    widthBox->setRange(0, 65536);
    widthBox->setValue(512);
    layout->insertRow(1, qApp->translate("RandomImgOp", "Width : "), widthBox);

    QSpinBox* heightBox = new QSpinBox(dialog);
    heightBox->setRange(0, 65536);
    heightBox->setValue(512);
    layout->insertRow(2, qApp->translate("RandomImgOp", "Height : "), heightBox);

    QSpinBox* channelBox = new QSpinBox(dialog);
    channelBox->setRange(1, 4);
    channelBox->setValue(3);
    layout->insertRow(3, qApp->translate("RandomImgOp", "Number of channels : "), channelBox);

    QWidget* intRangeWidget = new QWidget(dialog);
    QHBoxLayout* intRangeLayout = new QHBoxLayout(intRangeWidget);
    QSpinBox* intMinBox = new QSpinBox(dialog);
    QSpinBox* intMaxBox = new QSpinBox(dialog);
    intMinBox->setRange(0, 255);
    intMaxBox->setRange(0, 255);
    intMinBox->setValue(0);
    intMaxBox->setValue(255);
    intRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", "Range : ")));
    intRangeLayout->addWidget(intMinBox);
    intRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", " to ")));
    intRangeLayout->addWidget(intMaxBox);
    layout->insertRow(4, intRangeWidget);

    QWidget* floatRangeWidget = new QWidget(dialog);
    QHBoxLayout* floatRangeLayout = new QHBoxLayout(floatRangeWidget);
    QDoubleSpinBox* floatMinBox = new QDoubleSpinBox(dialog);
    QDoubleSpinBox* floatMaxBox = new QDoubleSpinBox(dialog);
    floatMinBox->setValue(0.0);
    floatMaxBox->setValue(1.0);
    floatMinBox->setRange(-65536, 65536);
    floatMaxBox->setRange(-65536, 65536);
    floatRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", "Range : ")));
    floatRangeLayout->addWidget(floatMinBox);
    floatRangeLayout->addWidget(new QLabel(qApp->translate("RandomImgOp", " to ")));
    floatRangeLayout->addWidget(floatMaxBox);
    layout->insertRow(5, floatRangeWidget);
    floatRangeWidget->hide();

    layout->setSizeConstraint(QLayout::SetFixedSize);

    QObject::connect(intButton, SIGNAL(toggled(bool)), intRangeWidget, SLOT(setVisible(bool)));
    QObject::connect(floatButton, SIGNAL(toggled(bool)), floatRangeWidget, SLOT(setVisible(bool)));

    QPushButton *okButton = new QPushButton(qApp->translate("Operations", "Validate"), dialog);
    okButton->setDefault(true);
    layout->addWidget(okButton);
    QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));

    QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec());

    if(code!=QDialog::Accepted) {
        return;
    }

    if(intButton->isChecked()) {

        Image* resImg = new Image(widthBox->value(), heightBox->value(), channelBox->value());
        RandomLib::Random random;
        for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) {
            for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
                for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
                    Image::depth_t value = random.IntegerC<Image::depth_t>(intMinBox->value(), intMaxBox->value());
//                    Image::depth_t value = 256. * (rand() / (RAND_MAX + 1.));;
                    resImg->setPixel(i, j, c, value);
                }
            }
        }
        this->outImage(resImg, qApp->translate("Operations", "Random image").toStdString());

    }
    else if(floatButton->isChecked()) {

        Image_t<double>* resImg = new Image_t<double>(widthBox->value(), heightBox->value(), channelBox->value());
        RandomLib::Random random;
        for(unsigned int c = 0; c < resImg->getNbChannels(); ++c) {
            for(unsigned int j = 0; j < resImg->getHeight(); ++j) {
                for(unsigned int i = 0; i < resImg->getWidth(); ++i) {
                    double min = floatMinBox->value();
                    double max = floatMaxBox->value();
//                    double width = max - min;
//                    double value = min + (double)rand() * width / RAND_MAX;
                    double value = random.FixedN<double>();
                    value = value*(max-min) + min;
                    resImg->setPixel(i, j, c, value);
                }
            }
        }
        this->outDoubleImage(resImg, qApp->translate("Operations", "Random image").toStdString(), true);

    }
}