Untitled
unknown
plain_text
a year ago
2.0 kB
3
Indexable
import imagej
from pathlib import Path
from PIL import Image
import scyjava
import logging
# Enable debug logging for scyjava
logging.basicConfig(level=logging.DEBUG)
# Ensure JVM is started
scyjava.start_jvm()
# Attempt to import the Java class
try:
Accesses = scyjava.jimport("net.imglib2.img.basictypeaccess.Accesses")
print("Successfully imported Accesses class")
except Exception as e:
print("Error importing Accesses class:", e)
def load_leica_image_to_imagej(imagej, image_path):
# Load image into ImageJ
imagej.ui().show(image_path)
imagej.ui().waitForUI()
imagej.ui().getWindow().pack()
imagej.ui().getWindow().toFront()
def export_image_sequence(imagej, output_folder, image_name_prefix):
# Iterate through all open images in ImageJ
for idx, image_id in enumerate(imagej.ui().getImageIDs()):
# Activate each image
imagej.ui().getImagePlus().setID(image_id)
imagej.ui().getImagePlus().setSlice(1)
# Get image data
image_title = imagej.ui().getImagePlus().getTitle()
img = imagej.ui().getImagePlus().getProcessor().getBufferedImage()
# Save as JPEG with specified naming convention
output_filename = f"{image_name_prefix}_{idx+1:05d}.jpg"
output_path = output_folder / output_filename
img_rgb = Image.fromarray(img)
img_rgb.save(output_path)
print(f"Saved {output_filename}")
def main():
# Initialize ImageJ
ij = imagej.init('net.imagej:imagej-legacy:0.37.1')
# Path to the Leica image file
leica_image_path = '/Volumes/Elements/WO153_pep22_16p25_240607.lif'
# Load Leica image into ImageJ
load_leica_image_to_imagej(ij, leica_image_path)
# Export images as JPEG sequence
output_folder = Path('/Volumes/Elements/results')
image_name_prefix = 'WO153_pep22_16p25_240607'
export_image_sequence(ij, output_folder, image_name_prefix)
if __name__ == "__main__":
main()
Editor is loading...
Leave a Comment