Esempio n. 1
0
Graph *CreateGraph(CImage *cimg)
{
  Graph *g=NULL;
  CImage *cxyz, *clab;
  int ncols, nrows;

  ncols = cimg->C[0]->ncols;
  nrows = cimg->C[0]->nrows;

  cxyz = CImageRGBtoXYZ(cimg);
  clab = CImageXYZtoLAB(cxyz);
  DestroyCImage(&cxyz);

  g = (Graph *) calloc(1,sizeof(Graph));
  if (g != NULL) {
    g->nodes = ComputeNodes(clab);
    g->edges = ComputeEdges(clab);
    g->nnodes = ncols * nrows;
    g->nedges = 2 * ncols * nrows - ncols - nrows;
  } else {
    Error(MSG1,"CreateGraph");
  }
  DestroyCImage(&clab);
  return(g);
}
Esempio n. 2
0
int main(int argc, char** argv)
{
    timer *tic, *toc;
    CImage *cimg=NULL;
    Image *mask=NULL;
    Histogram *hist=NULL;

    if (argc != 4) {
        fprintf(stderr,"usage: extrai_bic <image> <mask> <outputfile>\n");
        exit(-1);
    }

    cimg = ReadJPEGFile(argv[1]);
    mask = ReadImage(argv[2]);

    tic = Tic();
    hist = BIC(cimg, mask);
    toc = Toc();
    printf("BIC extracted in %f milliseconds\n\n",CTime(tic, toc));

    FILE *fp;
    fp = fopen(argv[3],"w");
    if (fp == NULL) {
        fprintf(stderr,"Cannot open %s\n",argv[3]);
        exit(-1);
    }

    WriteFHist(hist, fp);

    DestroyCImage(&cimg);
    DestroyHistogram(&hist);
    DestroyImage(&mask);
    fclose(fp);
    return(0);
}
Esempio n. 3
0
void Extraction(char *img_path, char *fv_path)
{
    CImage *cimg=NULL;
    Image *img=NULL;
    ImageHSV **imgHSV; //imagem no espaco HSV - mesmo tamanho da imagem original
    FeatureVector1D *sasi=NULL;
    int i,j;
    int sizes[3];
    sizes[0]=3;
    sizes[1]=5;
    sizes[2]=7;
    FILE *fout;

    cimg = ReadCImage(img_path);
    img = CreateImage(cimg->C[0]->ncols, cimg->C[0]->nrows);

    //Alocacao da imagem no espaco HSV
    imgHSV = (ImageHSV**) calloc(cimg->C[0]->nrows, sizeof(ImageHSV*));
    for (i=0; i<cimg->C[0]->nrows; i++) {
        imgHSV[i] = (ImageHSV*) calloc(cimg->C[0]->ncols, sizeof(ImageHSV));
    }

    //converte para HSV
    RGB2HSV_sasi(cimg, imgHSV);

    //copia canal V do HSV para a imagem cinza
    for (i = 0; i < cimg->C[0]->nrows; i++) {
        for (j = 0; j < cimg->C[0]->ncols; j++) {
            img->val[j+img->tbrow[i]] = imgHSV[i][j].V;
        }
    }

    sasi = SASI(img, 3, sizes);

    if ((fout = fopen(fv_path, "wb")) == NULL) {
        printf("ERRO CRIANDO ARQUIVO DE FV\n");
        exit(0);
    }
    //fprintf(fout,"%d\n",sasi->n);
    fwrite(&sasi->n,sizeof(int),1,fout);
    fwrite(sasi->X,sizeof(double),sasi->n,fout);
    fclose(fout);

    //liberando memoria imgHSV
    for (i=0; i<cimg->C[0]->nrows; i++) {
        free(imgHSV[i]);
    }
    free(imgHSV);

    DestroyFeatureVector1D(&sasi);
    DestroyCImage(&cimg);
    DestroyImage(&img);

}
Esempio n. 4
0
void Extraction(char *img_path, char *fv_path)
{
    CImage *cimg=NULL; //imagem de entrada
    ImageHSV **imgHSV; //imagem no espaco HSV - mesmo tamanho da imagem original
    Image *img=NULL;
    float *unser=NULL;
    int i,j;

    //le img colorida
    cimg = ReadCImage(img_path);

    //Alocacao da imagem no espaco HSV
    imgHSV = (ImageHSV**) calloc(cimg->C[0]->nrows, sizeof(ImageHSV*));
    for (i=0; i<cimg->C[0]->nrows; i++) {
        imgHSV[i] = (ImageHSV*) calloc(cimg->C[0]->ncols, sizeof(ImageHSV));
    }

    //converte para HSV
    RGB2HSV_unser(cimg, imgHSV);

    //cria imagem cinza
    img = CreateImage(cimg->C[0]->ncols, cimg->C[0]->nrows);

    //copia canal V do HSV para a imagem cinza
    for (i = 0; i < cimg->C[0]->nrows; i++) {
        for (j = 0; j < cimg->C[0]->ncols; j++) {
            img->val[j+img->tbrow[i]] = imgHSV[i][j].V;
        }
    }

    unser = Unser_float(img);    //agora retorna um float*

    FILE *fp;
    if ((fp = fopen(fv_path, "wb")) == NULL) {
        printf("ERRO CRIANDO ARQUIVO DE FV\n");
        exit(0);
    }
    fwrite(unser, sizeof(float), SIZE, fp);
    fclose(fp);

    //liberando memoria
    for (i=0; i<cimg->C[0]->nrows; i++) {
        free(imgHSV[i]);
    }
    free(imgHSV);

    free(unser);
    DestroyCImage(&cimg);
    DestroyImage(&img);

}
Esempio n. 5
0
void Extraction(char *img_path, char *fv_path)
{
  CImage *cimg=NULL;
  Histogram *acc=NULL;

  cimg = ReadCImage(img_path);

  acc = ACC(cimg);

  WriteFileHistogram(acc,fv_path);
  DestroyHistogram(&acc);
  DestroyCImage(&cimg);

}
Esempio n. 6
0
void Extraction(char *img_path, char *fv_path)
{
  CImage *cimg=NULL;
  Image *mask=NULL;
  Histogram *lch=NULL;

  cimg = ReadCImage(img_path);
  mask = CreateImage(cimg->C[0]->ncols, cimg->C[0]->nrows);

  lch = LCH(cimg, mask);

  WriteFileHistogram(lch,fv_path);
  DestroyHistogram(&lch);
  DestroyCImage(&cimg);
  DestroyImage(&mask);

}
Esempio n. 7
0
void Extraction(char *img_path, char *fv_path)
{
  CImage *cimg=NULL;
  Image *mask=NULL;
  Histogram *bic=NULL;

  cimg = ReadCImage(img_path);
  mask = CreateImage(cimg->C[0]->ncols, cimg->C[0]->nrows);

  bic = BIC(cimg, mask);

  WriteFileHistogram(bic,fv_path);
  DestroyHistogram(&bic);
  DestroyImage(&mask);
  DestroyCImage(&cimg);

}
Esempio n. 8
0
int main(int argc, char** argv)
{
  CImage *cimg=NULL;
  Histogram *acc=NULL;

  if (argc != 3) {
    fprintf(stderr,"usage: acc_extraction <img_path> <fv_path>\n");
    exit(-1);
  }

  cimg = ReadCImage(argv[1]);

  acc = ACC(cimg);

  WriteFileHistogram(acc,argv[2]);
  DestroyHistogram(&acc);
  DestroyCImage(&cimg);

  return(0);
}
Esempio n. 9
0
int main(int argc, char **argv)
{
  timer    *t1=NULL,*t2=NULL;
  Image    *img=NULL,*grad=NULL;
  ImageForest *fst=NULL;
  CImage   *cimg=NULL;
  Set      *Obj=NULL,*Bkg=NULL;
  char     outfile[100];
  char     *file_noext;
  /*--------------------------------------------------------*/

  void *trash = malloc(1);
  struct mallinfo info;
  int MemDinInicial, MemDinFinal;
  free(trash);
  info = mallinfo();
  MemDinInicial = info.uordblks;

  /*--------------------------------------------------------*/

  if (argc!=4){
    fprintf(stderr,"Usage: diffwatershed <image.pgm> <gradient.pgm> <seeds.txt>\n");
    fprintf(stderr,"image.pgm: image to overlay the watershed lines on it\n");
    fprintf(stderr,"gradient.pgm: gradient image to compute the watershed segmentation\n");
    fprintf(stderr,"seeds.txt: seed pixels\n");
    exit(-1);
  }

  img   = ReadImage(argv[1]);
  grad  = ReadImage(argv[2]);
  ReadSeeds(argv[3],&Obj,&Bkg);
  fst   = CreateImageForest(img);

  file_noext = strtok(argv[1],".");

  // Add object and background seeds

  t1 = Tic();
  DiffWatershed(grad,fst,Obj,Bkg,NULL); 
  t2 = Toc();
  fprintf(stdout,"Adding object and background seeds in %f ms\n",CTime(t1,t2));
  cimg = DrawLabeledRegions(img,fst->label);
  sprintf(outfile,"%s_result-a.ppm",file_noext);
  WriteCImage(cimg,outfile);
  DestroyCImage(&cimg);
  
  // Remove background trees 

  t1 = Tic();
  DiffWatershed(grad,fst,NULL,NULL,Bkg);
  t2 = Toc();
  fprintf(stdout,"Removing background trees in %f ms\n",CTime(t1,t2));
  cimg = DrawLabeledRegions(img,fst->label);
  sprintf(outfile,"%s_result-b.ppm",file_noext);
  WriteCImage(cimg,outfile);
  DestroyCImage(&cimg);

  // Adding background trees back to the forest  

  t1 = Tic();
  DiffWatershed(grad,fst,NULL,Bkg,NULL);
  t2 = Toc();
  fprintf(stdout,"Adding the removed background trees in %f ms\n",CTime(t1,t2));
  cimg = DrawLabeledRegions(img,fst->label);
  sprintf(outfile,"%s_result-c.ppm",file_noext);
  WriteCImage(cimg,outfile);
  DestroyCImage(&cimg);


  DestroyImageForest(&fst);
  DestroyImage(&img);
  DestroyImage(&grad);
  DestroySet(&Obj);
  DestroySet(&Bkg);


  /* ---------------------------------------------------------- */

  info = mallinfo();
  MemDinFinal = info.uordblks;
  if (MemDinInicial!=MemDinFinal)
    printf("\n\nDinamic memory was not completely deallocated (%d, %d)\n",
	   MemDinInicial,MemDinFinal);

  return(0);
}
Esempio n. 10
0
int main(int argc, char **argv)
{
  timer    *t1=NULL,*t2=NULL;
  Image    *img=NULL,*grad=NULL,*marker=NULL;
  Image    *label=NULL;
  CImage   *cimg=NULL;
  AdjRel   *A=NULL;
  char     outfile[100];
  char     *file_noext;
  /*--------------------------------------------------------*/

  void *trash = malloc(1);
  struct mallinfo info;
  int MemDinInicial, MemDinFinal;
  free(trash);
  info = mallinfo();
  MemDinInicial = info.uordblks;

  /*--------------------------------------------------------*/

  if (argc!=4){
    fprintf(stderr,"Usage: watergray <image.pgm> <gradient.pgm> <H>\n");
    fprintf(stderr,"image.pgm: grayscale image to overlay the watershed lines on it\n");
    fprintf(stderr,"gradient.pgm: gradient image to compute the watershed segmentation\n");
    fprintf(stderr,"H: an integer that will be added to the gradient to eliminate irrelevant basins (typically <= 100)\n");
    exit(-1);
  }

  img    = ReadImage(argv[1]);
  grad   = ReadImage(argv[2]);

  file_noext = strtok(argv[1],".");

  // A grayscale marker can be created by any extensive operation:
  // A value H may be added to eliminate irrelevant basins, for instance.

  marker = AddValue(grad,atoi(argv[3]));

  // Watershed from grayscale marker

  A = Circular(1.0); // try also higher adjacency radii: 1.5, 2.5, etc.

  t1 = Tic();

  label = WaterGray(grad,marker,A);

  t2 = Toc();

  fprintf(stdout,"Processing time in %f ms\n",CTime(t1,t2));

  // Draw watershed lines

  cimg = DrawLabeledRegions(img,label);
  sprintf(outfile,"%s_result.ppm",file_noext);
  WriteCImage(cimg,outfile);
  DestroyImage(&grad);
  DestroyImage(&img);
  DestroyImage(&marker);
  DestroyCImage(&cimg);
  DestroyImage(&label);
  DestroyAdjRel(&A);


  /* ---------------------------------------------------------- */

  info = mallinfo();
  MemDinFinal = info.uordblks;
  if (MemDinInicial!=MemDinFinal)
    printf("\n\nDinamic memory was not completely deallocated (%d, %d)\n",
	   MemDinInicial,MemDinFinal);

  return(0);
}