示例#1
0
void dt2d_binary(float *data, long int * label, const long int *sz, unsigned char tag) 
{
  long int i,j;
  float * ptr;
  long int tmp_j;
	
  for (j = 0; j < sz[1]; j++)
    {
      tmp_j = j*sz[0];
		
      for (i = 0; i < sz[0]; i++)
	{
	  ptr = data + tmp_j + i;
			
	  if (tag ==0) {
	    if ( *ptr > 0 )
	      *ptr = 0;
	    else
	      *ptr = FLOAT_INF;
          } else {
	    if ( *ptr > 0 )
	      *ptr = FLOAT_INF;
	    else
	      *ptr = 0;
          }
				
	}
    }
  dt2d(data, label, sz);
	
}
示例#2
0
文件: C_gdt.c 项目: hosang/gdt
static PyObject *gdt(PyObject *self, PyObject *args) {
    PyArrayObject *mat;
    if (!PyArg_ParseTuple(args, "O!", &PyArray_Type, &mat))
        return NULL;

    if (mat == NULL) return NULL;
    if (not_floatmatrix(mat)) return NULL;
    int d = mat->dimensions[0];
    int n = mat->dimensions[1];
    int m = mat->dimensions[2];
    float *cout = (float *) mat->data;
    dt2d(cout, d, n, m);
    Py_INCREF(Py_None);
    return Py_None;
}
/* dt of binary image using squared distance */
FIBITMAP *DLL_CALLCONV
FIA_DistanceTransform (FIBITMAP * src)
{
    int width = FreeImage_GetWidth (src);
    int height = FreeImage_GetHeight (src);
    float *out_ptr;
    unsigned char *src_ptr;

    FIBITMAP *out = FIA_ConvertToGreyscaleFloatType (src, FIT_FLOAT);

    for(register int y = 0; y < height; y++)
    {
        src_ptr = (unsigned char *) FreeImage_GetScanLine (src, y);
        out_ptr = (float *) FreeImage_GetScanLine (out, y);

        for(register int x = 0; x < width; x++)
        {

            if (src_ptr[x] == 0)
            {
                out_ptr[x] = 0.0f;
            }
            else
            {
                out_ptr[x] = INF;
            }
        }
    }

    dt2d (out);

    // take square roots
    for(register int y = 0; y < height; y++)
    {
        out_ptr = (float *) FreeImage_GetScanLine (out, y);

        for(register int x = 0; x < width; x++)
        {
            out_ptr[x] = sqrt (out_ptr[x]);
        }
    }

    FIBITMAP *ret = FreeImage_ConvertToStandardType (out, 1);

    FreeImage_Unload (out);

    return ret;
}