NIH LISTSERV
NIH LISTSERV
IMAGEJ archives -- November 2002 (#36)

Go to: Previous Message | Next Message
Previous in Topic | Next in Topic
Previous by Same Author | Next by Same Author
Previous Page (November 2002) | Back to Main IMAGEJ Page


Options: Reply | Post a New Message | Join or Leave IMAGEJ, or Change Options | Search
View: Chronologically | Most Recent First | Wrap Text (Proportional Font) | Don't Wrap Text (Non-proportional Font)
*

Content-Type: text/plain; charset=US-ASCII; format=flowed
Message-ID:  <[log in to unmask]>
Date:         Thu, 14 Nov 2002 17:57:39 -0500
Reply-To:     ImageJ Interest Group <[log in to unmask]>
Sender:       ImageJ Interest Group <[log in to unmask]>
From:         Wayne Rasband <[log in to unmask]>
Subject:      Re: Color correction
In-Reply-To:  <[log in to unmask]>

> I *know* this should be a fairly simple plugin to write, but I don't > know > Java! (I'm a non-GUI embedded C type, myself). I'm sure I can pick > up the > small amount of Java I'll need to write the calculations and create a > plugin > (cut-&-paste), but I have no clue about building the GUI I'll need. > > How much of this can (or should) be implemented as a script? How much > should be implemented in Java (preferred) or in C (for speed)? How > much is > already implemented in existing code? This should be a plugin. Macros that do pixel-by-pixel processing are about 100 times slower than plugins. There is no need for C. Java will be plenty fast. One way to have the user edit a 3x3 matrix is to display it in a GenericDialog as a text area. This is what the Process>Filters>Convolve command does for n x n kernels. A big advantage of using a GenericDialog is it makes the plugin recordable so it can be called from macros. I have attached an example plugin that allows a 3x3 matrix to be edited. -wayne /************************** Color_Corrector.java ********************************/ import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; import java.util.*; public class Color_Corrector implements PlugInFilter { ImagePlus imp; static double[] matrix = {1.791,-0.517,-0.274,-0.090, 1.321,-0.231,-0.054,-0.236, 1.290}; public int setup(String arg, ImagePlus imp) { this.imp = imp; return DOES_RGB; } public void run(ImageProcessor ip) { if (!getMatrix()) return; displayMatrix(); } boolean getMatrix() { GenericDialog gd = new GenericDialog("Matrix"); String text = ""; for (int i=0; i<9; i++) { text += IJ.d2s(matrix[i],3)+" "; if (i%3==2) text += "\n"; } gd.addTextAreas(text, null, 5, 20); gd.showDialog(); if (gd.wasCanceled()) return false; text = gd.getNextText(); StringTokenizer st = new StringTokenizer(text); int n = st.countTokens(); if (n!=9) {IJ.error("Matrix must be 3x3"); return false;} for (int i=0; i<9; i++) matrix[i] = getNum(st); return true; } double getNum(StringTokenizer st) { Double d; String token = st.nextToken(); try {d = new Double(token);} catch (NumberFormatException e){d = null;} if (d!=null) return(d.doubleValue()); else return 0.0; } void displayMatrix() { IJ.log(""); IJ.log(matrix[0]+" "+matrix[1]+" "+matrix[2]); IJ.log(matrix[3]+" "+matrix[4]+" "+matrix[5]); IJ.log(matrix[6]+" "+matrix[7]+" "+matrix[8]); } }




Back to: Top of message | Previous page | Main IMAGEJ page

NIH LISTSERV Home Page

CIT
Center for Information Technology
National Institutes of Health
Bethesda, Maryland 20892
301 594 6248 (v) 301 496 8294 (TDD)
Comments and Assistance
Accessibility wheelchair icon