How to open OIR files through ImageJ in MATLAB?

37 views (last 30 days)
Etash
Etash on 23 Jan 2024
Commented: Etash on 24 Jan 2024
I seek to use MATLAB to help me batch process a folder of OIR files with ImageJ. Conventionally, these OIR files can open directly in ImageJ (by dragging and dropping).
To use MATLAB, I first 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 properly starts ImageJ. However, my code doesn't open my image when I say:
function results = ImageJ_Test
javaaddpath('/Applications/MATLAB_R2021b.app/java/ij146r.jar');
javaaddpath('/Applications/MATLAB_R2021b.app/java/mij.jar');
% Start MIJ (initialize ImageJ in MATLAB)
MIJ.start;
% Define the path to the folder containing the images
folderPath = '/Users/Documents/Test';
% Get a list of all image files in the folder
imageFiles = dir(fullfile(folderPath, '**', '*.oir')); % Since the images are OIR files
% Loop through each image file in the folder
for i = 1:numel(imageFiles)
% Construct the full file path for the current image
imagePath = fullfile(folderPath, imageFiles(i).name);
address = append('path=[',imagePath,']');
% Open the current image in ImageJ
MIJ.run('Open...', address);
The MIT.run('Open...', address) isn't properly opening the file, and it is instead opening as a jumble of letters and characters instead of a proper image. I was wondering whether there is something I can do to make ImageJ open my OIR file correctly as an image instead of characters.
Thank you so much!
  2 Comments
Walter Roberson
Walter Roberson on 23 Jan 2024
imagePath = fullfile(folderPath, imageFiles(i).name);
That should be
imagePath = fullfile(imageFiles(i).folder, imageFiles(i).name);
The current code would work only if all of the oir files are directly underneath the folderPath

Sign in to comment.

Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!