Closing Java(?) windows opened by plugins from ImageJ macro

imagej

#1

Hi,

I wonder if there is a way to select and close windows that are opened by plugins and are not recognized by selectWindow command. For example when I use the Directionality (built-in) plugin it opens a histogram window and a table, that I want to close after extracting their output.

The following code does not work (using non relevant blobs image, but just for illustration):

run("Blobs (25K)");
run("Directionality", "method=[Local gradient orientation] nbins=90 histogram=-90");
selectWindow("Directionality for blobs (using Local gradient orientation)");
run("close");

and gives an error of:

No window with the title ""Directionality for blobs (using Local gradient orientation)" found

anyway to overcome this within a macro written in ImageJ macro language ?

Thanks
Ofra


#2

Dear @Ofra_Golani,

I fear that this is not possible with the macro language.

I have also tried with the following Groovy script to see if the windows get registered with the WindowManager:

import ij.IJ;
import ij.WindowManager;

IJ.run("Blobs (25K)");
IJ.run("Directionality", "method=[Local gradient orientation] nbins=90 histogram=-90");
println("Open windows: "+WindowManager.getWindowCount());

If you don’t have other windows open and run the script, it will return Open windows: 1. Since they are not registered with the WindowManager, I don’t now of a good way to close them…

Best,
Stefan


#3

Thanks @stelfrich !

I’ll try using another language

Ofra


#4

Directionality_ has a Java API that could be useful for you, depending on your use-case. If you can change how the plugin is actually called, you can can keep references to the JFrames and get rid of them:

import fiji.analyze.directionality.Directionality_

// Instantiate plugin
dir = Directionality_()

// Set fields and settings
dir.setImagePlus(WindowManager.getCurrentImage())
// dir.setMethod(Directionality_.AnalysisMethod.LOCAL_GRADIENT_ORIENTATION)
dir.setMethod(Directionality_.AnalysisMethod.FOURIER_COMPONENTS)
dir.setBinNumber(30)
dir.setBinStart(-60)
dir.setBuildOrientationMapFlag(True)

// Do calculation
dir.computeHistograms()
dir.fitHistograms()

// Display plot frame
plot_frame = dir.plotResults()
plot_frame.setVisible(True)

// Display fit analysis
data_frame = dir.displayFitAnalysis()
data_frame.setVisible(True) 

// Display results table
table = dir.displayResultsTable()
table.show("Directionality histograms")

// Display orientation map
stack = dir.getOrientationMap()
ImagePlus("Orientation map", stack).show()

// Generate a color wheel
Directionality_.generateColorWheel().show()

Best,
Stefan


#5

One workaround would be to postion the window and then close the window via the Java robot class available as an ImageJ plugin from @gabriel :

Here the plugin for download with a demo:

http://www.mecourse.com/landinig/software/ijrobot.zip

See also this older thread: