Thursday, March 31, 2011

Matlab liked my idea

Matlab is one of the most frequently used programming languages for science and engineering.

Though I can't verify it, it seems that Matlab has incorporated one of my ideas into its standard distribution.

Back in 2006, I was working on reconstruction algorithms for computed tomography (CT). Here is a video I made that demonstrates CT reconstruction. It takes the radon transform (at the bottom) and constructs the image slice (top).


I found Matlab's code slow, so I replaced the time-consuming part of their code with a faster version that I wrote. It was faster because I precompiled it using mex... nerd detail. I submitted my code to their File Exchange service so other people could benefit from it.

Anyhooo, in preparing my lecture on CT reconstruction today, I was suprised to see that Matlab's code was now faster than mine. WTF?!

I looked at their code, and saw that they had replaced the exact same part with mex code, just like I did.

Here is what a snippet of their original (slow) code looked like.


I replace it with the following code that calls the program I wrote (LinearBackproject).


And now this is what their new code looks like.


They even used my 0/1 flag (the last argument) to indicate to the iradonmex subroutine whether to use nearest-neighbour or linear interpolation.

Even if Matlab did use my code directly, I have no financial recourse. But it feels nice to be appreciated.

5 comments:

  1. Jeff Orchard,

    I have a question. In the original (slow) code there is a confused step -> "proj(t+ctrIdx)".

    If 't' is a matrix, why you can do proj(t+ctrIdx)?

    ReplyDelete
  2. t is a vector of indices (ctrIdx is a scalar, presumably the index offset for the centre). Matlab allows you to extract multiple array elements by specifying an array of indices (I think it might work only for 1D indexing).

    So, if
    proj = [10 11 12 13 14]
    then proj([2 3 5]) will return [11 12 14].

    ReplyDelete