Пример #1
0
VglSimpleBGModel::VglSimpleBGModel(VglImage* img_in, float std_thresh, int window_size, int num_training_images){
    this->width     = img_in->shape[VGL_WIDTH];
    this->height    = img_in->shape[VGL_HEIGHT];
    this->nChannels = img_in->nChannels;
    this->depth     = img_in->depth;
    

    if (depth != IPL_DEPTH_8U){
      printf("VglSimpleBGModel: Error: depth must be IPL_DEPTH_8U\n");
      return;
    }
    if (num_training_images < 2){
      printf("VglSimpleBGModel: Error: num_training_images must be >= 2\n");
      return;
    }
    if (std_thresh <= 0.0){
      printf("VglSimpleBGModel: Error: std_thresh must be > 0.0\n");
      return;
    }
    if (window_size < 1){
      printf("VglSimpleBGModel: Error: window_size must be >= 1\n");
      return;
    }

    this->num_training_images = num_training_images;
    this->std_thresh          = std_thresh;
    this->window_size         = window_size;

    foreground      = vglCreateImage(img_in); // should be single channel
    foregroundClose = vglCreateImage(img_in); // should be single channel
    buf             = vglCreateImage(img_in); // should be single channel
    background32    = vglCreateImage(cvSize(width, height), IPL_DEPTH_32F, nChannels); // should be float
    variance32      = vglCreateImage(cvSize(width, height), IPL_DEPTH_32F, nChannels); // should be float

    vglClear(foreground,      0.0, 0.0, 0.0);
    vglClear(foregroundClose, 0.0, 0.0, 0.0);
    vglClear(buf,             0.0, 0.0, 0.0);
    vglClear(background32,    0.0, 0.0, 0.0);
    vglClear(variance32,      0.0, 0.0, 0.0);

    curr_training_image = 0;

    sobel = 0;
    color = 0;
    grayx = 0;
    grayy = 0;
    //TrainVglSimpleBGModel(img_in);

    vglSetContext(foreground,      VGL_GL_CONTEXT);
    vglSetContext(foregroundClose, VGL_GL_CONTEXT);
    vglSetContext(buf,             VGL_GL_CONTEXT);
    vglSetContext(background32,    VGL_GL_CONTEXT);
    vglSetContext(variance32,      VGL_GL_CONTEXT);

}
Пример #2
0
/** Function for loading TIFF images.

    Function for loading TIFF images. Supports RGB (8 bits) and 
grayscale (8 and 16 bits) images, 2D and 3D. Alternative version with simpler code.

  */
VglImage* vglLoadTiffAlt(char* inFilename)
{  
  TIFF* tif;
  VglImage* img;
  uint16 pageNumber, numberPages, subfileType;

  tif = TIFFOpen(inFilename, "r");
  if (tif == NULL){
    fprintf(stderr, "%s:%s: Error: File %s not found.\n", __FILE__, __FUNCTION__, inFilename);
    return NULL;
  }
  
  int width  = tif_Width(tif);
  int height = tif_Height(tif);
  int is3d = tif_Is3d(tif);
  int layers = tif_Layers(tif);
  int depth  = tif_BytesPerPixel(tif);          // bytes per pixel
  int iplDepth = convertDepthTiffToVgl(depth);  // depth \in {IPL_DEPTH_8U, ...}
  int nChannels = tif_nChannels(tif);           // number of channels

  if (is3d)
  {
    img = vglCreate3dImage(cvSize(width,height), iplDepth, nChannels, layers, 0);
  }
  else
  {
    img = vglCreateImage(cvSize(width,height), iplDepth, nChannels);
  }

  char* imageData = img->getImageData();
  int widthStep = img->getWidthStep();
  char* buffer = (char*) tif_Malloc(tif);

  int pixelsPerLine = img->getWidth()*img->getNChannels();
  int bytesPerLine = pixelsPerLine*depth;
  int i = 0;
  int offset = 0;
  do
  {
    /*
    for(int i = 0; i < height; i++)
    {
      printf("i = %d\n", i);
      TIFFReadScanline(tif, buffer, i);
      memcpy(imageData + offset, buffer, bytesPerLine);
      offset += widthStep;
    }
    */
    TIFFReadRGBAImage(tif, width, height, (uint32*) buffer, 0);
    memcpy(imageData + offset, buffer, widthStep*height);
    offset += widthStep + height;
  }
  while(TIFFReadDirectory(tif));

  TIFFClose(tif); 

  vglSetContext(img, VGL_RAM_CONTEXT);

  return img;
}
Пример #3
0
/** Function for loading TIFF images.

    Function for loading TIFF images. Supports RGB (8 bits) and 
grayscale (8 and 16 bits) images, 2D and 3D.

  */
VglImage* vglLoadTiff(char* inFilename)
{  
  TIFF* tif;
  VglImage* img;
  uint16 pageNumber, numberPages, subfileType;

  tif = TIFFOpen(inFilename, "r");
  if (tif == NULL){
    fprintf(stderr, "%s:%s: Error: File %s not found.\n", __FILE__, __FUNCTION__, inFilename);
    return NULL;
  }
  
  int width  = tif_Width(tif);
  int height = tif_Height(tif);
  int is3d = tif_Is3d(tif);
  int layers = tif_Layers(tif);
  int depth  = tif_BytesPerPixel(tif);          // bytes per pixel
  int iplDepth = convertDepthTiffToVgl(depth);  // depth \in {IPL_DEPTH_8U, ...}
  int nChannels = tif_nChannels(tif);           // number of channels

  if (is3d)
  {
    img = vglCreate3dImage(cvSize(width,height), iplDepth, nChannels, layers, 0);
  }
  else
  {
    img = vglCreateImage(cvSize(width,height), iplDepth, nChannels);
  }

  char* imageData = img->getImageData();

  int pixelsPerFrame = img->getWidth()*img->getHeight()*img->nChannels;
  int bytesPerFrame = pixelsPerFrame*depth;
  int j = 0;
  do{
    char* buffer = (char*)tif_ReadData(tif);
    memcpy(imageData+j, buffer, bytesPerFrame);
    j += bytesPerFrame;
  }while(TIFFReadDirectory(tif));

  TIFFClose(tif); 

  vglSetContext(img, VGL_RAM_CONTEXT);

  return img;
}
Пример #4
0
int main(int argc, char* argv[])
{
  if (argc != 4)
  {
    printf("\nUsage: MMDCPU_benchmark lena_1024.tiff 1000 /tmp\n\n");
    printf("In this example, will run the program for lena_1024.tiff in a \nloop with 1000 iterations. Output images will be stored in /tmp.\n\n");
    printf("Error: Bad number of arguments = %d. 3 arguments required.\n", argc - 1);
    exit(1);
  }
  //vglInit(50, 50);

  int nSteps = atoi(argv[2]);
  char* inFilename = argv[1];
  char* outPath = argv[3];
  char* outFilename = (char*)malloc(strlen(outPath) + 400);
  sprintf(outFilename, "%s%s", outPath, "/test_out.tif");

  printf("VisionGL-OpenCL on %s, %d operations\n\n", inFilename, nSteps);

  VglImage* img = vglLoadImage(inFilename, 0);
  if (img == NULL)
    img = vglDcmtkLoadDicom(inFilename);
  VglImage* out = vglCreateImage(img);
  float* mask;
  int* mask_size;
  if (img->ndim == 2)
  {
    mask = (float*)malloc(sizeof(float) * 9);
    float actual_mask[9] = { 0, 1, 0, 1, 1, 1, 0, 1, 0 };
    memcpy(mask, actual_mask, sizeof(float) * 9);

    mask_size = (int*)malloc(sizeof(int) * 2);
    int actual_mask_size[2] = { 3, 3 };
    memcpy(mask_size, actual_mask_size, sizeof(int) * 2);
  } 
  else
  {
    mask = (float*)malloc(sizeof(float) * 27);
    float actual_mask[27] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, };
    memcpy(mask, actual_mask, sizeof(float) * 27);

    mask_size = (int*)malloc(sizeof(int) * 3);
    int actual_mask_size[3] = { 3, 3, 3 };
    memcpy(mask_size, actual_mask_size, sizeof(int) * 3);
  }

  printf("Mask = { %d, %d, %d }\n", mask_size[0], mask_size[1], mask_size[2]);
  
  benchmark(img, out, mask, mask_size, nSteps, ERODE, "Standard Erode", outPath, &MMD_STANDARD);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "Standard Dilate", outPath, &MMD_STANDARD);

  benchmark(img, out, mask, mask_size, nSteps, ERODE, "Algebraic Erode", outPath, &MMD_ALGEBRAIC);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "Algebraic Dilate", outPath, &MMD_ALGEBRAIC);

  benchmark(img, out, mask, mask_size, nSteps, ERODE, "Arithmetic Erode", outPath, &MMD_ARITHMETIC);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "Arithmetic Dilate", outPath, &MMD_ARITHMETIC);

  benchmark(img, out, mask, mask_size, nSteps, ERODE, "Geometric Erode", outPath, &MMD_GEOMETRIC);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "Geometric Dilate", outPath, &MMD_GEOMETRIC);

  benchmark(img, out, mask, mask_size, nSteps, ERODE, "Bound Erode", outPath, &MMD_BOUND);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "Bound Dilate", outPath, &MMD_BOUND);

  benchmark(img, out, mask, mask_size, nSteps, ERODE, "Drastic Erode", outPath, &MMD_DRASTIC);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "Drastic Dilate", outPath, &MMD_DRASTIC);

  benchmark(img, out, mask, mask_size, nSteps, ERODE, "DaP Erode", outPath, &MMD_DaP);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "DaP Dilate", outPath, &MMD_DaP);

  benchmark(img, out, mask, mask_size, nSteps, ERODE, "Hamacher Erode", outPath, &MMD_HAMACHER);
  benchmark(img, out, mask, mask_size, nSteps, DILATE, "Hamacher Dilate", outPath, &MMD_HAMACHER);

  return 0;
}