Dear all,
Here is my situation: I have over 600 image sequences in one folder (each contains 360 frames, in avi format), each sequence shows 1-2 objects moving within these 360 frames. The final goal is to measure the velocity of these objects in the first 60 frames. I can do it one by one as follows: first I need to subtract each frame with a background frame which contains constant things (I can process one sequence manually by "image"--"stacks"--"Z projection"---"max intensity" to get the background frame, then "process"---"image calculator"--- "difference" between original sequence and "max intensity") Then convert to binary mode (I can do it manually by setting threshold) Lastly run "object tracker" plug-in which I downloaded from internet But I need it to be batch processed. I did find something relevant: background subtraction:http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt binary:http://www.fmhs.auckland.ac.nz/sms/biru/_docs/Using_and_Writing_Macros_in_ImageJ.pdf (Page 9) As a start to adopt these two macros, I ran these original macros,but somehow I kept having error window pop up (I converted my avi to tif) I don't know the reason. Is there anyone who can help me here, either by modifying and combining these two macros to fit my need, or just giving me some directions to start with. I would appreciate any kind of help! Best, Zheng |
Sorry for the mass, I just realized that in the step of background
subtraction, in most cases, I can use "process"---"subtract background"---rolling ball (which is the command used in : http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt I attached in the first email), no need to find background image. Anyone can help me? Best, Zheng 2011/8/15 zezh1112 <[hidden email]> > Dear all, > > Here is my situation: I have over 600 image sequences in one folder (each > contains 360 frames, in avi format), each sequence shows 1-2 objects moving > within these 360 frames. The final goal is to measure the velocity of these > objects in the first 60 frames. > > I can do it one by one as follows: > > first I need to subtract each frame with a background frame which contains > constant things (I can process one sequence manually by > "image"--"stacks"--"Z projection"---"max intensity" to get the background > frame, then "process"---"image calculator"--- "difference" between original > sequence and "max intensity") > > Then convert to binary mode (I can do it manually by setting threshold) > > Lastly run "object tracker" plug-in which I downloaded from internet > > But I need it to be batch processed. I did find something relevant: > *background > subtraction*:http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt > *binary*: > http://www.fmhs.auckland.ac.nz/sms/biru/_docs/Using_and_Writing_Macros_in_ImageJ.pdf > (Page 9) > > As a start to adopt these two macros, I ran these original macros,but > somehow I kept having error window pop up (I converted my avi to tif) > > I don't know the reason. Is there anyone who can help me here, either by > modifying and combining these two macros to fit my need, or just giving me > some directions to start with. I would appreciate any kind of help! > > Best, > Zheng > > -- > View this message in context: > http://imagej.588099.n2.nabble.com/batch-background-subtraction-and-convert-to-binary-images-tp6689869p6689869.html > Sent from the ImageJ mailing list archive at Nabble.com. > |
I tried myself to adopt the exiting batch macro as follows:
*requires("1.33s"); * * dir = getDirectory("Choose a Directory ");* * setBatchMode(true);* * count = 0;* * countFiles(dir);* * n = 0;* * processFiles(dir);* * //print(count+" files processed");* * * * function countFiles(dir) {* * list = getFileList(dir);* * for (i=0; i<list.length; i++) {* * if (endsWith(list[i], "/"))* * countFiles(""+dir+list[i]);* * else* * count++;* * }* * }* * * * function processFiles(dir) {* * list = getFileList(dir);* * for (i=0; i<list.length; i++) {* * if (endsWith(list[i], "/"))* * processFiles(""+dir+list[i]);* * else {* * showProgress(n++, count);* * path = dir+list[i];* * processFile(path);* * }* * }* * }* * * * function processFile(path) {* * if (endsWith(path, ".avi")) {* * for (i=0; i<list.length; i++) {* * open(path);* * run("Z Project...", "start=1 stop=61 projection=[Max Intensity]");* * imageCalculator("Difference create stack", "list[i]","MAX_list[i]");* * selectWindow("Result of list[i]");* * setAutoThreshold("Minimum");* * run("Convert to Mask", " black");* * run("Tracker ", "minimum=1 maximum=10000");* * }* * }* * }* But I was told that the computer couldn't find image when it read to line: *imageCalculator("Difference create stack", "list[i]","MAX_list[i]");* there must be something wrong about "list[i]", I tried to replace by path, the same error occurred. Does anyone know how to debug it? Thanks so much! Zheng 2011/8/15 Zheng Zeng <[hidden email]> > Sorry for the mass, I just realized that in the step of background > subtraction, in most cases, I can use "process"---"subtract > background"---rolling ball (which is the command used in : > http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt I attached in > the first email), no need to find background image. > > Anyone can help me? > > Best, > Zheng > > > 2011/8/15 zezh1112 <[hidden email]> > >> Dear all, >> >> Here is my situation: I have over 600 image sequences in one folder (each >> contains 360 frames, in avi format), each sequence shows 1-2 objects >> moving >> within these 360 frames. The final goal is to measure the velocity of >> these >> objects in the first 60 frames. >> >> I can do it one by one as follows: >> >> first I need to subtract each frame with a background frame which contains >> constant things (I can process one sequence manually by >> "image"--"stacks"--"Z projection"---"max intensity" to get the background >> frame, then "process"---"image calculator"--- "difference" between >> original >> sequence and "max intensity") >> >> Then convert to binary mode (I can do it manually by setting threshold) >> >> Lastly run "object tracker" plug-in which I downloaded from internet >> >> But I need it to be batch processed. I did find something relevant: >> *background >> subtraction*:http://rsb.info.nih.gov/ij/macros/BatchProcessFolders.txt >> *binary*: >> http://www.fmhs.auckland.ac.nz/sms/biru/_docs/Using_and_Writing_Macros_in_ImageJ.pdf >> (Page 9) >> >> As a start to adopt these two macros, I ran these original macros,but >> somehow I kept having error window pop up (I converted my avi to tif) >> >> I don't know the reason. Is there anyone who can help me here, either by >> modifying and combining these two macros to fit my need, or just giving me >> some directions to start with. I would appreciate any kind of help! >> >> Best, >> Zheng >> >> -- >> View this message in context: >> http://imagej.588099.n2.nabble.com/batch-background-subtraction-and-convert-to-binary-images-tp6689869p6689869.html >> Sent from the ImageJ mailing list archive at Nabble.com. >> > > |
On Wednesday 17 Aug 2011, you wrote:
> I tried myself to adopt the exiting batch macro as follows: imageCalculator("Difference create stack", "list[i]","MAX_list[i]"); selectWindow("Result of list[i]");* > But I was told that the computer couldn't find image when it read to > line: *imageCalculator("Difference > create stack", "list[i]","MAX_list[i]");* > there must be something wrong about "list[i]", I tried to replace by path, > the same error occurred. Does anyone know how to debug it? Yes, you are parsing the string incorrectly, list[] is an array, not a string, so it should not go within the " ". You need to do something like this: imageCalculator("Difference create stack", list[i], "MAX_"+list[i]); selectWindow("Result of "+list[i]); I have not tried this, so I might have some typo. Cheers G |
Hi Gabriel,
Thanks for your help! I changed accordingly, *function processFile(path) {* * if (endsWith(path, ".avi")) {* * for (i=0; i<list.length; i++) {* * open(path);* * run("Z Project...", "start=1 stop=61 projection=[Max Intensity]");* * imageCalculator("Difference create stack", list[i], "MAX_"+list[i]);* * selectWindow("Result of "+list[i]);* * save(path+".tif"); * * close(); * * }* * }* * }* I ran the macro to a test folder with only 2 files, the time when second file was processed, an error pop up: *image not found in line 38* *imageCalculator("Difference create stack", list[i<]>, "MAX_"+list[i]);* And when I went back to this test folder after running the macro, I did find the first file successfully processed and saved. what happened? If the first works, that means command itself should be right, while second doesn't work, something wrong about the loop? Thanks again for your patience and help! Zheng 2011/8/17 Gabriel Landini <[hidden email]> > On Wednesday 17 Aug 2011, you wrote: > > I tried myself to adopt the exiting batch macro as follows: > imageCalculator("Difference create stack", > "list[i]","MAX_list[i]"); > selectWindow("Result of list[i]");* > > > But I was told that the computer couldn't find image when it read to > > line: *imageCalculator("Difference > > create stack", "list[i]","MAX_list[i]");* > > there must be something wrong about "list[i]", I tried to replace by > path, > > the same error occurred. Does anyone know how to debug it? > > Yes, you are parsing the string incorrectly, list[] is an array, not a > string, > so it should not go within the " ". You need to do something like this: > > imageCalculator("Difference create stack", list[i], "MAX_"+list[i]); > selectWindow("Result of "+list[i]); > > I have not tried this, so I might have some typo. > Cheers > > G > |
On Wednesday 17 Aug 2011, Zheng Zeng wrote:
> Hi Gabriel, > > Thanks for your help! I changed accordingly, > > *function processFile(path) {* > * if (endsWith(path, ".avi")) {* > * for (i=0; i<list.length; i++) {* > * open(path);* > * run("Z Project...", "start=1 stop=61 projection=[Max > Intensity]");* > * imageCalculator("Difference create stack", list[i], > "MAX_"+list[i]);* > * selectWindow("Result of "+list[i]);* > * save(path+".tif"); * > * close(); * > * }* > * }* > * }* Not sure. You open > * for (i=0; i<list.length; i++) {* > * open(path);* I guess that you are not opening the right image in the loop. Does you function see the list[ ] array? I think the path variable has the name of one file, so the processFile function should only process 1 file, not an array of files. Cheers G. |
Free forum by Nabble | Edit this page |