user17304179
user17304179

Reputation:

how to open an image in imagej using python?

I want to automatically count cells and I usually do this with ImageJ

I can open imagej using subprocess

subprocess.Popen(r"path\ImageJ\ImageJ.exe")

I want to upload an image into imagej from python

Then run an imagej macro (edits image file and sets threshold) from python using this code:

subprocess.Popen(r"path\ij153-win-java8\ImageJ\macros\autocount.ijm")

How can I open an image in ImageJ through python? Full code:

#import libraries
import subprocess

#open imageJ
subprocess.Popen(r"path\ij153-win-java8\ImageJ\ImageJ.exe")

#open file in imageJ


#open imageJ macro
subprocess.Popen(r"path\ij153-win-java8\ImageJ\macros\autocount.ijm")

Upvotes: 0

Views: 750

Answers (1)

Aloohala
Aloohala

Reputation: 21

You can use Simple ITK to import the image and execute the image_viewer function.

https://simpleitk.readthedocs.io/en/v1.2.4/Examples/ImageViewing/Documentation.html

import SimpleITK as sitk

Image = sitk.ReadImage(inputImageFileName)
image_viewer = sitk.ImageViewer()
image_viewer.SetTitle('Cell Image') #title image (optional )
image_viewer.SetApplication(r'path\ij153-win-java8\ImageJ\ImageJ.exe') #Application to be used e.g. ImageJ or ITK-SNAP
image_viewer.SetFileExtension(".tiff") #any formats you use
image_viewer.Execute(Image)

Upvotes: 2

Related Questions