I am hoping to make a modified version of HyperStackReducer, a plugin
that is bundled with and installed in the current version of ImagJ. When I find the source code at http://rsb.info.nih.gov/ij/docs/source/ij/plugin/HyperStackReducer.java.html and copy the code and save it in a file called HyperStackReducer.java, I get no errors, but nothing happens. Running the same plugin from the Image>Hyperstacks>Reduce Dimensionality... menu, however, it works exactly as expected from the code. The opening lines of the plugin are: package ij.plugin; import ij.*; import ij.gui.*; import ij.process.*; import ij.measure.Calibration; import java.awt.*; import java.util.Vector; /** Implements the Image/HyperStacks/Reduce Dimensionality command. */ public class HyperStackReducer implements PlugIn, DialogListener { ImagePlus imp; int channels1, slices1, frames1; int channels2, slices2, frames2; double imageSize; static boolean keep = true; /** Default constructor */ public HyperStackReducer() { } /** Constructs a HyperStackReducer using the specified source image. */ public HyperStackReducer(ImagePlus imp) { this.imp = imp; } public void run(String arg) { imp = IJ.getImage(); if (!(imp.isHyperStack() || imp.isComposite())) { IJ.error("Reducer", "HyperStack required"); return; } int width = imp.getWidth(); . . . I have tried a few variations to the code including public void run(String arg) { imp = ij.WindowManager.getCurrentImage(); ... but get the same result. It seems that the plugin is not even executing, because running it from the installed menu command gives an error if there is no image open or if the current image is not of the correct type. My efforts with "Compile and Run..." don't even give the errors in such situations. Am I un aware or forgetting some magic that's needed to get a plugin to execute on the current image? I am still quite new to java code, but I can't find what I'm missing. Are the constructors the problem? Thanks for any help! Bill -- William A. Mohler Associate Professor Dept. of Genetics and Developmental Biology University of Connecticut Health Center MC-3301 263 Farmington Ave. Farmington, CT 06030-3301 [hidden email] Mobile: (860) 985-2719 alt. mobile: (860) 331-8514 skype: wmohler Office: (860) 679-1833, room E2029 Lab: (860) 679-1834, room E2032 Fax: (314) 689-1833 G&DB dept. ofc.: (860) 679-8350 G&DB dept. fax : (860) 679-8345 http://genetics.uchc.edu/Faculty/Mohler/Mohler.html P Think before you print |
Bill,
The PlugIn needs an underscore in the class name to be recognized as a PlugIn intended as an ImageJ menu command. So instead of HyperStackReducer, call it HyperStack_Reducer in a HyperStack_Reducer.java file. Otherwise it won't appear on the menus ever after compilation (nor it will be run, I think, from what you describe.) Albert -- Albert Cardona http://albert.rierol.net |
Thanks, Albert. But this doesn't seem to be a problem of being
installed. I can't even get the plugin to run when I select it from "Compile and Run..." or when I choose "Compile and Run" from the File menu of a text window in ImageJ. The class file compiles just fine (no errors or warnings), but nothing runs. I don't thing it's the underscore issue (I know I need that for to class to appear in the Plugins menu). Am I still missing something obvious? Bill >Bill, > >The PlugIn needs an underscore in the class name to be recognized as >a PlugIn intended as an ImageJ menu command. > >So instead of HyperStackReducer, call it HyperStack_Reducer in a >HyperStack_Reducer.java file. > >Otherwise it won't appear on the menus ever after compilation (nor >it will be run, I think, from what you describe.) > >Albert > >-- >Albert Cardona >http://albert.rierol.net |
In reply to this post by Bill Mohler
The first line in the plugin ("package ij.plugin;") needs to be
replaced with "import ij.plugin.*;". -wayne On Apr 6, 2009, at 4:57 PM, Bill Mohler wrote: > I am hoping to make a modified version of HyperStackReducer, a plugin > that is bundled with and installed in the current version of ImagJ. > > When I find the source code at > http://rsb.info.nih.gov/ij/docs/source/ij/plugin/ > HyperStackReducer.java.html and copy the code and save it in a file > called HyperStackReducer.java, > I get no errors, but nothing happens. > > Running the same plugin from the Image>Hyperstacks>Reduce > Dimensionality... menu, however, it works exactly as expected from the > code. > > The opening lines of the plugin are: > > package ij.plugin; > import ij.*; > import ij.gui.*; > import ij.process.*; > import ij.measure.Calibration; > import java.awt.*; > import java.util.Vector; > > /** Implements the Image/HyperStacks/Reduce Dimensionality command. */ > public class HyperStackReducer implements PlugIn, DialogListener { > ImagePlus imp; > int channels1, slices1, frames1; > int channels2, slices2, frames2; > double imageSize; > static boolean keep = true; > /** Default constructor */ > public HyperStackReducer() { > } > > /** Constructs a HyperStackReducer using the specified source > image. */ > public HyperStackReducer(ImagePlus imp) { > this.imp = imp; > } > > public void run(String arg) { > imp = IJ.getImage(); > if (!(imp.isHyperStack() || imp.isComposite())) { > IJ.error("Reducer", "HyperStack required"); > return; > } > int width = imp.getWidth(); > . > . > . > > I have tried a few variations to the code including > public void run(String arg) { > imp = ij.WindowManager.getCurrentImage(); > ... > but get the same result. > It seems that the plugin is not even executing, because running it > from the installed menu command gives an error if there is no image > open or if the current image is not of the correct type. My efforts > with "Compile and Run..." don't even give the errors in such > situations. > > Am I un aware or forgetting some magic that's needed to get a plugin > to execute on the current image? I am still quite new to java code, > but I can't find what I'm missing. Are the constructors the problem? > > Thanks for any help! > Bill > > > -- > William A. Mohler > Associate Professor > Dept. of Genetics and Developmental Biology > University of Connecticut Health Center > MC-3301 > 263 Farmington Ave. > Farmington, CT 06030-3301 > > [hidden email] > Mobile: (860) 985-2719 > alt. mobile: (860) 331-8514 > skype: wmohler > > Office: (860) 679-1833, room E2029 > Lab: (860) 679-1834, room E2032 > Fax: (314) 689-1833 > > G&DB dept. ofc.: (860) 679-8350 > G&DB dept. fax : (860) 679-8345 > http://genetics.uchc.edu/Faculty/Mohler/Mohler.html > P Think before you print > |
Ah yes!!
I knew I must be overlooking something dumb! Thanks, Wayne. And thanks also for the new hyperstack navigation keys in 1.42l! Bill >The first line in the plugin ("package ij.plugin;") needs to be >replaced with "import ij.plugin.*;". > >-wayne > >On Apr 6, 2009, at 4:57 PM, Bill Mohler wrote: > >>I am hoping to make a modified version of HyperStackReducer, a >>plugin that is bundled with and installed in the current version of >>ImagJ. >> >>When I find the source code at >>http://rsb.info.nih.gov/ij/docs/source/ij/plugin/HyperStackReducer.java.html >>and copy the code and save it in a file called >>HyperStackReducer.java, >>I get no errors, but nothing happens. >> >>Running the same plugin from the Image>Hyperstacks>Reduce >>Dimensionality... menu, however, it works exactly as expected from >>the code. >> >>The opening lines of the plugin are: >> >>package ij.plugin; >>import ij.*; >>import ij.gui.*; >>import ij.process.*; >>import ij.measure.Calibration; >>import java.awt.*; >>import java.util.Vector; >> >>/** Implements the Image/HyperStacks/Reduce Dimensionality command. */ >>public class HyperStackReducer implements PlugIn, DialogListener { >> ImagePlus imp; >> int channels1, slices1, frames1; >> int channels2, slices2, frames2; >> double imageSize; >> static boolean keep = true; >> /** Default constructor */ >> public HyperStackReducer() { >> } >> >> /** Constructs a HyperStackReducer using the specified source image. */ >> public HyperStackReducer(ImagePlus imp) { >> this.imp = imp; >> } >> >> public void run(String arg) { >> imp = IJ.getImage(); >> if (!(imp.isHyperStack() || imp.isComposite())) { >> IJ.error("Reducer", "HyperStack required"); >> return; >> } >> int width = imp.getWidth(); >>. >>. >>. >> >>I have tried a few variations to the code including >> public void run(String arg) { >> imp = ij.WindowManager.getCurrentImage(); >>... >>but get the same result. >>It seems that the plugin is not even executing, because running it >>from the installed menu command gives an error if there is no image >>open or if the current image is not of the correct type. My >>efforts with "Compile and Run..." don't even give the errors in >>such situations. >> >>Am I un aware or forgetting some magic that's needed to get a >>plugin to execute on the current image? I am still quite new to >>java code, but I can't find what I'm missing. Are the constructors >>the problem? >> >>Thanks for any help! >>Bill >> >> >>-- >>William A. Mohler >>Associate Professor >>Dept. of Genetics and Developmental Biology >>University of Connecticut Health Center >>MC-3301 >>263 Farmington Ave. >>Farmington, CT 06030-3301 >> >>[hidden email] >>Mobile: (860) 985-2719 >>alt. mobile: (860) 331-8514 >>skype: wmohler >> >>Office: (860) 679-1833, room E2029 >>Lab: (860) 679-1834, room E2032 >>Fax: (314) 689-1833 >> >>G&DB dept. ofc.: (860) 679-8350 >>G&DB dept. fax : (860) 679-8345 >>http://genetics.uchc.edu/Faculty/Mohler/Mohler.html >>P Think before you print |
Free forum by Nabble | Edit this page |