get percentage of Background(pixel intensity = 0) for a batch of images by using Macro

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

get percentage of Background(pixel intensity = 0) for a batch of images by using Macro

zkwyao
Hi,

I am currently dealing with batches of images using imagej macro, to extract the background percentage from each image and want to save the percentages into one folder with file name save as the image file. could you pls offer me some help?

Thank you so so so much!
Reply | Threaded
Open this post in threaded view
|

Re: get percentage of Background(pixel intensity = 0) for a batch of images by using Macro

zkwyao
my code is


dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
setBatchMode(true);
for (i = 0; i<list.length; i++)
{
showProgress(i, list.length);
open(dir1+list[i]);

run("Subtract...", "value=700");
Background = 0;
Cell = 0;
for (y = 0; y < getHeight; y++) {
  for (x = 0; x < getWidth; x++) {
  inten = getPixel(x,y);
    if (inten <= 0) Background++;
    else Cell++;
  }
}
Backgroundpercent = Background/(Background + Cell) * 100;

showMessage("Background = " + Background +
  ", Cell = " + Cell +
  ", Background percentage = " + Backgroundpercent + "%")
  }


but how to save the data into one file with different names in the file?