Ferret distance problem in macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Ferret distance problem in macro

Fabian Kriegel
Hi everybody,
I am trying to automate my image analysis a bit. I wrote that little piece of code.  It should read in all the files in the directory, threshold them, run particle analyzer, and draw the ferret distance in the picture for the particle with the biggest area and later plot some parameters.

My Problems:

1.       The Ferret distance is not shown correctly

2.       Is theire a way to clean up the results table in a way that only the particle with the biggest area of each picture is shown?

Thx for your help

Fabi


Code:

dir1 = getDirectory("Choose Source Directory");

flist = getFileList(dir1);

setBatchMode(false);

for (lala=0; lala<flist.length; lala++ ){



                showProgress(lala+1, flist.length);

                open(dir1+flist[lala]);

                               //needed to change input pictures

                               changeValues(0x999999, 0x999999, 0x000000);

                               changeValues(0xffffff, 0xffffff, 0x000000);

                               a= getWidth();

                               b= getHeight();

                               a1= a/(1.11);

                               b1= b/(1.12);

                               w= a-a1;

                               h= b-b1;

                               setColor(0);

                               fillRect(a1, b1, w, h);

                               //Threshold

                               min=newArray(3);

                               max=newArray(3);

                               filter=newArray(3);

                               at=getTitle();

                               run("HSB Stack");

                               run("Convert Stack to Images");

                               selectWindow("Hue");

                               rename("0");

                               selectWindow("Saturation");

                               rename("1");

                               selectWindow("Brightness");

                               rename("2");

                               min[0]=0;

                               max[0]=255;

                                filter[0]="pass";

                               min[1]=0;

                               max[1]=255;

                               filter[1]="pass";

                               min[2]=119;

                               max[2]=255;

                               filter[2]="pass";

                               for (j=0;j<3;j++){

                                 selectWindow(""+j);

                                 setThreshold(min[j], max[j]);

                                 run("Convert to Mask");

                                 if (filter[j]=="stop")  run("Invert");

                               }

                               imageCalculator("AND create", "0","1");

                               imageCalculator("AND create", "Result of 0","2");

                               for (k=0;k<3;k++){

                                 selectWindow(""+k);

                                 close();

                               }

                               selectWindow("Result of 0");

                               close();

                               selectWindow("Result of Result of 0");

                               rename(at);





                               run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Outlines display summarize record add");



                               // Ferret NOT WORKING

                               List.setMeasurements;

                               x1 = List.getValue("FeretX");

                               y1 = List.getValue("FeretY");

                               length = List.getValue("Feret");

                               degrees = List.getValue("FeretAngle");

                               if (degrees>90)

                                               degrees += 180;

                               angle = degrees*PI/180;

                               x2 = x1 + cos(angle)*length;

                               y2 = y1 -sin(angle)*length;

                               setColor("red");

                               Overlay.drawLine(x1, y1, x2, y2);

                               Overlay.show();

}





--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Ferret distance problem in macro

Rasband, Wayne (NIH/NIMH) [E]
On Apr 22, 2013, at 8:17 AM, Fabian Kriegel wrote:

> Hi everybody,
> I am trying to automate my image analysis a bit. I wrote that little piece of code.  It should read in all the files in the directory, threshold them, run particle analyzer, and draw the ferret distance in the picture for the particle with the biggest area and later plot some parameters.
>
> My Problems:
>
> 1.       The Ferret distance is not shown correctly

Spatially calibrated X and Y coordinates retrieved from the Results table must be converted to pixel coordinates using toUnscaled() before they can be used to draw lines, points and text. Here is an example:

  // Draws the Feret diameter of the current selection.
  List.setMeasurements;
  x1 = List.getValue("FeretX");
  y1 = List.getValue("FeretY");
  length = List.getValue("Feret");
  degrees = List.getValue("FeretAngle");
  if (degrees>90)
     degrees += 180;
  angle = degrees*PI/180;
  x2 = x1 + cos(angle)*length;
  y2 = y1 - sin(angle)*length;
  setColor("red");
  toUnscaled(x1, y1);
  toUnscaled(x2, y2);
  Overlay.drawLine(x1, y1, x2, y2);
  Overlay.show();

-wayne

> 2.       Is theire a way to clean up the results table in a way that only the particle with the biggest area of each picture is shown?
>
> Thx for your help
>
> Fabi
>
>
> Code:
>
> dir1 = getDirectory("Choose Source Directory");
>
> flist = getFileList(dir1);
>
> setBatchMode(false);
>
> for (lala=0; lala<flist.length; lala++ ){
>
>
>
>                showProgress(lala+1, flist.length);
>
>                open(dir1+flist[lala]);
>
>                               //needed to change input pictures
>
>                               changeValues(0x999999, 0x999999, 0x000000);
>
>                               changeValues(0xffffff, 0xffffff, 0x000000);
>
>                               a= getWidth();
>
>                               b= getHeight();
>
>                               a1= a/(1.11);
>
>                               b1= b/(1.12);
>
>                               w= a-a1;
>
>                               h= b-b1;
>
>                               setColor(0);
>
>                               fillRect(a1, b1, w, h);
>
>                               //Threshold
>
>                               min=newArray(3);
>
>                               max=newArray(3);
>
>                               filter=newArray(3);
>
>                               at=getTitle();
>
>                               run("HSB Stack");
>
>                               run("Convert Stack to Images");
>
>                               selectWindow("Hue");
>
>                               rename("0");
>
>                               selectWindow("Saturation");
>
>                               rename("1");
>
>                               selectWindow("Brightness");
>
>                               rename("2");
>
>                               min[0]=0;
>
>                               max[0]=255;
>
>                                filter[0]="pass";
>
>                               min[1]=0;
>
>                               max[1]=255;
>
>                               filter[1]="pass";
>
>                               min[2]=119;
>
>                               max[2]=255;
>
>                               filter[2]="pass";
>
>                               for (j=0;j<3;j++){
>
>                                 selectWindow(""+j);
>
>                                 setThreshold(min[j], max[j]);
>
>                                 run("Convert to Mask");
>
>                                 if (filter[j]=="stop")  run("Invert");
>
>                               }
>
>                               imageCalculator("AND create", "0","1");
>
>                               imageCalculator("AND create", "Result of 0","2");
>
>                               for (k=0;k<3;k++){
>
>                                 selectWindow(""+k);
>
>                                 close();
>
>                               }
>
>                               selectWindow("Result of 0");
>
>                               close();
>
>                               selectWindow("Result of Result of 0");
>
>                               rename(at);
>
>
>
>
>
>                               run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Outlines display summarize record add");
>
>
>
>                               // Ferret NOT WORKING
>
>                               List.setMeasurements;
>
>                               x1 = List.getValue("FeretX");
>
>                               y1 = List.getValue("FeretY");
>
>                               length = List.getValue("Feret");
>
>                               degrees = List.getValue("FeretAngle");
>
>                               if (degrees>90)
>
>                                               degrees += 180;
>
>                               angle = degrees*PI/180;
>
>                               x2 = x1 + cos(angle)*length;
>
>                               y2 = y1 -sin(angle)*length;
>
>                               setColor("red");
>
>                               Overlay.drawLine(x1, y1, x2, y2);
>
>                               Overlay.show();
>
> }
>
>
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html