Running ImageJ Macro commands in MATLAB

74 Ansichten (letzte 30 Tage)
Etash
Etash am 24 Jan. 2024
Bearbeitet: Walter Roberson am 5 Feb. 2024
Hello!
I am trying to use MATLAB to batch-process a series of TIFF images using ImageJ. I started put the mij.jar and ij.jar (ImageJ) into the java directory of MATLAB, and I subsequently added them to the classpath.
The command "MIJ.start;" and "IJ.run('Open...', ['path=' imagePath ]);" properly start ImageJ and open my image (since imagePath represents the correct file location of my TIFF file).
However, I now want to split the image channels to do an analysis on each of the channels using a for-loop. To split the channels, I used the coommands:
% OPEN CURRENT IMAGE IN ImageJ
imp = IJ.openImage(imagePath);
IJ.run('Open...', ['path=' imagePath ]);
% SPLIT CHANNELS
MIJ.run('Split Channels');
% Get the number of channels in the current image --> to eventually use for a for-loop
numChannels = imp.getNChannels();
Yet, I am running into a problem, as ImageJ is not able to recognize the Macro command, and I get an error saying "Unrecognized command: Split Channels". I was wondering what may be causing this problem, and how I can individually analyze different channels.
Thank you!

Antworten (2)

Pratyush Swain
Pratyush Swain am 1 Feb. 2024
Hi Etash,
I understand you are facing difficulty in running ImageJ commands in MATLAB. I carried out the following installation process for setting up ImageJ-MATLAB Integration.
1- Download and Install ImageJ(Fiji)
Fiji is a distribution of ImageJ that includes many useful plugins. Download it from the Fiji downloads page.
2- Integrating ImageJ with MATLAB
  • Obtain Fiji app folder by extracting the downloaded package.
  • Go to Fiji.app folder and find the application file there.
  • Open the application and install updates.
  • Click on "Manage update sites".
  • Scroll down the list and check the box next to "ImageJ-MATLAB".
  • Close the "Manage update sites" window.
  • Click "Apply changes" in the updater window.
3-Using ImageJ with MATLAB
Once the ImageJ-MATLAB update is installed, you can use the "ij.IJ" and "ij.WindowManager" classes directly in MATLAB.Here's how you can modify the implementation to work with the updated integration.
% Starting ImageJ %
MIJ.start;
% Replace with path to your file
imagePath = 'image.tiff' ;
% Open the image in ImageJ
ij.IJ.open(imagePath);
% Split the channels in ImageJ
MIJ.run('Split Channels');
% Alternatively this can be followed to split channels
% ij.IJ.run('Split Channels');
% Leveraging WindowManger class to get the number of channels in the current image
imp = ij.WindowManager.getCurrentImage();
numChannels = imp.getNChannels();
% Display number of channels in the image
disp(numChannels)
You can also follow this documentation for running ImageJ within MATLAB: https://www.mathworks.com/matlabcentral/fileexchange/47545-mij-running-imagej-and-fiji-within-matlab
Hope this helps.

Vignesh
Vignesh am 5 Feb. 2024
Bearbeitet: Vignesh am 5 Feb. 2024
If you are open to using features in MATLAB, consider imsplit to split image channels and imageBatchProcessor to batch processing images. The imageBatchProcessor allows you to specify a function which you want to apply to a batch of images https://www.mathworks.com/help/images/batch-processing-using-the-image-batch-processor-app.html
I = imread("board.tif");
[r,g,b] = imsplit(I);
Open the imageBatchProcessor UI and specify a batch processing function. If you prefer command line, you can use the app to generate MATLAB code that the app used to process your files, on the app toolstrip, click Export and select Generate function.
imageBatchProcessor

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by