Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
GP
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version)

GP
Hie!

I have been trying to run "restore selection" in my simple macro but after few initial images it has been doing the selection at the wrong co-ordinates. 
I am using 1.51i version. Have tried to run it in both batch mode true and false but the problem persists. 

In my macro I do the following on Binary images:

1.Open Image (Lets call it 'Org')
2.Run Select none
3.Run Set Measurements 
4.Duplicate (lets call it 'D')
5.On the Duplicate 'D' > run Auto Threshold, Default mode 
6.Run Convex Hull Selection on 'Org'
7.Restore selection on the Duplicate 'D'
8.Run Analyze Particles on Duplicate 'D'

I have run the entire macro on same image it works but then the "Analyze Particle" considers "Convex Hull Selection" as one blob instead of differentiating the contents within the hull as separate objects.
This is probably because image needs to be thresholded before running "Analyze Particle"

Please help me out. Probably I am making some silly mistake.
Thank you so much.

--
Gunjan Pandey

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version)

Straatman, Kees (Dr.)
Dear Gunjan,

If you publish your code on the mailing list it is easier to see where the problem might be

Kees

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of GP
Sent: 02 February 2017 23:59
To: [hidden email]
Subject: Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version)

Hie!

I have been trying to run "restore selection" in my simple macro but after few initial images it has been doing the selection at the wrong co-ordinates.
I am using 1.51i version. Have tried to run it in both batch mode true and false but the problem persists.

In my macro I do the following on Binary images:

1.Open Image (Lets call it 'Org')
2.Run Select none
3.Run Set Measurements
4.Duplicate (lets call it 'D')
5.On the Duplicate 'D' > run Auto Threshold, Default mode 6.Run Convex Hull Selection on 'Org'
7.Restore selection on the Duplicate 'D'
8.Run Analyze Particles on Duplicate 'D'

I have run the entire macro on same image it works but then the "Analyze Particle" considers "Convex Hull Selection" as one blob instead of differentiating the contents within the hull as separate objects.
This is probably because image needs to be thresholded before running "Analyze Particle"

Please help me out. Probably I am making some silly mistake.
Thank you so much.

--
Gunjan Pandey




--
View this message in context: http://imagej.1557.x6.nabble.com/Re-Restore-Selection-at-Wrong-Co-ordinates-through-Macro-Run-1-51i-version-tp5018013.html
Sent from the ImageJ mailing list archive at Nabble.com.

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

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

Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version)

GP
Hie!

Here is the used code:

print("\\Clear");
run("Clear Results");
dir1 = getDirectory("Choose  Directory ");
list = getFileList(dir1);
dirName = File.getName(dir1);

outDir = dir1+"Analyz_Prt_cyst"+dirName+File.separator;
File.makeDirectory(outDir);
if (!File.exists(outDir))
exit("Unable to create directory");

setBatchMode(true);
for (i=0;i<list.length;i++)
{
          showProgress(i+1, list.length);
      if (endsWith(list[i],"tif") || endsWith(list[i],"TIF"))
      {
     
        open(dir1+ list[i]);
      run("Select None");
      run("Set Measurements...", "area mean standard modal min centroid center perimeter bounding fit shape integrated median skewness kurtosis area_fraction redirect=None decimal=3");
      OrgTitle = getTitle();
      run("Duplicate...", " ");
      AnaTitle = getTitle();
      run("Auto Threshold", "method=Default");
      selectWindow(OrgTitle);
      run("Select None");
                run("Convex Hull Plus", "mode=[Convex Hull Selection] white log");
                selectWindow(AnaTitle);
                run("Restore Selection");
                run("Analyze Particles...", "  show=Outlines display include summarize");
                TargetTitle = getTitle();
                saveAs("tif", ""+outDir+""+TargetTitle+"Analyz_Prt.tif");
 }
          selectWindow("Log");
         // saveAs("Text", ""+outDir+""+dirName+"Analyz_Prt_cyst.xls");
          saveAs("Results", outDir+"Analyz_Prt_cyst.xls");
}

Thanks,
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version)

Rasband, Wayne (NIH/NIMH) [E]
> On Feb 3, 2017, at 3:59 AM, GP <[hidden email]> wrote:
>
> Hie!
>
> Here is the used code:

What we need to debug this problem is an MCVE (Minimal, Complete and Verifiable example).

    http://stackoverflow.com/help/mcve

An MCVE for a problem with the "Restore Selection” command would look something like the following, except that this macro shows that "Restore Selection” works as expected.

-wayne

   run("Leaf (36K)");
   makeRectangle(10, 82, 491, 354);
   run("Crop");
   run("8-bit");
   setAutoThreshold("MinError");
   run("Analyze Particles...", "size=1000 show=Overlay");
   Overlay.activateSelection(0);
   run("Convex Hull");
   Roi.getBounds(x,y,width,height);
   print(getTitle, x,y,width,height);
   newImage("Untitled", "8-bit black", 491, 354, 1);
   run("Restore Selection");
   Roi.getBounds(x,y,width,height);
   print(getTitle, x,y,width,height);


> print("\\Clear");
> run("Clear Results");
> dir1 = getDirectory("Choose  Directory ");
> list = getFileList(dir1);
> dirName = File.getName(dir1);
>
> outDir = dir1+"Analyz_Prt_cyst"+dirName+File.separator;
> File.makeDirectory(outDir);
> if (!File.exists(outDir))
> exit("Unable to create directory");
>
> setBatchMode(true);
> for (i=0;i<list.length;i++)
> {
>  showProgress(i+1, list.length);
>      if (endsWith(list[i],"tif") || endsWith(list[i],"TIF"))
>      {
>      
>        open(dir1+ list[i]);
>     run("Select None");
>     run("Set Measurements...", "area mean standard modal min centroid
> center perimeter bounding fit shape integrated median skewness kurtosis
> area_fraction redirect=None decimal=3");
>     OrgTitle = getTitle();
>     run("Duplicate...", " ");
>     AnaTitle = getTitle();
>     run("Auto Threshold", "method=Default");
>     selectWindow(OrgTitle);
>     run("Select None");
> run("Convex Hull Plus", "mode=[Convex Hull Selection] white log");
> selectWindow(AnaTitle);
> run("Restore Selection");
> run("Analyze Particles...", "  show=Outlines display include summarize");
> TargetTitle = getTitle();
> saveAs("tif", ""+outDir+""+TargetTitle+"Analyz_Prt.tif");
> }
>  selectWindow("Log");
> // saveAs("Text", ""+outDir+""+dirName+"Analyz_Prt_cyst.xls");
>  saveAs("Results", outDir+"Analyz_Prt_cyst.xls");
> }
>
> Thanks,



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

Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version)

GP
Hie!

Thank you for the MCVE approach. I did it from scratch and it seems to work now.

If we take the example figure: Leaf 36K I basically wanted to get the area of the parts between the 'convex hull' and Leaf at the base (No: 5 and 24 only). 

Inline image 1

With the following code it works much better on my images:

                run("Leaf (36K)");
run("Make Binary");
makeRectangle(1, 77, 503, 366);
run("Crop");
run("Convex Hull Plus", "mode=[Convex Hull selection] white log");
run("Auto Threshold", "method=MinError(I)");
run("Analyze Particles...", "  show=Outlines display include summarize");

However I am still working on how to filter these values from the other ones that I get along with them.

Thanks again :)

Best Regards,

On Sat, Feb 4, 2017 at 5:18 AM, Rasband, Wayne (NIH/NIMH) [E] [via ImageJ] <[hidden email]> wrote:
> On Feb 3, 2017, at 3:59 AM, GP <[hidden email]> wrote:
>
> Hie!
>
> Here is the used code:

What we need to debug this problem is an MCVE (Minimal, Complete and Verifiable example).

    http://stackoverflow.com/help/mcve

An MCVE for a problem with the "Restore Selection” command would look something like the following, except that this macro shows that "Restore Selection” works as expected.

-wayne

   run("Leaf (36K)");
   makeRectangle(10, 82, 491, 354);
   run("Crop");
   run("8-bit");
   setAutoThreshold("MinError");
   run("Analyze Particles...", "size=1000 show=Overlay");
   Overlay.activateSelection(0);
   run("Convex Hull");
   Roi.getBounds(x,y,width,height);
   print(getTitle, x,y,width,height);
   newImage("Untitled", "8-bit black", 491, 354, 1);
   run("Restore Selection");
   Roi.getBounds(x,y,width,height);
   print(getTitle, x,y,width,height);


> print("\\Clear");
> run("Clear Results");
> dir1 = getDirectory("Choose  Directory ");
> list = getFileList(dir1);
> dirName = File.getName(dir1);
>
> outDir = dir1+"Analyz_Prt_cyst"+dirName+File.separator;
> File.makeDirectory(outDir);
> if (!File.exists(outDir))
> exit("Unable to create directory");
>
> setBatchMode(true);
> for (i=0;i<list.length;i++)
> {
>  showProgress(i+1, list.length);
>      if (endsWith(list[i],"tif") || endsWith(list[i],"TIF"))
>      {
>      
>        open(dir1+ list[i]);
>     run("Select None");
>     run("Set Measurements...", "area mean standard modal min centroid
> center perimeter bounding fit shape integrated median skewness kurtosis
> area_fraction redirect=None decimal=3");
>     OrgTitle = getTitle();
>     run("Duplicate...", " ");
>     AnaTitle = getTitle();
>     run("Auto Threshold", "method=Default");
>     selectWindow(OrgTitle);
>     run("Select None");
> run("Convex Hull Plus", "mode=[Convex Hull Selection] white log");
> selectWindow(AnaTitle);
> run("Restore Selection");
> run("Analyze Particles...", "  show=Outlines display include summarize");
> TargetTitle = getTitle();
> saveAs("tif", ""+outDir+""+TargetTitle+"Analyz_Prt.tif");
> }
>  selectWindow("Log");
> // saveAs("Text", ""+outDir+""+dirName+"Analyz_Prt_cyst.xls");
>  saveAs("Results", outDir+"Analyz_Prt_cyst.xls");
> }
>
> Thanks,


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



To unsubscribe from Re: "Restore Selection" at Wrong Co-ordinates through Macro Run (1.51i version), click here.
NAML



--
Gunjan Pandey

Loading...