Re: Gamma correction slider?
Posted by dscho on Dec 18, 2009; 5:23pm
URL: http://imagej.273.s1.nabble.com/Gamma-correction-slider-tp3689970p3689973.html
Hi Leonard,
On Fri, 18 Dec 2009, Leonard Sitongia wrote:
> I see a few postings about this subject in the archive, but didn't see a
> reply or resolution. People around here like the gamma slider on IDL's
> xloadct GUI and I'd like to be able to provide a way of doing this in
> ImageJ as a substitute for IDL. I found a plug-in which creates a black
> and white LUT with a gamma control (I like how it presents the control
> as a dynamic gamma correction plot) but a slider would be most familiar
> to people.
>
> Is there already a solution for this?
The easiest I can think of is this little Javascript I wrote in response
to your question:
-- snip --
importClass(Packages.ij.WindowManager)
importClass(Packages.ij.gui.GenericDialog)
importClass(Packages.ij.process.ImageProcessor)
importClass(Packages.java.awt.event.AdjustmentListener)
var image = WindowManager.getCurrentImage();
if (image != null) {
var ip = image.getProcessor();
ip.snapshot();
var dialog = GenericDialog("Gamma (1.0)");
dialog.addSlider("gamma", 1, 500, 100);
dialog.getNumericFields().lastElement().setVisible(false);
var scrollbar = dialog.getSliders().lastElement();
dialog.add(scrollbar);
var listener = new AdjustmentListener ({
adjustmentValueChanged : function(event) {
var value = scrollbar.getValue() / 100.0;
dialog.setTitle("Gamma (" + value + ")");
ip.reset();
ip.snapshot();
ip.gamma(value);
image.updateAndDraw();
}
});
scrollbar.addAdjustmentListener(listener);
dialog.showDialog();
if (dialog.wasCanceled()) {
ip.reset();
image.updateAndDraw();
}
}
-- snap --
In ImageJ, you can copy-paste this into the window you get after
Plugins>New>JavaScript. In Fiji, you can paste it into the script editor
(File>New>Script, then Language>Javascript), you will even get syntax
highlighting with that.
Ciao,
Johannes