Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does af.regions work on 3D image input? #264

Open
solarflarefx opened this issue Nov 16, 2023 · 3 comments
Open

Does af.regions work on 3D image input? #264

solarflarefx opened this issue Nov 16, 2023 · 3 comments

Comments

@solarflarefx
Copy link

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`
@syurkevi
Copy link
Contributor

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?

@solarflarefx
Copy link
Author

@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.

@syurkevi
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants