Saving csv in batch mode

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

Saving csv in batch mode

Aina
Hi,

I'm trying to detect and count jellyfish in a very large number of images (extracted as jpeg from video). Therefore, I would like to use the batch processing function. The process I follow for one image is to invert it, I apply colour threshold, do a selection, transfer the selection to the ROI manager, split the selection and measure, I then save Results as a csv file. I've managed to get the macro working for one image but I haven't managed to apply the batch function through a macro. I've followed similar posts but I guess I'm still very unfamiliar with ImageJ and its language, I would appreciate any help greatly.

Say my input file is here: "Users/input" and my output file where I would like all the csv to go to is here "Users/output". How do I set it?What do I need to add at the beginning and end of the code? I'm confused about how to set the directories, the files and the name files. In other posts I've seen code such as:

setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++)
        action(input, output, list[i]);
setBatchMode(false);

BUT, do I need to replace "input", "output" with the actual path of my files or do I need to define input and output previously (i.e. input=/Users/input)

Below is the code I'm running. What do I need to add at the beginning and end of the code?:

This is the code that I run:

run("Invert");
run("Color Threshold...");
// Color Thresholder 2.0.0-rc-61/1.51n
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=140;
max[0]=243;
filter[0]="pass";
min[1]=0;
max[1]=51;
filter[1]="pass";
min[2]=43;
max[2]=186;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
  selectWindow(""+i);
  close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);
// Colour Thresholding-------------

run("Create Selection");
roiManager("Add");
roiManager("Split");
roiManager("Measure");

I'd be extremely grateful for any help or tips given,

Ana
Reply | Threaded
Open this post in threaded view
|

Re: Saving csv in batch mode

Rainer M. Engel
Hey Ana,

you need to specify different things. Available functions can be found
here..
https://imagej.nih.gov/ij/developer/macro/functions.html

As a starting point try this.. (but you need to adjust it further)
//++++++++++++++++++++++++++++++++++++++++++
dir1   = getDirectory("Input Folder ..");
dir2   = getDirectory("Output Folder (CSV/TXT) ..");
list1 = getFileList(dir1);

setBatchMode(true);

for (i=0; i<list1.length; i++) {
        showProgress(i+1, list1.length);

        workF = dir1+list1[i];
        print(workF);

        //do all your fancy stuff with openend image
        //open(workF);
        //-----------------------
       
        run("Close All");

        //write CSV
        outLog = dir2+substring(list1[i], 0, lengthOf(list1[i])-4)+"_results.txt";
        //nada = File.delete(outLog); //maybe delete first
        outLog = File.open(outLog);

        print(outLog, "Only a placeholder for what you want to write..");
       
        File.close(outLog);
}
//++++++++++++++++++++++++++++++++++++++++++

Most important is the part, what you want to write as csv.

Regards,
Rainer

Am 25.07.2017 um 10:49 schrieb Aina:

> Hi,
>
> I'm trying to detect and count jellyfish in a very large number of images
> (extracted as jpeg from video). Therefore, I would like to use the batch
> processing function. The process I follow for one image is to invert it, I
> apply colour threshold, do a selection, transfer the selection to the ROI
> manager, split the selection and measure, I then save Results as a csv file.
> I've managed to get the macro working for one image but I haven't managed to
> apply the batch function through a macro. I've followed similar posts but I
> guess I'm still very unfamiliar with ImageJ and its language, I would
> appreciate any help greatly.
>
> Say my input file is here: "Users/input" and my output file where I would
> like all the csv to go to is here "Users/output". How do I set it?What do I
> need to add at the beginning and end of the code? I'm confused about how to
> set the directories, the files and the name files. In other posts I've seen
> code such as:
>
> setBatchMode(true);
> list = getFileList(input);
> for (i = 0; i < list.length; i++)
>         action(input, output, list[i]);
> setBatchMode(false);
>
> BUT, do I need to replace "input", "output" with the actual path of my files
> or do I need to define input and output previously (i.e. input=/Users/input)
>
> Below is the code I'm running. What do I need to add at the beginning and
> end of the code?:
>
> This is the code that I run:
>
> run("Invert");
> run("Color Threshold...");
> // Color Thresholder 2.0.0-rc-61/1.51n
> // Autogenerated macro, single images only!
> min=newArray(3);
> max=newArray(3);
> filter=newArray(3);
> a=getTitle();
> run("HSB Stack");
> run("Convert Stack to Images");
> selectWindow("Hue");
> rename("0");
> selectWindow("Saturation");
> rename("1");
> selectWindow("Brightness");
> rename("2");
> min[0]=140;
> max[0]=243;
> filter[0]="pass";
> min[1]=0;
> max[1]=51;
> filter[1]="pass";
> min[2]=43;
> max[2]=186;
> filter[2]="pass";
> for (i=0;i<3;i++){
>   selectWindow(""+i);
>   setThreshold(min[i], max[i]);
>   run("Convert to Mask");
>   if (filter[i]=="stop")  run("Invert");
> }
> imageCalculator("AND create", "0","1");
> imageCalculator("AND create", "Result of 0","2");
> for (i=0;i<3;i++){
>   selectWindow(""+i);
>   close();
> }
> selectWindow("Result of 0");
> close();
> selectWindow("Result of Result of 0");
> rename(a);
> // Colour Thresholding-------------
>
> run("Create Selection");
> roiManager("Add");
> roiManager("Split");
> roiManager("Measure");
>
> I'd be extremely grateful for any help or tips given,
>
> Ana
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Saving-csv-in-batch-mode-tp5019124.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
Reply | Threaded
Open this post in threaded view
|

Re: Saving csv in batch mode

jerie
Hi Ana,

how about https://imagej.nih.gov/ij/docs/guide/146-29.html#sub:batch
>Macro...

Measurements made during the batch processing are appended to the results
window.

My2cents,
cheers, Jens



Dr. Jens Rietdorf, visiting scientist @ center for technological
development in health CDTS, Oswaldo Cruz Foundation Fiocruz, Rio de Janeiro
Brasil.

From Sep 1st, 2017: Customer Success Manager, FEI, The Netherlands.


On Tue, Jul 25, 2017 at 9:30 AM, Rainer M. Engel <[hidden email]> wrote:

> Hey Ana,
>
> you need to specify different things. Available functions can be found
> here..
> https://imagej.nih.gov/ij/developer/macro/functions.html
>
> As a starting point try this.. (but you need to adjust it further)
> //++++++++++++++++++++++++++++++++++++++++++
> dir1    = getDirectory("Input Folder ..");
> dir2    = getDirectory("Output Folder (CSV/TXT) ..");
> list1   = getFileList(dir1);
>
> setBatchMode(true);
>
> for (i=0; i<list1.length; i++) {
>         showProgress(i+1, list1.length);
>
>         workF   = dir1+list1[i];
>         print(workF);
>
>         //do all your fancy stuff with openend image
>         //open(workF);
>         //-----------------------
>
>         run("Close All");
>
>         //write CSV
>         outLog  = dir2+substring(list1[i], 0, lengthOf(list1[i])-4)+"_
> results.txt";
>         //nada  = File.delete(outLog);  //maybe delete first
>         outLog  = File.open(outLog);
>
>         print(outLog, "Only a placeholder for what you want to write..");
>
>         File.close(outLog);
> }
> //++++++++++++++++++++++++++++++++++++++++++
>
> Most important is the part, what you want to write as csv.
>
> Regards,
> Rainer
>
> Am 25.07.2017 um 10:49 schrieb Aina:
> > Hi,
> >
> > I'm trying to detect and count jellyfish in a very large number of images
> > (extracted as jpeg from video). Therefore, I would like to use the batch
> > processing function. The process I follow for one image is to invert it,
> I
> > apply colour threshold, do a selection, transfer the selection to the ROI
> > manager, split the selection and measure, I then save Results as a csv
> file.
> > I've managed to get the macro working for one image but I haven't
> managed to
> > apply the batch function through a macro. I've followed similar posts
> but I
> > guess I'm still very unfamiliar with ImageJ and its language, I would
> > appreciate any help greatly.
> >
> > Say my input file is here: "Users/input" and my output file where I would
> > like all the csv to go to is here "Users/output". How do I set it?What
> do I
> > need to add at the beginning and end of the code? I'm confused about how
> to
> > set the directories, the files and the name files. In other posts I've
> seen
> > code such as:
> >
> > setBatchMode(true);
> > list = getFileList(input);
> > for (i = 0; i < list.length; i++)
> >         action(input, output, list[i]);
> > setBatchMode(false);
> >
> > BUT, do I need to replace "input", "output" with the actual path of my
> files
> > or do I need to define input and output previously (i.e.
> input=/Users/input)
> >
> > Below is the code I'm running. What do I need to add at the beginning and
> > end of the code?:
> >
> > This is the code that I run:
> >
> > run("Invert");
> > run("Color Threshold...");
> > // Color Thresholder 2.0.0-rc-61/1.51n
> > // Autogenerated macro, single images only!
> > min=newArray(3);
> > max=newArray(3);
> > filter=newArray(3);
> > a=getTitle();
> > run("HSB Stack");
> > run("Convert Stack to Images");
> > selectWindow("Hue");
> > rename("0");
> > selectWindow("Saturation");
> > rename("1");
> > selectWindow("Brightness");
> > rename("2");
> > min[0]=140;
> > max[0]=243;
> > filter[0]="pass";
> > min[1]=0;
> > max[1]=51;
> > filter[1]="pass";
> > min[2]=43;
> > max[2]=186;
> > filter[2]="pass";
> > for (i=0;i<3;i++){
> >   selectWindow(""+i);
> >   setThreshold(min[i], max[i]);
> >   run("Convert to Mask");
> >   if (filter[i]=="stop")  run("Invert");
> > }
> > imageCalculator("AND create", "0","1");
> > imageCalculator("AND create", "Result of 0","2");
> > for (i=0;i<3;i++){
> >   selectWindow(""+i);
> >   close();
> > }
> > selectWindow("Result of 0");
> > close();
> > selectWindow("Result of Result of 0");
> > rename(a);
> > // Colour Thresholding-------------
> >
> > run("Create Selection");
> > roiManager("Add");
> > roiManager("Split");
> > roiManager("Measure");
> >
> > I'd be extremely grateful for any help or tips given,
> >
> > Ana
> >
> >
> >
> > --
> > View this message in context: http://imagej.1557.x6.nabble.
> com/Saving-csv-in-batch-mode-tp5019124.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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Jens Rietdorf Visiting Scientist Fundação Oswaldo Cruz - Ministério da Saúde, Centro de Desenvolvimento Tecnológico em Saúde (CDTS), Rio de Janeiro, Brasil.