Exemplo n.º 1
0
/**Non-separable kernels are formatted as one might expect.  Separable kernels
 * show the two separable functions in a "+" pattern in the image.
 */
DImage DKernel2D::toDImage(){
  int w, h;
  DImage dst;
  double *pDst;

  w = 2*radiusX+1;
  h = 2*radiusY+1;

  dst.create(w, h, DImage::DImage_dbl_multi, 1);
  pDst = dst.dataPointer_dbl(0);

  if(!fSep){ // non-separable: just copy the data to the image
    memcpy(pDst, rgData_dbl, sizeof(double)*w*h);
  }
  else{ // separable: make a "+" with the two separable 1-d kernels
    memset(pDst, 0, sizeof(double)*w*h);
    for(int y = 0; y < h; ++y){
      pDst[y*w+w/2] = rgSep_dbl[w+y];
    }
    pDst += h/2*w;
    for(int x = 0; x < w; ++x){
      pDst[x] = rgSep_dbl[x];
    }
  }

  return dst;
}
Exemplo n.º 2
0
///Assignment from a DImage object (creates a kernel based on srcImg contents)
const DKernel2D& DKernel2D::operator=(const DImage &srcImg){
  int w, h;
  DImage imgDbl;
  double *pDataDbl;
  double *pDataDst;
  float *pDataFlt;

  if((0 == (srcImg.width() & 1)) || (0 == (srcImg.height() & 1))){
    fprintf(stderr, "DKernel2D::operator=() source image w,h must be odd\n");
    exit(1);
  }
  if(1 != srcImg.numChannels()){
    fprintf(stderr, "DKernel2D::operator=() source image numChannels != 1\n");
    exit(1);
  }
  if(srcImg.getImageType() == DImage::DImage_cmplx){
    fprintf(stderr, "DKernel2D::operator=() DImage_cmplx not supported\n");
    exit(1);
  }
  srcImg.convertedImgType_(imgDbl, DImage::DImage_dbl_multi, 1);
  pDataDbl = imgDbl.dataPointer_dbl();
  fSep = false;
  radiusX = srcImg.width() / 2;
  radiusY = srcImg.height() / 2;
  numSigsX = DEFAULT_NUM_SIGMAS;
  numSigsY = DEFAULT_NUM_SIGMAS;
  w = 2*radiusX+1;
  h = 2*radiusY+1;
  deleteBuffers();
  allocBuffers(w, h);
  pDataDst = rgData_dbl;
  pDataFlt = rgData_flt;
  
  for(int y = 0; y < h; ++y){
    memcpy(pDataDst, pDataDbl, sizeof(double) * w);
    for(int x = 0; x < w; ++x)
      pDataFlt[x] = (float)(pDataDst[x]);
    pDataDst += w;
    pDataDbl += w;
    pDataFlt += w;
  }

  return *this;
}