Understanding the inner workings of the radon function (from skimage)

Kaloyan Marinov kaloyan.at.uw at gmail.com
Mon Apr 14 08:17:47 EDT 2014


Dear Guillaume and Juan,

Thank you both for your comments, they've been very helpful.

Best regards,
Kaloyan

On Saturday, April 12, 2014 10:24:01 AM UTC+3, Guillaume wrote:
>
>  Juan, this was enlightening...
>
> G.
> Le 12/04/2014 04:57, Juan Nunez-Iglesias a écrit :
>  
> Hey Guillaume, Kaloyan, 
>
>
> On Fri, Apr 11, 2014 at 9:53 PM, Guillaume Gay <
> guil... at mitotic-machine.org <javascript:>> wrote: 
>>
>>   
>>    
>>   The docstring is incorrect, and you can see that in _wrap_fast:
>>  
>> ```python
>> cdef double[:, ::1] M = np.ascontiguousarray(H)
>> ```
>>
>> meaning that the array passed to the loop will be read as a 'flat' array.
>>  
>
>  No, flat is referred to as flat. =) Contiguous just means that the 
> contents of the array are contiguous in memory, but the comma inside the [] 
> brackets means that M has two dimensions. However, because they are 
> contiguous, the actual data is laid out in one contiguous block of memory 
> of size 9 times the dtype of the array. Notice that it's not M that is 
> passed to the _matrix_transform function, but &M[0, 0], that is, the memory 
> address of the first element of the array. Because the memory is guaranteed 
> to be contiguous, you can access those elements using pointer arithmetic. 
> So, in _matrix_transform, H[3] actually points to M[1, 0], H[5] points to 
> M[1, 2], and so on.
>
>   I guess the comment should read something like `contiguous array from 
>> an array of shape (3,3)`
>>
>
>  Yeah, that's certainly true. The docstring for _matrix_transform itself 
> is confusing and your suggestion is a good one. Wanna submit a PR? ;)
>
>>   
>>    
>>   My guess is `&M[0, 0]` is the pointer to the (flat) matrix M
>>
>
>  Yes, as detailed above. Cython is a mixture of Python and C so you have 
> to draw on the syntax of both.  
>
>>   
>>    - last but not least, the type of img is defined to cnp.ndarray, and 
>>    then one converts it to a contiguous array; what is the purpose/advantage 
>>    of doing this conversion?
>>     
>>   My guess: it's more efficient, and less cumbersome (1D arrays are 
>> easier to understand from a C point of view)
>>
>
>  Pretty close. As mentioned above, contiguous is not the same as flat. 
> Contiguous arrays are more efficient and easier to deal with (no need to 
> think about memory strides). Flat arrays are *sometimes* easier to deal 
> with. That depends on the context.
>
>>   
>>    - I do have a _warps_cy.so on my harddrive, but I don't know what 
>>    application it can be opened it; could you let me know about that?
>>     
>>   This is a shared object (akin to a DLL in windows) so it's binary, 
>> compiled from C code generated by cython from the .pyx file, you have no 
>> reason to open it.
>>
>
>  Also correct — you also have _warps_cy.pyx, right?
>
>  Hope this all helps!
>
>  Juan.
>   -- 
> You received this message because you are subscribed to the Google Groups 
> "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to scikit-image... at googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20140414/39bd06be/attachment.html>


More information about the scikit-image mailing list