Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:36:03+00:00 2026-05-29T05:36:03+00:00

From Mathematica, I wish to pass an image to an ImageJ plugin and get

  • 0

From Mathematica, I wish to pass an image to an ImageJ plugin and get the result sent from ImageJ to Mathematica.

JLink is the tool that will help, but I am familiar neither with it nor with ImageJ (making it hard to leverage existing related questions on SO). Would you know how to do that?

(I have installed ImageJ on my mac already.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:36:04+00:00Added an answer on May 29, 2026 at 5:36 am

    This should only serve as teaser to show you, that this is not as hard as it seems. There is no way around, that you have to be familiar with Java, the ImageJ-API, and yes, JLink.

    So here is how you get started: You need the ImageJ java archive ij.jar which you can download from the ImageJ Website. This jar contains all classes and functions ImageJ is using by itself.

    What you want to do is to create an image not by opening it through the ImageJ-GUI but by using Java-methods. For this you have to get familiar with the ImageJ-API to know how you can create an image from e.g. an array of numbers, because that’s how we want to transfer the Mathematica-images to Java.
    Skimming through this documentation brought me to the ImageProcessor classes. As you can see they provide two methods: setPixels and getPixels and both accept simple arrays. Let’s use this and write a very basic filter:

    import ij.process.FloatProcessor;
    
    public class SimpleTest {
    
        public static float[] func(float []bm, int nx, int ny) {
            FloatProcessor p = new FloatProcessor(nx,ny);
            p.setPixels(bm);
            float[] kernel = new float[{0.111f,0.111f,0.111f,0.111f,
                                        0.111f,0.111f,0.111f,0.111f,0.111f};
            p.convolve(kernel, 3, 3);
            return (float[]) p.getPixels();
        }
    }
    

    This function gets the image-data and the image-dimensions, does a convolution and returns the filtered image-data. To compile this, remember that ij.process.FloatProcessor is inside the ij.jar. You have to include this archive in your classpath. Later, you have to ensure that JLink finds both, the ij.jar and your SimpleTest.class. I usually pack my classes inside a jar too. For this I called it simple.jar.

    While the java-side is now ready to rock, we need a few lines to extract image-data and dimensions from a Mathematica-image

    img = ColorConvert[ExampleData[{"TestImage", "Lena"}], "Grayscale"];
    {nx, ny} = ImageDimensions[img];
    data = ImageData[img] // Flatten;
    

    What we do now is sending the flat integer array data to our Java-function, taking the result and building the output-image. To make Mathematica find your jar-archives, one way is to call AppendToClassPath:

    Needs["JLink`"]
    AddToClassPath["/pathTo/ij.jar","pathTo/simple.jar"];
    
    simpleTest = LoadJavaClass["SimpleTest", StaticsVisible -> True];
    output = SimpleTest`func[data, nx, ny];
    Image[Partition[output, nx]]
    

    With this last step we complete the cycle and get our final result.

    Final notes:

    • You should maybe (and this means “do it”) use the same java-version JLink is using for the compilation of your code.
    • There are already plugins in the ij.jar. This will not include all available stuff. But remember: The ImageJ-GUI just calls methods from ij.jar to use auxiliary plugins, so you can do the same with your code.
    • Some plugins use native (JNI) code which may lead to unexpected errors, when you use this from within Mathematica
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In how-do-i-access-the-stackoverflow-api-from-mathematica I outlined how one could use the SO API to get Mathematica
Given a list of numbers in Mathematica, how would I extract from that list
I came across an old problem that you Mathematica/StackOverflow folks will probably like and
I wish to plot a vector with the help of ListLinePlot function in mathematica.
My work requires that I perform a mathematical simulation whose parameters come from a
From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread.
How do I make a Mathematica graph from edges with named vertices? EG: http://pastebin.com/Se1Nhe3M
Is there an easy way to extract data from specific HTML tables using Mathematica?
The mathematica.SE is currently in private beta and will open to the public in
Is it possible to use Mathematica's computing capabilities from other languages? I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.