Login  Register

Re: macro help please

Posted by Larry Nolan on Dec 16, 2009; 12:03am
URL: http://imagej.273.s1.nabble.com/macro-help-please-tp3689867p3689885.html

Jerome,
  one thing I don't understand in the fragment you proposed; what's  
the variable 'nResults' coming from?

thanks,
Larry

On Dec 15, 2009, at 4:58 PM, Jerome Mutterer wrote:

> Larry Nolan <[hidden email]> wrote:
> setAutoThreshold();
> setThreshold(0, 128);
>
>
> Larry,
> In addition to Gabriels' answers, you might also be wanting to  
> record the
> actual threshold values used for your measurements. In that case,  
> you could
> add them to your results table by adding the following lines to your  
> code:
>
> ...
> setAutoThreshold();
> getThreshold(lower, upper);
> run("Convert to Mask");
> run("Measure");
> setResult("Lower",nResults-1,lower);
> setResult("Upper",nResults-1,upper);
> updateResults();
> close();
> ...
>
> Sincerely,
> Jerome
>
>
>
> On Tue, Dec 15, 2009 at 11:28 PM, Larry Nolan <[hidden email]>  
> wrote:
>
>> I'm creating a macro to process a directory of forest canopy images.
>> Here's what I've got so far after wrapping a recorded macro for one  
>> image
>> file:
>>
>>  dir = getDirectory("Choose a Directory ");
>>  list = getFileList(dir);
>>  setOption("display labels", true);
>>  setBatchMode(true);
>>
>>  for (i=0; i<list.length; i++) {
>>      path = dir+list[i];
>>      showProgress(i, list.length);
>>
>>      open(path);
>>
>>      run("8-bit");
>>      setAutoThreshold();
>>      //run("Threshold...");
>>      setThreshold(0, 128);
>>      run("Convert to Mask");
>>      run("Measure");
>>
>>      close();
>>  }
>>
>> My question is that I want each image to get it's own threshold set
>> automatically but I'm not sure how to do that to replace the
>> setThreshold(0,128) call.  What I want is to open each image,  
>> convert to
>> greyscale, do an autothreshold, then convert to Binary and do the  
>> Measure
>> function to calculate the percentage of black pixel which represent  
>> the
>> canopy.  I think I'm close but would appreciate a review of what  
>> I've done
>> so far.
>>
>> thanks,
>>
>> Larry
>>