arrayfire / arrayfire-python

Python bindings for ArrayFire: A general purpose GPU library.

Home Page:https://arrayfire.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does af.regions work on 3D image input?

solarflarefx opened this issue · comments

From the documentation it appears as though the method is designed to work in 2D only:
`def regions(image, conn = CONNECTIVITY.FOUR, out_type = Dtype.f32):
"""
Find the connected components in the image.

Parameters
----------
image : af.Array
      - A 2 D arrayfire array representing an image.

conn : optional: af.CONNECTIVITY. default: af.CONNECTIVITY.FOUR.
      - Specifies the connectivity of the pixels.

out_type : optional: af.Dtype. default: af.Dtype.f32.
      - Specifies the type for the output.

Returns
---------

output : af.Array
       - An array where each pixel is labeled with its component number.

"""
output = Array()
safe_call(backend.get().af_regions(c_pointer(output.arr), image.arr,
                                   conn.value, out_type.value))
return output`

Yes that's right. Here's the assertion that limits the input to 2d (https://github.com/arrayfire/arrayfire/blob/4061db86e66306995175a14cf906c55c35373918/src/api/c/confidence_connected.cpp#L209)
If you mean to do multiple images, you'd have to do a for loop of each individual slice in a 3d array. Would a batch method be useful? Or did you want the connected components to work on 3d data?

@syurkevi I was actually looking to find connected components in a 3D volume structure. I got the sense that at least some of the other methods work on 3d structures but I want to make sure. Actually I came across this library after working with SimpleITK, which does work on 3D structures but I found the performance to be quite slow. Do you think ArrayFire could be a potentially suitable alternative if I am looking for something more performant?

OpenCV can be pretty performant for 2D image processing but lacks a more comprehensive 3D processing capability. SimpleITK has 3D capability but its libraries are written to be used more generally and are not so performant from my experience. I was hoping ArrayFire would be my solution.

We do have some support for 3d functions such as JIT functions, convolutions, FFT, however many of our computer vision and image processing functions focus on 2d and batch processing. Higher level indexing for implementing the kinds of operations you are interested should work from a functional perspective, but i think they may be better suited for a custom kernel (which can be done through our interop functions in the c++ backend) if performance is the critical consideration.