Batch processing images with custom threshold values

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

Batch processing images with custom threshold values

ademcan
Dear List members,

I am working on a project which requires cell counts from thousands of
images. Obviously, batch processing is the right way to work on these
images. I am not a programmer but still managed to reverse engineer some
batch processing macros originally written for other functions for myself.
But still there are problems that I need your expertise to solve.

These are 8-bit images of immunoreactive neurons to be counted. I can't use
the built-in autothresholding or entropy methods. Instead for each image a
different threshold value is calculated according to the following formula:
mean gray values+(2.5xSTD). I can calculate these values en masse with batch
statistics macro. But after that, I have to do actual cell counting one by
one, entering the appropriate threshold value for each image, a process
which is, needlessly to say, unproductive.

The ideal macro will batch process the following steps:

-Open each image from a folder
-Calculate the threshold value for that image, according to a user defined
algorithm (e.g. mean gray values+(2.5xSTD))
-Calculate number and total area of cells according to user defined
parameters (e.g. min-max pixel size) using the threshold value from the
previous step
-Export these cell number and area values with the file name of the image
into an Excel sheet (or a text file)

So far I could not write such a macro. Thank you in advance for your help.


Adem Can
The University of Texas at Austin, Department of Psychology
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing images with custom threshold values

Wayne Rasband
Here is a macro that runs the particle analyzer on all the images in  
a folder using custom threshold values and saves the results as a  
text file. It requires ImageJ 1.38o or later. The particle analyzer  
in earlier versions created a "Summary" window for each image.

     requires("1.38o");
     dir = getDirectory("Choose a Directory ");
     list = getFileList(dir);
     setBatchMode(true);
     for (i=0; i<list.length; i++) {
         showProgress(i, list.length);
         open(dir+list[i]);
         getStatistics(area, mean, min, max, std);
         threshold = mean + 2.5*std;
         setThreshold(threshold, 255);
         run("Analyze Particles...", "size=10-1000 summarize");
         close;
     }
     selectWindow("Summary");
     saveAs("Text", getDirectory("home")+"Summary.txt");

-wayne

On Jul 4, 2007, at 5:37 PM, Adem Can wrote:

> Dear List members,
>
> I am working on a project which requires cell counts from thousands of
> images. Obviously, batch processing is the right way to work on these
> images. I am not a programmer but still managed to reverse engineer  
> some
> batch processing macros originally written for other functions for  
> myself.
> But still there are problems that I need your expertise to solve.
>
> These are 8-bit images of immunoreactive neurons to be counted. I  
> can't use
> the built-in autothresholding or entropy methods. Instead for each  
> image a
> different threshold value is calculated according to the following  
> formula:
> mean gray values+(2.5xSTD). I can calculate these values en masse  
> with batch
> statistics macro. But after that, I have to do actual cell counting  
> one by
> one, entering the appropriate threshold value for each image, a  
> process
> which is, needlessly to say, unproductive.
>
> The ideal macro will batch process the following steps:
>
> -Open each image from a folder
> -Calculate the threshold value for that image, according to a user  
> defined
> algorithm (e.g. mean gray values+(2.5xSTD))
> -Calculate number and total area of cells according to user defined
> parameters (e.g. min-max pixel size) using the threshold value from  
> the
> previous step
> -Export these cell number and area values with the file name of the  
> image
> into an Excel sheet (or a text file)
>
> So far I could not write such a macro. Thank you in advance for  
> your help.
>
>
> Adem Can
> The University of Texas at Austin, Department of Psychology
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing images with custom threshold values

ademcan
Wayne,

Thanks a lot for your prompt response and the excellent macro. It
works perfect. I appreciate your help.

Adem

On 7/4/07, Rasband Wayne <[hidden email]> wrote:

> Here is a macro that runs the particle analyzer on all the images in
> a folder using custom threshold values and saves the results as a
> text file. It requires ImageJ 1.38o or later. The particle analyzer
> in earlier versions created a "Summary" window for each image.
>
>      requires("1.38o");
>      dir = getDirectory("Choose a Directory ");
>      list = getFileList(dir);
>      setBatchMode(true);
>      for (i=0; i<list.length; i++) {
>          showProgress(i, list.length);
>          open(dir+list[i]);
>          getStatistics(area, mean, min, max, std);
>          threshold = mean + 2.5*std;
>          setThreshold(threshold, 255);
>          run("Analyze Particles...", "size=10-1000 summarize");
>          close;
>      }
>      selectWindow("Summary");
>      saveAs("Text", getDirectory("home")+"Summary.txt");
>
> -wayne
>
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing images with custom threshold values

Pascal Lorentz
In reply to this post by Wayne Rasband
Hi Wayne

your plugin is really great.
I'm still working with the version 1.37v and therefore I get a summary window
for each image and can not save them in a single file.
On the ImageJ website I can not get a newer version than 1.37v for PC.
What can I do.

Pascal


Zitat von Rasband Wayne <[hidden email]>:

> Here is a macro that runs the particle analyzer on all the images in
> a folder using custom threshold values and saves the results as a
> text file. It requires ImageJ 1.38o or later. The particle analyzer
> in earlier versions created a "Summary" window for each image.
>
>      requires("1.38o");
>      dir = getDirectory("Choose a Directory ");
>      list = getFileList(dir);
>      setBatchMode(true);
>      for (i=0; i<list.length; i++) {
>          showProgress(i, list.length);
>          open(dir+list[i]);
>          getStatistics(area, mean, min, max, std);
>          threshold = mean + 2.5*std;
>          setThreshold(threshold, 255);
>          run("Analyze Particles...", "size=10-1000 summarize");
>          close;
>      }
>      selectWindow("Summary");
>      saveAs("Text", getDirectory("home")+"Summary.txt");
>
> -wayne
>
> On Jul 4, 2007, at 5:37 PM, Adem Can wrote:
>
> > Dear List members,
> >
> > I am working on a project which requires cell counts from thousands of
> > images. Obviously, batch processing is the right way to work on these
> > images. I am not a programmer but still managed to reverse engineer
> > some
> > batch processing macros originally written for other functions for
> > myself.
> > But still there are problems that I need your expertise to solve.
> >
> > These are 8-bit images of immunoreactive neurons to be counted. I
> > can't use
> > the built-in autothresholding or entropy methods. Instead for each
> > image a
> > different threshold value is calculated according to the following
> > formula:
> > mean gray values+(2.5xSTD). I can calculate these values en masse
> > with batch
> > statistics macro. But after that, I have to do actual cell counting
> > one by
> > one, entering the appropriate threshold value for each image, a
> > process
> > which is, needlessly to say, unproductive.
> >
> > The ideal macro will batch process the following steps:
> >
> > -Open each image from a folder
> > -Calculate the threshold value for that image, according to a user
> > defined
> > algorithm (e.g. mean gray values+(2.5xSTD))
> > -Calculate number and total area of cells according to user defined
> > parameters (e.g. min-max pixel size) using the threshold value from
> > the
> > previous step
> > -Export these cell number and area values with the file name of the
> > image
> > into an Excel sheet (or a text file)
> >
> > So far I could not write such a macro. Thank you in advance for
> > your help.
> >
> >
> > Adem Can
> > The University of Texas at Austin, Department of Psychology
>


--
Pascal Lorentz
Centre for Biomedicine
Department of Clinical-Biological Sciences
University of Basel


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing images with custom threshold values

jmutterer
Pascal,
You can upgrade your ImageJ installation by following the instructions
available at
http://rsb.info.nih.gov/ij/upgrade/

Jerome


On 7/10/07, Pascal Lorentz <[hidden email]> wrote:

>
> Hi Wayne
>
> your plugin is really great.
> I'm still working with the version 1.37v and therefore I get a summary
> window
> for each image and can not save them in a single file.
> On the ImageJ website I can not get a newer version than 1.37v for PC.
> What can I do.
>
> Pascal
>
>
> Zitat von Rasband Wayne <[hidden email]>:
>
> > Here is a macro that runs the particle analyzer on all the images in
> > a folder using custom threshold values and saves the results as a
> > text file. It requires ImageJ 1.38o or later. The particle analyzer
> > in earlier versions created a "Summary" window for each image.
> >
> >      requires("1.38o");
> >      dir = getDirectory("Choose a Directory ");
> >      list = getFileList(dir);
> >      setBatchMode(true);
> >      for (i=0; i<list.length; i++) {
> >          showProgress(i, list.length);
> >          open(dir+list[i]);
> >          getStatistics(area, mean, min, max, std);
> >          threshold = mean + 2.5*std;
> >          setThreshold(threshold, 255);
> >          run("Analyze Particles...", "size=10-1000 summarize");
> >          close;
> >      }
> >      selectWindow("Summary");
> >      saveAs("Text", getDirectory("home")+"Summary.txt");
> >
> > -wayne
> >
> > On Jul 4, 2007, at 5:37 PM, Adem Can wrote:
> >
> > > Dear List members,
> > >
> > > I am working on a project which requires cell counts from thousands of
> > > images. Obviously, batch processing is the right way to work on these
> > > images. I am not a programmer but still managed to reverse engineer
> > > some
> > > batch processing macros originally written for other functions for
> > > myself.
> > > But still there are problems that I need your expertise to solve.
> > >
> > > These are 8-bit images of immunoreactive neurons to be counted. I
> > > can't use
> > > the built-in autothresholding or entropy methods. Instead for each
> > > image a
> > > different threshold value is calculated according to the following
> > > formula:
> > > mean gray values+(2.5xSTD). I can calculate these values en masse
> > > with batch
> > > statistics macro. But after that, I have to do actual cell counting
> > > one by
> > > one, entering the appropriate threshold value for each image, a
> > > process
> > > which is, needlessly to say, unproductive.
> > >
> > > The ideal macro will batch process the following steps:
> > >
> > > -Open each image from a folder
> > > -Calculate the threshold value for that image, according to a user
> > > defined
> > > algorithm (e.g. mean gray values+(2.5xSTD))
> > > -Calculate number and total area of cells according to user defined
> > > parameters (e.g. min-max pixel size) using the threshold value from
> > > the
> > > previous step
> > > -Export these cell number and area values with the file name of the
> > > image
> > > into an Excel sheet (or a text file)
> > >
> > > So far I could not write such a macro. Thank you in advance for
> > > your help.
> > >
> > >
> > > Adem Can
> > > The University of Texas at Austin, Department of Psychology
> >
>
>
> --
> Pascal Lorentz
> Centre for Biomedicine
> Department of Clinical-Biological Sciences
> University of Basel
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
Reply | Threaded
Open this post in threaded view
|

Re: Batch processing images with custom threshold values

seb-7
In reply to this post by Pascal Lorentz
Pascal Lorentz wrote:
> Hi Wayne
>
> your plugin is really great.
> I'm still working with the version 1.37v and therefore I get a summary window
> for each image and can not save them in a single file.
> On the ImageJ website I can not get a newer version than 1.37v for PC.
> What can I do.
>
> Pascal


Hi Pascal,

Go to

http://rsb.info.nih.gov/ij/upgrade/index.html

the first link is the last ij.jar you need to download.
Replace the old ij.jar which should be in
C:\Prograp Files\ImageJ (assuming you use MS Windows) with this one and
start  ImageJ
The Help->About ImageJ menu should confirm you run the last version
(which is 1.38x when I am writing)


http://imagejdocu.tudor.lu/imagej-documentation-wiki/faq/how-do-i-update-imagej

regards,
sebastien
Reply | Threaded
Open this post in threaded view
|

problem opening avi files created by ImageJ in quicktime after upgrading to imovie HD 6

John Oreopoulos
In reply to this post by jmutterer
Yesterday I upgraded to imovie HD 6 on my mac laptop, and for some  
strange reason, I cannot open .avi files that were created by ImageJ  
in quicktime or imovie.

Old avi files created before the upgrade open up, but the movie just  
appears as a white screen in quicktime.
New avi files created after the upgrade won't even open at all using  
quicktime, I just get any error message saying the file can't be opened.

I made sure that I had the latest versions of ImageJ and quicktime  
installed on my laptop and even re-installed them, and I still have  
the same problem.

We have a mac ImageJ workstation in our lab which has not been  
upgraded to imovie HD 6, and all avi files, old or new, open fine in  
quicktime and imovie on this machine.

Has anyone else encountered this problem and does anyone know how to  
fix it?

Thanks ahead of time for any help or advice.


John Oreopoulos, BSc,
PhD Candidate
University of Toronto
Institute For Biomaterials and Biomedical Engineering
Centre For Studies in Molecular Imaging

Tel: W:416-946-5022
Reply | Threaded
Open this post in threaded view
|

Re: problem opening avi files created by ImageJ in quicktime after upgrading to imovie HD 6

John Oreopoulos
I also tried going the other way - I created an avi file on our lab  
workstation using ImageJ and then tried to open the file on my laptop  
using quicktime. The file will not open at all again. Very strange.

John

On 10-Jul-07, at 11:04 AM, John Oreopoulos wrote:

> Yesterday I upgraded to imovie HD 6 on my mac laptop, and for some  
> strange reason, I cannot open .avi files that were created by  
> ImageJ in quicktime or imovie.
>
> Old avi files created before the upgrade open up, but the movie  
> just appears as a white screen in quicktime.
> New avi files created after the upgrade won't even open at all  
> using quicktime, I just get any error message saying the file can't  
> be opened.
>
> I made sure that I had the latest versions of ImageJ and quicktime  
> installed on my laptop and even re-installed them, and I still have  
> the same problem.
>
> We have a mac ImageJ workstation in our lab which has not been  
> upgraded to imovie HD 6, and all avi files, old or new, open fine  
> in quicktime and imovie on this machine.
>
> Has anyone else encountered this problem and does anyone know how  
> to fix it?
>
> Thanks ahead of time for any help or advice.
>
>
> John Oreopoulos, BSc,
> PhD Candidate
> University of Toronto
> Institute For Biomaterials and Biomedical Engineering
> Centre For Studies in Molecular Imaging
>
> Tel: W:416-946-5022
>
>
Reply | Threaded
Open this post in threaded view
|

Re: problem opening avi files created by ImageJ in quicktime after upgrading to imovie HD 6

Michael Elbaum
In reply to this post by John Oreopoulos
You can try playing the file with mplayer (www.mplayerhq.hu). With the codecs it can play just about everything, and if you start it on the command line it spits out a lot of useful diagnostics.

Michael



>>> John Oreopoulos <[hidden email]> 07/10/07 5:55 PM >>>
I also tried going the other way - I created an avi file on our lab  
workstation using ImageJ and then tried to open the file on my laptop  
using quicktime. The file will not open at all again. Very strange.

John

On 10-Jul-07, at 11:04 AM, John Oreopoulos wrote:

> Yesterday I upgraded to imovie HD 6 on my mac laptop, and for some  
> strange reason, I cannot open .avi files that were created by  
> ImageJ in quicktime or imovie.
>
> Old avi files created before the upgrade open up, but the movie  
> just appears as a white screen in quicktime.
> New avi files created after the upgrade won't even open at all  
> using quicktime, I just get any error message saying the file can't  
> be opened.
>
> I made sure that I had the latest versions of ImageJ and quicktime  
> installed on my laptop and even re-installed them, and I still have  
> the same problem.
>
> We have a mac ImageJ workstation in our lab which has not been  
> upgraded to imovie HD 6, and all avi files, old or new, open fine  
> in quicktime and imovie on this machine.
>
> Has anyone else encountered this problem and does anyone know how  
> to fix it?
>
> Thanks ahead of time for any help or advice.
>
>
> John Oreopoulos, BSc,
> PhD Candidate
> University of Toronto
> Institute For Biomaterials and Biomedical Engineering
> Centre For Studies in Molecular Imaging
>
> Tel: W:416-946-5022
>
>
Reply | Threaded
Open this post in threaded view
|

Re: problem opening avi files created by ImageJ in quicktime after upgrading to imovie HD 6

ctrueden
In reply to this post by John Oreopoulos
Hi John,

I have a Mac Pro running OS X 10.4.10 with iMovie 6.0.3, QuickTime
Player 7.1.6 and ImageJ 1.38x. I used ImageJ to produce an AVI from
the MRI Stack sample, and was able to play it back with both iMovie
and QuickTime Player. An AVI produced with the Bio-Formats Exporter
plugin also worked.

You could try playing back the movies with other software, or on other
OSes (e.g., Windows Media Player). You might also want to try the
procedure with the MRI Stack, to see whether it is something about
your dataset (e.g., it could be a bug that manifests itself only for
images of certain resolutions).

-Curtis

On 7/10/07, John Oreopoulos <[hidden email]> wrote:

> I also tried going the other way - I created an avi file on our lab
> workstation using ImageJ and then tried to open the file on my laptop
> using quicktime. The file will not open at all again. Very strange.
>
> John
>
> On 10-Jul-07, at 11:04 AM, John Oreopoulos wrote:
>
> > Yesterday I upgraded to imovie HD 6 on my mac laptop, and for some
> > strange reason, I cannot open .avi files that were created by
> > ImageJ in quicktime or imovie.
> >
> > Old avi files created before the upgrade open up, but the movie
> > just appears as a white screen in quicktime.
> > New avi files created after the upgrade won't even open at all
> > using quicktime, I just get any error message saying the file can't
> > be opened.
> >
> > I made sure that I had the latest versions of ImageJ and quicktime
> > installed on my laptop and even re-installed them, and I still have
> > the same problem.
> >
> > We have a mac ImageJ workstation in our lab which has not been
> > upgraded to imovie HD 6, and all avi files, old or new, open fine
> > in quicktime and imovie on this machine.
> >
> > Has anyone else encountered this problem and does anyone know how
> > to fix it?
> >
> > Thanks ahead of time for any help or advice.
> >
> >
> > John Oreopoulos, BSc,
> > PhD Candidate
> > University of Toronto
> > Institute For Biomaterials and Biomedical Engineering
> > Centre For Studies in Molecular Imaging
> >
> > Tel: W:416-946-5022
> >
> >
>