Thanks, now it works. :)
> Hello,
> you need to call the method incrementCounter on the results-table each
> time before adding values to a new line.
> Volker
>
> On 19/05/11 11:48, Susanna Trollvad wrote:
> > I have written a plugin which loads n pictures, and stores their names in
> an
> > array called fileArray. The pictures contains one or more needle-like
> > objects and my plugin finds them and measures their length and width
> which
> > is then stored in two arrays:
> > length[][]
> > width[][]
> > for example id picture one has two "needles" length[0] will contain an
> int
> > array with the length of each needle in each element.
> >
> > I want to display the results in table that a user could view, save and
> > possibly manipulate. I have tried using the class ResultsTable in imagej
> but
> > I doesn't work and I'm not sure why. Does anyone else know?
> >
> > Here is the code were I try to put the values in the table:
> >
> >
> > resulty = new ResultsTable();
> > for(int a = 0;a<fileArray.length;a++) {
> > for(int b=0;b<county[a];b++){
> > resulty.addLabel("Image",fileArray[a]);
> > //resulty.addValue("Length",(double)lengthArr[a][b]);
> > //resulty.addValue("Width",(double)widthArr[a][b]);
> > }
> > }
> >
> > This is the message I get when I try to run my program:
> >
> > "java.lang.IllegalArgumentException: Counter==0
> > at ij.measure.ResultsTable.addLabel(ResultsTable.java:160)
> > at Rotating_Bounding_Box.run(Rotating_Bounding_Box.java:140)
> > at ij.IJ.runUserPlugIn(IJ.java:183)
> > at ij.ImageJ.runUserPlugIn(ImageJ.java:264)
> > at ij.plugin.PlugInExecuter.run(Compiler.java:264)
> > at java.lang.Thread.run(Thread.java:619)"
> >
> > Here is the entire program:
> >
> > import ij.*;
> > import ij.plugin.filter.PlugInFilter;
> > import ij.process.*;
> > import java.awt.*;
> > import ij.plugin.*;
> > import ij.gui.*;
> > import ij.measure.*;
> > import ij.text.*;
> > import java.util.*;
> > import ij.plugin.Thresholder;
> > import ij.plugin.filter.ParticleAnalyzer;
> > import ij.plugin.frame.RoiManager;
> > import java.io.File;
> > import ij.io.Opener;
> > import ij.WindowManager;
> > import ij.measure.ResultsTable;
> > //Plugin that loads a number of pictures(all depicting one or more
> pin-like
> > structures).
> > //Then the plugin measures the length and thickness of each pin in all of
> > the pictures.
> >
> >
> > public class Rotating_Bounding_Box implements PlugIn {
> > ImagePlus imp;
> > ImageProcessor ip;
> > ImageConverter convert;
> > ImageStack stacky;
> > Thresholder treshy;
> > ParticleAnalyzer party;
> > RoiManager manager1;
> > Roi[] RoiArr;
> > Rectangle r;
> > Roi roy;
> > ImageWindow win;
> > File load;
> > String path;
> > String[] fileArray;
> > Opener openy;
> > String processy;
> > String MorP;
> > ResultsTable resulty;
> > int[] county;
> > int[][] lengthArr;
> > int[][] widthArr;
> >
> > public void run(String arg) {
> >
> > path = IJ.getString("Path to image files: ",path);
> > load = new File(path);
> > fileArray = load.list();
> > openy = new Opener();
> > county = new int[fileArray.length];
> > lengthArr = new int[fileArray.length][];
> > widthArr = new int[fileArray.length][];
> >
> > for(int i = 0;i<fileArray.length;i++) {
> > imp = openy.openImage(path+"/"+fileArray[i]);
> > imp.show();
> >
> > //Code from line 34-53 adapted from (
> >
>
http://imagej.588099.n2.nabble.com/How-to-rotate-transform-an-Roi-td2639892.html> > )
> > int ht = imp.getHeight();
> > int wd = imp.getWidth();
> >
> > ImagePlus dst = NewImage.createRGBImage("HSB", wd, ht, 1,
> > NewImage.FILL_BLACK);
> >
> > ImageProcessor srcp = imp.getProcessor();
> > imp.changes = false;
> > imp.close();
> > ImageProcessor dstp = dst.getProcessor();
> > int[] srcpix = (int[])srcp.getPixels();
> > int[] dstpix = (int[])dstp.getPixels();
> >
> > Rectangle r = srcp.getRoi();
> >
> > for (int y=r.y; y<(r.y+r.height); y++) {
> > for (int x=r.x; x<(r.x+r.width); x++) {
> > int u = x + y*wd;
> > dstpix[u] = srcpix[u];
> > }
> > }
> > dst.show();
> >
> > //Convert to HSB and delete H and S slice
> > convert = new ImageConverter(dst);
> > convert.convertToHSB();
> > stacky = dst.getImageStack();
> > dst.setSlice(3);
> > stacky.deleteSlice(1);
> > stacky.deleteSlice(2);
> >
> > //Threshold
> > //Use ThresholdtoSelection?
> > dstp.setThreshold(200, 255, dstp.getLutUpdateMode());
> > treshy = new Thresholder();
> > treshy.run("Convert to Mask");
> >
> > //Analyze particles
> > manager1 = new RoiManager();//For all particles
> > IJ.run(dst,"Analyze Particles...", "size=1000-Infinity
> > circularity=0.00-1.00 show=Nothing exclude clear include add
> > slice");
> >
> > //Rotate particles
> > manager1 = manager1.getInstance();
> > county[i] = manager1.getCount();
> > if(manager1.getCount()!=0) {
> > RoiArr = manager1.getRoisAsArray();
> > lengthArr[i] = new int[RoiArr.length];
> > widthArr[i] = new int[RoiArr.length];
> > int minW; int lengthy;
> > for(int j=0;j<RoiArr.length;j++){
> > r = RoiArr[j].getBounds();
> > minW = r.width;
> > lengthy = r.height;
> > manager1.select(dst,j);
> > for(int ang=1;ang<180;ang++){
> > IJ.run("Rotate...", "angle="+IJ.d2s(ang));
> > roy = dst.getRoi();
> > r=roy.getBounds();
> > if(minW>r.width){
> > minW = r.width;
> > lengthy = r.height;
> > }
> > manager1.select(dst,j);
> > }
> > lengthArr[i][j] = lengthy;
> > widthArr[i][j] = minW;
> > }
> > }
> > else{
> > lengthArr[i] = new int[1];
> > widthArr[i] = new int[1];
> > lengthArr[i][0] = 0;
> > widthArr[i][0] = 0;
> > }
> > dst.changes = false;
> > dst.close();
> > manager1.close();
> > }
> >
> > resulty = new ResultsTable();
> > for(int a = 0;a<fileArray.length;a++) {
> > for(int b=0;b<county[a];b++){
> > resulty.addLabel("Image",fileArray[a]);
> > //resulty.addValue("Length",(double)lengthArr[a][b]);
> > //resulty.addValue("Width",(double)widthArr[a][b]);
> > }
> > }
> >
> >
> > }
> >
> >
> > }
>