コード例 #1
0
ファイル: gradient.cpp プロジェクト: joelgallant/skcf
void fhog(const cv::Mat& image, vector<Mat>& fhogs, int binSize,
          int orientations) {
    assert(image.type() == CV_32F || image.type() == CV_32FC3);
    assert(image.isContinuous());
    float *M = new float[image.rows * image.cols];
    float *O = new float[image.rows * image.cols];

    int hb       = image.rows / binSize;
    int wb       = image.cols / binSize;
    int nChannls = orientations * 3 + 5;

    float *H = new float[hb * wb * nChannls];
    fill_n(H, hb * wb * nChannls, 0);
    gradientMagnitude(image, M, O);

    fhog(M, O, H, image.rows, image.cols, binSize, orientations, -1, 0.2f);

    for (size_t i = 0; i < nChannls; i++) {
        Mat tmp(Size(wb, hb), CV_32FC1);
        Matlab2OpenCVC1(H + ( i * (wb * hb)), tmp);
        fhogs.push_back(tmp);
    }

    delete[] H;
    delete[] M;
    delete[] O;
}
コード例 #2
0
float neighborStandardDeviationGradients(const tgt::ivec3& pos, const VolumeRAM* dataset, const tgt::vec3 spacing, Statistics& stats) {
    for (int z=-1; z <= 1; z++)
        for (int y=-1; y <= 1; y++)
            for (int x=-1; x <= 1; x++) {
                tgt::ivec3 p(x, y, z);
                if (p != tgt::ivec3::zero)
                    stats.addSample(gradientMagnitude(pos + p, dataset, spacing));
            }

    return stats.getStdDev();
}
コード例 #3
0
SegmentList WaterShedDecomposer::decompose(ImageColor const & image) const {
   QTime time;
   time.start();

   // original image
   image.save("WS1_original.png");

   // filter image
   time.restart();
   ImageColor filtered = filterGauss(image, radiusGauss->value());
   qDebug("Image filtered in %g seconds", time.restart()/1000.0);
   filtered.save("WS2_filtered.png");

   // calculate gradient magnitude map
   time.restart();
   ImageGray gradientMap = gradientMagnitude(filtered);
   qDebug("Gradient magnitude map calculated in %g seconds", time.restart()/1000.0);
   gradientMap.save("WS3_gradient.png");

   // apply watershed transformation
   time.restart();
   SegmentList segments = watershed(gradientMap, image);
   qDebug("Watershed transformation applied in %g seconds", time.restart()/1000.0);
   qDebug("  Segments: %d", segments.size());
   ImageColor debugOut(image.width(), image.height());
   segments.copyToImageAVG(debugOut);
   debugOut.save("WS4_transformed.png");

   // merge similiar and small segments
   time.restart();
   int oldSegmentsSize;
   do {
      oldSegmentsSize = segments.size();
      mergeSimiliarSegments(segments, epsilonMerge->value()*epsilonMerge->value());
      mergeSmallSegments(segments, minSize->value());
   } while (segments.size() != oldSegmentsSize);
   qDebug("Segments merged in %g seconds", time.restart()/1000.0);
   qDebug("  Segments: %d", segments.size());
   segments.copyToImageAVG(debugOut);
   debugOut.save("WS5_merged.png");

   return segments;
}
コード例 #4
0
ファイル: gradient.cpp プロジェクト: joelgallant/skcf
void fhog(const cv::Mat& image, Mat& fhogs, int binSize, int orientations) {
    assert(image.type() == CV_32F || image.type() == CV_32FC3);
    float *M = new float[image.rows * image.cols];
    float *O = new float[image.rows * image.cols];

    int hb       = image.rows / binSize;
    int wb       = image.cols / binSize;
    int nChannls = orientations * 3 + 5;

    float *H = new float[hb * wb * nChannls];

    gradientMagnitude(image, M, O);

    fhog(M, O, H, image.rows, image.cols, binSize, orientations, -1, 0.2f);

    fhogs = Mat::zeros(Size(wb, hb), CV_32FC(nChannls));
    Matlab2OpenCV(H, fhogs);

    delete [] H;
    delete [] M;
    delete [] O;
}
コード例 #5
0
ファイル: TpIFT6150-2.c プロジェクト: smdarry/tiaut2010
/*------------------------------------------------*/
int main(int argc,int** argv)
{
    int i,j,k,l;
    int length,width;
    float tau_L;
    float tau_H;
    float p_H;
    float sigma;
	
    /* Entrer des valeurs */
    printf("Entrez la valeur de tau_L: ");
    scanf("%f",&tau_L);
    printf("Entrez la valeur de tau_H: ");
    scanf("%f",&tau_H);
    printf("Entrez l'ecart type du filter Gaussien: ");
    scanf("%f",&sigma);
  
    // Chargement de l'image
    float** MatriceImgR=LoadImagePgm(NAME_IMG_IN,&length,&width);
    float** MatriceImgI=fmatrix_allocate_2d(length,width);
    float** gaussMaskI=fmatrix_allocate_2d(length,width);

    // Initialisation a zero de la partie imaginaire
    for(i=0;i<length;i++) 
    {
        for(j=0;j<width;j++) 
        {
	        MatriceImgI[i][j]=0.0;
	        gaussMaskI[i][j]=0.0;
        }
    }

    /* Implementer detecteur de Canny */
    int halfMaskWidth = 16;
    int maskSize = halfMaskWidth*2 + 1;

    ////////////////////////////////////////////
    // Etape 1: application d'un filtre Gaussien
    //
    float** mask = gaussianMask(halfMaskWidth, sigma);
    float** gaussMaskR = padWithZeros(mask, maskSize, maskSize, length, width);

    // Convolution
    float** convR = fmatrix_allocate_2d(length,width);
    float** convI = fmatrix_allocate_2d(length,width);
    FFTDD(MatriceImgR,MatriceImgI,length,width);
    FFTDD(gaussMaskR,gaussMaskI,length,width);
    MultMatrix(convR,convI,MatriceImgR,MatriceImgI,gaussMaskR,gaussMaskI,length,width);
    IFFTDD(convR,convI,length,width);

    // Sauvegarde de l'image filtree
    SaveImagePgm(NAME_IMG_CANNY,convR,length,width);

    /////////////////////////////////////////////
    // Etape 2: calcul du gradient a chaque pixel
    //
    float** gradientX = fmatrix_allocate_2d(length,width);
    float** gradientY = fmatrix_allocate_2d(length,width);
    float** gradientMagn = fmatrix_allocate_2d(length,width);
    float** gradientAngles = fmatrix_allocate_2d(length,width);
    float** contourAngles = fmatrix_allocate_2d(length,width);

    gradient(convR, gradientX, gradientY, length, width);
    gradientMagnitude(gradientX, gradientY, gradientMagn, length, width);
    gradientAngle(gradientX, gradientY, gradientAngles, contourAngles, length, width);

    // Sauvegarde de l'image du gradient
    SaveImagePgm(NAME_IMG_GRADIENT,gradientMagn,length,width);

    // Suppression des non-maximums
    deleteNonMaximums(gradientMagn,contourAngles,length,width);

    // Sauvegarde de l'image des non-maximum supprimes
    SaveImagePgm(NAME_IMG_SUPPRESSION,gradientMagn,length,width);

  /* Sauvegarder les images 
     TpIFT6150-2-gradient.pgm
     TpIFT6150-2-suppression.pgm
     TpIFT6150-2-canny.pgm */

    printf("Entrez la valeur de p_H: ");
    scanf("%f",&p_H);
 
   /* Implementer detecteur de Canny semi-automatique */
  
   /* Sauvegarder l'image TpIFT6150-2-cannySemiAuto.pgm */
   
   /*retour sans probleme*/  
 
  printf("\n C'est fini ... \n\n\n");
  return 0; 	 
}