How to write a macro for multiple images analysis in the calculator plus?

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

How to write a macro for multiple images analysis in the calculator plus?

behravan1987
Hello everyone

I have a set of images in a folder which their names are: 2 days.bmp 3
days.bmp ..... 28 days.bmp. Also, I have a folder with the background images
exactly with the same names. I want to use the calculator plus and divide
each image to its relevant background. I want to save time and do that at
the same time instead of doing it for each image one by one. Is there any
idea how can I do that? I have written a macro but it didn't work for me.
Thanks.



macro "Batch calculate images [1]" {

LocationOfFiles = getDirectory("Select Folder");

LocationOfbackgrounds = getDirectory("Select Folder of backgrounds");

LocationOfSave = getDirectory("Select Save Location");



setBatchMode(true);

FileList = getFileList(LocationOfFiles);

NumberOfFiles = FileList.length;

for (i=0; i<NumberOfFiles; i+=1) {

FileName = FileList[i];

pathtofile1 = LocationOfFiles+FileName;

open(pathtofile1);

name1 = getTitle();

pathtofile2 = LocationOfbackgrounds+FileName;

open(pathtofile2);

name2 = getTitle();

run("Calculator Plus", "i1="+name1+" i2="+name2+" operation=[Divide: i2 =
(i1/i2) x k1 + k2] k1=255 k2=0 create");

selectWindow("Result");

SaveName = replace(name, ".bmp", "_backgroud subtracted.jpg");

saveAs("BMP", LocationOfSave+SaveName);

selectWindow(BackgroundImage);

close("\\Others");



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: How to write a macro for multiple images analysis in the calculator plus?

Fred Damen
Greetings,

File->Import->Image Sequence...
File->Import->Image Sequence...
Process->Image Calculator... (Entire Stack)

Fred

On Mon, November 19, 2018 6:02 pm, behravan1987 wrote:

> Hello everyone
>
> I have a set of images in a folder which their names are: 2 days.bmp 3
> days.bmp ..... 28 days.bmp. Also, I have a folder with the background images
> exactly with the same names. I want to use the calculator plus and divide
> each image to its relevant background. I want to save time and do that at
> the same time instead of doing it for each image one by one. Is there any
> idea how can I do that? I have written a macro but it didn't work for me.
> Thanks.
>
>
>
> macro "Batch calculate images [1]" {
>
> LocationOfFiles = getDirectory("Select Folder");
>
> LocationOfbackgrounds = getDirectory("Select Folder of backgrounds");
>
> LocationOfSave = getDirectory("Select Save Location");
>
>
>
> setBatchMode(true);
>
> FileList = getFileList(LocationOfFiles);
>
> NumberOfFiles = FileList.length;
>
> for (i=0; i<NumberOfFiles; i+=1) {
>
> FileName = FileList[i];
>
> pathtofile1 = LocationOfFiles+FileName;
>
> open(pathtofile1);
>
> name1 = getTitle();
>
> pathtofile2 = LocationOfbackgrounds+FileName;
>
> open(pathtofile2);
>
> name2 = getTitle();
>
> run("Calculator Plus", "i1="+name1+" i2="+name2+" operation=[Divide: i2 =
> (i1/i2) x k1 + k2] k1=255 k2=0 create");
>
> selectWindow("Result");
>
> SaveName = replace(name, ".bmp", "_backgroud subtracted.jpg");
>
> saveAs("BMP", LocationOfSave+SaveName);
>
> selectWindow(BackgroundImage);
>
> close("\\Others");
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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