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

addPairwiseBilateral for densecrf2d in densecrf.pyx file #59

Closed
ranok92 opened this issue Mar 31, 2018 · 4 comments
Closed

addPairwiseBilateral for densecrf2d in densecrf.pyx file #59

ranok92 opened this issue Mar 31, 2018 · 4 comments

Comments

@ranok92
Copy link

ranok92 commented Mar 31, 2018

Hey, I was going through the original cpp code for the addPairwiseBilateral for denseCRF2D and there the array they pass, im, seem to be of the dimension [(w_*h_*3), 1], but in the .pyx file it checks for the size of the im array to be of [w_ , h_ , 3]. Can someone please explain to me this part? Sorry, I am kind of new to this. So, having an issue understanding how the stuff actually works.

Thanks,

@lucasb-eyer
Copy link
Owner

In C, array's don't have any shape, they are just a contiguous "line" of memory. What is important is that the access to that buffer are consistent on both the NumPy and the C side. In this case, they are, since the C code is accessing the memory as [(y*W+x)*3+c], which is consistent with the memory layout NumPy gives to a [H,W,C] C-contiguous array. Note that you have a typo in your question, the .pyx file checks for the rgbim array to be of [h_, w_, 3], not [w_, h_, 3]. This distinction is important.

If you want to learn more, I recommend you read about memory layout, especially this part of the NumPy documentation. And maybe the NumPy ndarray paper helps, too.

I'm closing the issue as you're not reporting a bug, but feel free to ask more and, if you do find a bug, re-open the issue.

@ranok92
Copy link
Author

ranok92 commented Mar 31, 2018 via email

@lucasb-eyer
Copy link
Owner

Both of these are explained in the Cython User Guide, chapter about Typed Memoryviews, you should read that if you're interested.

Briefly, the first one means it's a 3D array that is C-contiguous in layout; if a non-C-contiguous array is passed, it will raise an exception.

The second one, &rgbim[0,0,0] (you forgot the & which is important) is a pointer to the start of the buffer.

@ranok92
Copy link
Author

ranok92 commented Apr 1, 2018 via email

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