4
$\begingroup$

I have created a specialized image analysis method in Mathematica that takes an image and returns a marked up image with some detection output. In order to allow others to feed images into my analysis from arbitrary sources (databases, file systems, web interfaces, scanners, etc), I would like to wrap in a .NET application (preferably C#).

Is there any way to pass an image object from .NET into MathKernel via NETLink and handle it as an Image in the kernel? I have found examples of how to get images out of MathKernel, but not the other direction.

I could write the image to a temporary file, but that seems sloppy.

$\endgroup$
  • 1
    $\begingroup$ In general you could pass data through a socket. Check SocketListen $\endgroup$ – Fortsaint Oct 2 '19 at 18:39
  • 1
    $\begingroup$ Perhaps pass as base 64 string e.g. mathematica.stackexchange.com/a/27956/363 $\endgroup$ – Chris Degnen Oct 2 '19 at 21:50
  • 1
    $\begingroup$ In the J/Link implementation they use a PutByteArray(...) of the image data, presumably NETLink supplies a similar hook to MLPutByteArray? That will be fast and presumably pretty simple. Use PutType("Image", 1) or whatever the correct call is (can't remember) to wrap the data in Image first or whatever. I did this for my implementation of J/Link for python and remember it being pretty simple along those lines. $\endgroup$ – b3m2a1 Oct 10 '19 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.