J-Win
J-Win

Reputation: 1492

How to view the source code of a .mex file

I saw online that you can just use edit rgb2gray to open up the source file, but I ran into another function in the rgb2gray.m file that I don't know how to view.

Lines 54-55 contain the following function:

if threeD
  I = images.internal.rgb2graymex(X);

How do I view the source code for this rgb2graymex function?

Upvotes: 1

Views: 2732

Answers (2)

Sam Roberts
Sam Roberts

Reputation: 24127

In general you can't see the contents of a .mex file, as @Adriaan indicates in his answer.

You mention in the comments, though, that what you really want is to find the coefficients used from the transform matrix for converting RGB to grayscale. You can find these in the code immediately below the section you quote:

  T    = inv([1.0 0.956 0.621; 1.0 -0.272 -0.647; 1.0 -1.106 1.703]);
  coef = T(1,:);

That gives me:

coef =
   0.298936021293775   0.587043074451121   0.114020904255103

Now it's true that you can't demonstrate conclusively that the .mex file is doing the same thing as this; but the .mex file is just there to speed things up when you pass in a big mxnx3 RGB image, rather than a small nx3 RGB colormap. I'd be very surprised if it was using different coefficients. A few experiments that I've just done indicate only the tiniest of numerical differences (<1e-15) between the .mex file and using the coefficients present in the code.

Upvotes: 1

Adriaan
Adriaan

Reputation: 18177

rgb2graymex is, as its name suggests, a .mex file. .mex files are pre-compiled files which you thus cannot view the contents of, unless you use exotic decompilers (which usually don't give a 100% result), or obtain the source code from the one who's written it, which is not going to happen with proprietary code.

Read more on MEX files on the MathWorks site.

Upvotes: 4

Related Questions