Posted by
moxed on
Apr 04, 2018; 8:42pm
URL: http://imagej.273.s1.nabble.com/Trouble-with-active-windows-within-a-loop-tp5020382.html
Scripting newbie here, having trouble calling windows to the front in a for
loop. As a brief example, I'm trying to write a script (jython) that will
loop through an array of images and convert them to 8-bit and also set a
particular threshold.
I can't seem to get the convert to 8bit command to work on all images in the
array. It looks like only the last image is acted upon.
I think I need to be able to call an image to the front, using the image
title or ID, but I can't figure out how to do that. Any advice would be
great.
(In my real code there are a number of more manipulations, and also more
than 2 files being processed)
import os
from java.io import File
from ij import IJ, Macro, ImagePlus, WindowManager
from ij.process import ImageStatistics as IS, ImageProcessor
from ij.measure import Measurements
from ij.process import ImageConverter
wt_path = "C:/wt.tif"
dic_path = "C:/dic.tif"
wt = IJ.openImage(wt_path)
dic = IJ.openImage(dic_path)
imp = [wt, dic]
for img in imp:
IJ.getImage()
IJ.run("8-bit")
if img == dic:
maxThreshold = wt.getStatistics(Measurements.MIN_MAX).max
IJ.setThreshold(0.50*maxThreshold, maxThreshold)
print img, "mxt=", maxThreshold
else:
maxThreshold = img.getStatistics(Measurements.MIN_MAX).max
IJ.setThreshold(0.20*maxThreshold, maxThreshold)
print img, "mxt=", maxThreshold
print end
The threshold function works perfect, but I can't for the life of me get the
8 bit to run. Only the last image in the array `dic` is converted.
I've also tried:
for img in imp:
ImageConverter.convertToGray8(img)
But that throws an error:
> TypeError: convertToGray8(): self arg can't be coerced to
> ij.process.ImageConverter
I can't figure out how to call a specific image either by window title or by
image ID.
--
Sent from:
http://imagej.1557.x6.nabble.com/--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html