/******************************************************* * Copyright (c) 2014, ArrayFire * All rights reserved. * * This file is distributed under 3-clause BSD license. * The complete license agreement can be obtained at: * http://arrayfire.com/licenses/BSD-3-Clause ********************************************************/ #include #include #include #include #include #include #include using af::dim4; using namespace detail; template static inline af_array morph(const af_array &in, const af_array &mask) { const Array &input = getArray(in); const Array &filter = getArray(mask); Array out = morph(input, filter); return getHandle(out); } template static inline af_array morph3d(const af_array &in, const af_array &mask) { const Array &input = getArray(in); const Array &filter = getArray(mask); Array out = morph3d(input, filter); return getHandle(out); } template static af_err morph(af_array *out, const af_array &in, const af_array &mask) { try { ArrayInfo info = getInfo(in); ArrayInfo mInfo= getInfo(mask); af::dim4 dims = info.dims(); af::dim4 mdims = mInfo.dims(); dim_type in_ndims = dims.ndims(); dim_type mask_ndims = mdims.ndims(); DIM_ASSERT(1, (in_ndims <= 3 && in_ndims >= 2)); DIM_ASSERT(2, (mask_ndims == 2)); af_array output; af_dtype type = info.getType(); switch(type) { case f32: output = morph(in, mask); break; case f64: output = morph(in, mask); break; case b8 : output = morph(in, mask); break; case s32: output = morph(in, mask); break; case u32: output = morph(in, mask); break; case u8 : output = morph(in, mask); break; default : TYPE_ERROR(1, type); } std::swap(*out, output); } CATCHALL; return AF_SUCCESS; } template static af_err morph3d(af_array *out, const af_array &in, const af_array &mask) { try { ArrayInfo info = getInfo(in); ArrayInfo mInfo= getInfo(mask); af::dim4 dims = info.dims(); af::dim4 mdims = mInfo.dims(); dim_type in_ndims = dims.ndims(); dim_type mask_ndims = mdims.ndims(); DIM_ASSERT(1, (in_ndims == 3)); DIM_ASSERT(2, (mask_ndims == 3)); af_array output; af_dtype type = info.getType(); switch(type) { case f32: output = morph3d(in, mask); break; case f64: output = morph3d(in, mask); break; case b8 : output = morph3d(in, mask); break; case s32: output = morph3d(in, mask); break; case u32: output = morph3d(in, mask); break; case u8 : output = morph3d(in, mask); break; default : TYPE_ERROR(1, type); } std::swap(*out, output); } CATCHALL; return AF_SUCCESS; } af_err af_dilate(af_array *out, const af_array in, const af_array mask) { return morph(out,in,mask); } af_err af_erode(af_array *out, const af_array in, const af_array mask) { return morph(out,in,mask); } af_err af_dilate3d(af_array *out, const af_array in, const af_array mask) { return morph3d(out,in,mask); } af_err af_erode3d(af_array *out, const af_array in, const af_array mask) { return morph3d(out,in,mask); }