Exemple #1
0
// FloatMatrix returns an Image in the GRAY colorspace as FloatMatrix,
// where each pixel represents an element of the matrix. Each element
// is normalized to the [0,1] range.
func (im *Image) FloatMatrix() (FloatMatrix, error) {
	if im.Colorspace() != GRAY {
		return nil, fmt.Errorf("FloatMatrix() is available only for GRAY images, this one is in %s", im.Colorspace())
	}
	width := im.Width()
	height := im.Height()
	ptrs := make([]*C.double, width)
	for ii := range ptrs {
		ptrs[ii] = allocDoublePtr(height)
	}
	defer func() {
		for _, p := range ptrs {
			freeDoublePtr(p)
		}
	}()
	var ex C.ExceptionInfo
	C.GetExceptionInfo(&ex)
	defer C.DestroyExceptionInfo(&ex)
	C.image_matrix(im.image, (**C.double)(unsafe.Pointer(&ptrs[0])), &ex)
	if ex.severity != C.UndefinedException {
		return nil, exError(&ex, "generating float matrix")
	}
	m := make([][]float64, width)
	for ii := range m {
		m[ii] = doublePtrToFloat64Slice(ptrs[ii], height)
	}
	return FloatMatrix(m), nil
}
Exemple #2
0
// FloatMatrix returns an Image in the GRAY colorspace as FloatMatrix,
// where each pixel represents an element of the matrix. Each element
// is normalized to the [0,1] range.
func (im *Image) FloatMatrix() (FloatMatrix, error) {
	if im.Colorspace() != GRAY {
		return nil, fmt.Errorf("FloatMatrix() is available only for GRAY images, this one is in %s", im.Colorspace())
	}
	width := im.Width()
	height := im.Height()
	m := make([][]float64, width)
	ptrs := make([]unsafe.Pointer, width)
	for ii := range m {
		col := make([]float64, height)
		m[ii] = col
		ptrs[ii] = unsafe.Pointer(&col[0])
	}
	var ex C.ExceptionInfo
	C.GetExceptionInfo(&ex)
	defer C.DestroyExceptionInfo(&ex)
	C.image_matrix(im.image, (**C.double)(unsafe.Pointer(&ptrs[0])), &ex)
	if ex.severity != C.UndefinedException {
		return nil, exError(&ex, "generating float matrix")
	}
	return FloatMatrix(m), nil
}