コード例 #1
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 "";
}