Hi all,
I'm using a macro to do some calculations on variables and then i'd like the results of the calculations to be added to a results table. So my first question is how do i make a customised results table with my own headings, columns and rows. I've seen the Plugins>New>Table option but i don't know how to add the headings and columns. Then how can i output a number stored in a variable to a specific column/row of my table. So far the macro makes a calculation but i'd like to run a loop so the calculation can be made on different objects in my image, then adding a subsequent row to my table. Any advice on data manipulation in tables would be great. Thanks in advance, Matt Pearson -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Matt,
you can simply use setResult("my name", rowNumber, value) It automatically creates a new column if there is no column with that name. You have to care about the row number yourself; ImageJ does not increment it automatically. See http://rsb.info.nih.gov/ij/developer/macro/functions.html#setResult Close the Results Table first selectWindow("Results"); run("Close"); if you want to start with a clean Results table having no other headings except your own. Michael ________________________________________________________________ On Nov 6, 2012, at 17:29, Matthew Pearson wrote: > Hi all, > > I'm using a macro to do some calculations on variables and then i'd like the results of the calculations to be added to a results table. So my first question is how do i make a customised results table with my own headings, columns and rows. I've seen the Plugins>New>Table option but i don't know how to add the headings and columns. Then how can i output a number stored in a variable to a specific column/row of my table. So far the macro makes a calculation but i'd like to run a loop so the calculation can be made on different objects in my image, then adding a subsequent row to my table. > > Any advice on data manipulation in tables would be great. > Thanks in advance, > > Matt Pearson -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by PEARSON Matthew
hi
If you want a table, but not THE results table the macro is not obvious so here is a the code from one of the help macros: title1 = Ttitle; title2 = "["+title1+"]"; f=title2; run("New... ", "name="+title2+" type=Table"); print(f,"\\Headings:Point\tX\tY\tetc\tetc"); then add a line of data output to that table by: print(f,Point[i]+"\t"+x1+"\t"+y1+"\t"+etc1+"\t"+etc2); regards Kenton On 6 Nov 2012, at 16:29, Matthew Pearson wrote: > Hi all, > > I'm using a macro to do some calculations on variables and then i'd like the results of the calculations to be added to a results table. So my first question is how do i make a customised results table with my own headings, columns and rows. I've seen the Plugins>New>Table option but i don't know how to add the headings and columns. Then how can i output a number stored in a variable to a specific column/row of my table. So far the macro makes a calculation but i'd like to run a loop so the calculation can be made on different objects in my image, then adding a subsequent row to my table. > > Any advice on data manipulation in tables would be great. > Thanks in advance, > > Matt Pearson > > > > > > > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
Hi, what can i do if i want to add a new topline in the resultstable with the
filename in the left corner? something like: title = getTitle(); run("Image to Results"); setResult("", nResults, title) saveAs("Results", dir+title+".csv"); Thanks in advance :) -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Good day,
no idea what this "run("Image to Results");" means but did you study the commented list of built-in macro functions of ImageJ: <https://imagej.nih.gov/ij/developer/macro/functions.html> Regards Herbie ::::::::::::::::::::::::::::::::::::: Am 28.03.18 um 14:04 schrieb dschones: > Hi, what can i do if i want to add a new topline in the resultstable with the > filename in the left corner? > something like: > > title = getTitle(); > run("Image to Results"); > setResult("", nResults, title) > saveAs("Results", dir+title+".csv"); > > Thanks in advance :) > > > > -- > 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 |
Hi. I studied the man of setResult("Column", row, value) but couldn't set it
as I need. Meanwhile i'm using textmanipulation to insert the filenames. Best wishes, Dschones -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
It would be helpful if you could precisely describe what you need.
If you need the latest entry row of a results table at the topmost position than this is just the other way round the table was conceptualized. I would stay with the conventional order, i.e. rows are added as the appear in time. HTH Herbie :::::::::::::::::::::::::::::::::::::: Am 28.03.18 um 16:07 schrieb dschones: > Hi. I studied the man of setResult("Column", row, value) but couldn't set it > as I need. Meanwhile i'm using textmanipulation to insert the filenames. > Best wishes, Dschones > > > > -- > 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 |
In reply to this post by dschones
Hi,
as far as I can say, you cannot insert anything at the beginning of a ResultsTable. For a table from "Image to Results", the first column is the rowLabel, not a regular column, so you can't overwrite it with setResult. If you need it like this for writing to a file, I would suggest to try the String functions https://imagej.nih.gov/ij/developer/macro/functions.html#String You can then use File.saveString. It will give you a tab-delimited file, not a .csv. @Herbie: run("Image to Results"); The command finder (L key) tells it is in Image>Transform. It writes the pixel values of the selection into the Results table (overwriting it). Michael ________________________________________________________________ On 28/03/2018 14:04, dschones wrote: > Hi, what can i do if i want to add a new topline in the resultstable with the > filename in the left corner? > something like: > > title = getTitle(); > run("Image to Results"); > setResult("", nResults, title) > saveAs("Results", dir+title+".csv"); > > Thanks in advance :) > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Herbie
Hi Herbie,
I'll just leave the generation of the results as they are and give the reference to the way I found getting the filename into first line of the results.txt https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> Good afternoon! :) -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Would it be ok to have the filename in a new first column:
X936 X937 X938 01.txt Y516 01.txt Y517 01.txt Y518 01.txt Y519 01.txt Y520 02.txt Y516 02.txt Y517 02.txt Y518 02.txt Y519 02.txt Y520 or something like: X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt X938_02.txt (watch for line breaks) Y516 Y517 Y518 Y519 Y520 or something along these lines: 01.txt X936 X937 X938 02.txt X936 X937 X938 Y516 Y516 Y517 Y517 Y518 Y518 Y519 Y519 Y520 Y520 AFAIK it is not possible to have numbers and letters in the same column except in the column headers. Please be aware of the fact that ImageJ is not a spread-sheet program, but serves for image processing in the first place. Regards Herbie :::::::::::::::::::::::::::::::::::::: Am 28.03.18 um 17:35 schrieb dschones: > Hi Herbie, > > I'll just leave the generation of the results as they are and give the > reference to the way I found getting the filename into first line of the > results.txt > > https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files > <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> > > Good afternoon! :) -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by dschones
Hi,
Below you can find a portion of a macro I have written, in which I generate a table with predefined columns and then I populate it with data. This can be measurements extracted from Results table and other variables and measurements you need. It generates a table in tab delimited format (the tabs are added as strings between the variables). As an attachment I also add the entire macro, so you can have an idea where are all results in my piece of code are coming from. I hope this will help you in your studies. Best wishes, Stoyan --- //The following code creates the table window and the columns run("Table...", "name=[Cell counts] width=800 height=600"); print("[Cell counts]", "\\Headings:Group\ Image\ Genes\ Counts\ Total\ ClassColor"); // This sequence adds the variables to their corresponding columns. You can use for this any variable including anything extracted with getResults command.If you insert it in aloop it can write repeated ly each measurement on a new row. print("[Cell counts]", trgroup+ " "+filename+" "+"negative "+negativecount+" "+total+" "+ 0); print("[Cell counts]", trgroup+ " "+filename+" "+geneonename+" "+gene1count+" "+total+" "+ 20); print("[Cell counts]", trgroup+ " "+filename+" "+genetwoname+" "+gene2count+" "+total+" "+ 53); print("[Cell counts]", trgroup+ " "+filename+" "+geneonename+"+"+genetwoname+" "+gene1and2count+" "+total+" "+ 73); --- Assoc.Prof. Stoyan P. Pavlov, MD, PhD Departament of Anatomy, Histology and Embryology Medical University "Prof. Dr. Paraskev Stoyanov", Varna Prof. Marin Drinov Str.55 9002 Varna Bulgaria Tel: +359 (0) 52 - 677 - 052 e-mail: [hidden email] [hidden email] 2018-03-28 15:04 GMT+03:00 dschones <[hidden email]>: > Hi, what can i do if i want to add a new topline in the resultstable with > the > filename in the left corner? > something like: > > title = getTitle(); > run("Image to Results"); > setResult("", nResults, title) > saveAs("Results", dir+title+".csv"); > > Thanks in advance :) > > > > -- > 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 |
In reply to this post by Herbie
Hi Herbie & dschones,
the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with getResultLabel(row) and setResult("Label", row, string). With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: myName = "01.txt"; Table.applyMacro("Results", "_='"+myName+" '+_"); (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) This gives you a space, not a tab between the '01.txt' and the 'Y123' In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: setResult("X123", 1, "hello"); Michael ________________________________________________________________ On 28/03/2018 17:58, Herbie wrote: > Would it be ok to have the filename in a new first column: > > X936 X937 X938 > 01.txt Y516 > 01.txt Y517 > 01.txt Y518 > 01.txt Y519 > 01.txt Y520 > > 02.txt Y516 > 02.txt Y517 > 02.txt Y518 > 02.txt Y519 > 02.txt Y520 > > or something like: > > X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt > X938_02.txt (watch for line breaks) > Y516 > Y517 > Y518 > Y519 > Y520 > > or something along these lines: > > 01.txt X936 X937 X938 02.txt X936 X937 X938 > Y516 Y516 > Y517 Y517 > Y518 Y518 > Y519 Y519 > Y520 Y520 > > > AFAIK it is not possible to have numbers and letters in the same column > except in the column headers. > > Please be aware of the fact that ImageJ is not a spread-sheet program, > but serves for image processing in the first place. > > Regards > > Herbie > > :::::::::::::::::::::::::::::::::::::: > Am 28.03.18 um 17:35 schrieb dschones: >> Hi Herbie, >> >> I'll just leave the generation of the results as they are and give the >> reference to the way I found getting the filename into first line of the >> results.txt >> >> https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files >> >> <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> >> >> >> Good afternoon! :) > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael, Stoyan Pavlov and Herbie,
thanks for your help! For the Moment I'm happy with what I figured out but I will work on this later :) Good day to you wishes Dschones -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
Table.applyMacro seems very useful, but I cannot see it documented in the
https://imagej.nih.gov/ij/developer/macro/functions.html webpage? Are there any other Table.* functions implemented in ImageJ ? Stein -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid Sent: 28. mars 2018 18:51 To: [hidden email] Subject: Re: How to create a customised results table and add data to it within a macro Hi Herbie & dschones, the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with getResultLabel(row) and setResult("Label", row, string). With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: myName = "01.txt"; Table.applyMacro("Results", "_='"+myName+" '+_"); (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) This gives you a space, not a tab between the '01.txt' and the 'Y123' In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: setResult("X123", 1, "hello"); Michael ________________________________________________________________ On 28/03/2018 17:58, Herbie wrote: > Would it be ok to have the filename in a new first column: > > X936 X937 X938 > 01.txt Y516 > 01.txt Y517 > 01.txt Y518 > 01.txt Y519 > 01.txt Y520 > > 02.txt Y516 > 02.txt Y517 > 02.txt Y518 > 02.txt Y519 > 02.txt Y520 > > or something like: > > X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt > X938_02.txt (watch for line breaks) > Y516 > Y517 > Y518 > Y519 > Y520 > > or something along these lines: > > 01.txt X936 X937 X938 02.txt X936 X937 X938 > Y516 Y516 > Y517 Y517 > Y518 Y518 > Y519 Y519 > Y520 Y520 > > > AFAIK it is not possible to have numbers and letters in the same column > except in the column headers. > > Please be aware of the fact that ImageJ is not a spread-sheet program, > but serves for image processing in the first place. > > Regards > > Herbie > > :::::::::::::::::::::::::::::::::::::: > Am 28.03.18 um 17:35 schrieb dschones: >> Hi Herbie, >> >> I'll just leave the generation of the results as they are and give the >> reference to the way I found getting the filename into first line of the >> results.txt >> >> https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files >> >> <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> >> >> >> Good afternoon! :) > > -- > 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 |
I wrote an analysis script that does something very like what dschones needs here. Since ImageJ does not allow two official Results tables, the macro creates a new table with custom column titles, then performs measurements and uses variables to store the results, then closes 'Results', renames the custom table to 'Results' and populates it with the measurement results. Then it renames the custom table again so that the next loop can use 'Results' to perform new measurements. It’s a bit of a kludge but it generates a Results table that has strings (e.g., any file name) in the first column and custom column titles.
All the best, Tim Timothy Feinstein, Ph.D. Research Scientist Department of Developmental Biology University of Pittsburgh On 4/9/18, 6:51 AM, "ImageJ Interest Group on behalf of Stein Rørvik" <[hidden email] on behalf of [hidden email]> wrote: Table.applyMacro seems very useful, but I cannot see it documented in the https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.nih.gov%2Fij%2Fdeveloper%2Fmacro%2Ffunctions.html&data=01%7C01%7Ctnf8%40pitt.edu%7Cb3a6afd98e8a45355aca08d59e07e110%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=awbyIkbopanJrse6w9ytgcKQy0vMDe8hbpjD8o4vk8s%3D&reserved=0 webpage? Are there any other Table.* functions implemented in ImageJ ? Stein -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid Sent: 28. mars 2018 18:51 To: [hidden email] Subject: Re: How to create a customised results table and add data to it within a macro Hi Herbie & dschones, the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with getResultLabel(row) and setResult("Label", row, string). With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: myName = "01.txt"; Table.applyMacro("Results", "_='"+myName+" '+_"); (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) This gives you a space, not a tab between the '01.txt' and the 'Y123' In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: setResult("X123", 1, "hello"); Michael ________________________________________________________________ On 28/03/2018 17:58, Herbie wrote: > Would it be ok to have the filename in a new first column: > > X936 X937 X938 > 01.txt Y516 > 01.txt Y517 > 01.txt Y518 > 01.txt Y519 > 01.txt Y520 > > 02.txt Y516 > 02.txt Y517 > 02.txt Y518 > 02.txt Y519 > 02.txt Y520 > > or something like: > > X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt > X938_02.txt (watch for line breaks) > Y516 > Y517 > Y518 > Y519 > Y520 > > or something along these lines: > > 01.txt X936 X937 X938 02.txt X936 X937 X938 > Y516 Y516 > Y517 Y517 > Y518 Y518 > Y519 Y519 > Y520 Y520 > > > AFAIK it is not possible to have numbers and letters in the same column > except in the column headers. > > Please be aware of the fact that ImageJ is not a spread-sheet program, > but serves for image processing in the first place. > > Regards > > Herbie > > :::::::::::::::::::::::::::::::::::::: > Am 28.03.18 um 17:35 schrieb dschones: >> Hi Herbie, >> >> I'll just leave the generation of the results as they are and give the >> reference to the way I found getting the filename into first line of the >> results.txt >> >> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Faskubuntu.com%2Fquestions%2F1019727%2Finserting-file-name-in-first-line-of-merged-txt-files&data=01%7C01%7Ctnf8%40pitt.edu%7Cb3a6afd98e8a45355aca08d59e07e110%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=iI6PBEGhJUnFBXSIf%2BAfgZ5BD5bA0E10jYm04d6LdCU%3D&reserved=0 >> >> <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Faskubuntu.com%2Fquestions%2F1019727%2Finserting-file-name-in-first-line-of-merged-txt-files&data=01%7C01%7Ctnf8%40pitt.edu%7Cb3a6afd98e8a45355aca08d59e07e110%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=iI6PBEGhJUnFBXSIf%2BAfgZ5BD5bA0E10jYm04d6LdCU%3D&reserved=0> >> >> >> Good afternoon! :) > > -- > ImageJ mailing list: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=01%7C01%7Ctnf8%40pitt.edu%7Cb3a6afd98e8a45355aca08d59e07e110%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=0B3tsXJnyVqe22LXVoGxAiZZSU04doULI%2FdUwxCHnBA%3D&reserved=0 -- ImageJ mailing list: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=01%7C01%7Ctnf8%40pitt.edu%7Cb3a6afd98e8a45355aca08d59e07e110%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=0B3tsXJnyVqe22LXVoGxAiZZSU04doULI%2FdUwxCHnBA%3D&reserved=0 -- ImageJ mailing list: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=01%7C01%7Ctnf8%40pitt.edu%7Cb3a6afd98e8a45355aca08d59e07e110%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=0B3tsXJnyVqe22LXVoGxAiZZSU04doULI%2FdUwxCHnBA%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Stein Rørvik
Hi Stein,
the Table.* functions are currently under development; they are in the daily build only. The list of currently implemented commands is in the Release notes: https://github.com/imagej/imagej1/blob/master/release-notes.html Table.create() - opens a new table Table.size() - number of rows in the table Table.title() - title of the current table Table.headings() - column headings as a tab-delimited string Table.get(columnName, rowIndex) - returns a numeric value Table.getString(columnName, rowIndex) - returns a string value Table.set(columnName, rowIndex, value) - sets numeric or string value Table.update() - updates table window Table.reset() - resets (clears) the table Table.applyMacro(macro) - applies macro code to table Table.rename(title1, title2) - renames a table Table.save(filePath) - saves the table Table.deleteRows(index1, index2) - deletes specified rows Table.deleteColumn(columnName) - deletes specified column Table.hideRowNumbers() - disables display of row numbers You can also specify the title of a table, this argument goes last. So e.g. the macro I had suggested last week has to be changed to: myName = "01.txt"; Table.applyMacro("_='"+myName+" '+_", "Results"); If no title is given, the commands refer the main "Results" table or to the current foreground window (if it has a table). Inside the macro of 'apply macro', if no title is given, the Table commands refer to the table processed by the macro. Note that these commands are still experimental. Things may still change, so you may have to adapt your macros in case of changes! Michael ________________________________________________________________ On 09/04/2018 12:43, Stein Rørvik wrote: > Table.applyMacro seems very useful, but I cannot see it documented in the > https://imagej.nih.gov/ij/developer/macro/functions.html webpage? > Are there any other Table.* functions implemented in ImageJ ? > > Stein > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid > Sent: 28. mars 2018 18:51 > To: [hidden email] > Subject: Re: How to create a customised results table and add data to it within a macro > > Hi Herbie & dschones, > > the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with > getResultLabel(row) and > setResult("Label", row, string). > > With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: > > myName = "01.txt"; > Table.applyMacro("Results", "_='"+myName+" '+_"); > > (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) > > This gives you a space, not a tab between the '01.txt' and the 'Y123' > > In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. > > By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: > setResult("X123", 1, "hello"); > > > Michael > ________________________________________________________________ > > > On 28/03/2018 17:58, Herbie wrote: >> Would it be ok to have the filename in a new first column: >> >> X936 X937 X938 >> 01.txt Y516 >> 01.txt Y517 >> 01.txt Y518 >> 01.txt Y519 >> 01.txt Y520 >> >> 02.txt Y516 >> 02.txt Y517 >> 02.txt Y518 >> 02.txt Y519 >> 02.txt Y520 >> >> or something like: >> >> X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt >> X938_02.txt (watch for line breaks) >> Y516 >> Y517 >> Y518 >> Y519 >> Y520 >> >> or something along these lines: >> >> 01.txt X936 X937 X938 02.txt X936 X937 X938 >> Y516 Y516 >> Y517 Y517 >> Y518 Y518 >> Y519 Y519 >> Y520 Y520 >> >> >> AFAIK it is not possible to have numbers and letters in the same column >> except in the column headers. >> >> Please be aware of the fact that ImageJ is not a spread-sheet program, >> but serves for image processing in the first place. >> >> Regards >> >> Herbie >> >> :::::::::::::::::::::::::::::::::::::: >> Am 28.03.18 um 17:35 schrieb dschones: >>> Hi Herbie, >>> >>> I'll just leave the generation of the results as they are and give the >>> reference to the way I found getting the filename into first line of the >>> results.txt >>> >>> https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files >>> >>> <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> >>> >>> >>> Good afternoon! :) >> >> -- >> 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 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks, exactly what I need. These functions will be very useful for manipulating an existing results table.
I already tried Table.applyMacro("Results", "DoubleArea=Area*2") with daily build 1.52a39 and it worked as expected. Today I use a similar approach as Timothy outlined: I create a new table, read the results from the old one, and use the getResult / setResult functions to create a new table. I also sometimes split lines and use the print(tablename, ... ) syntax to print tab-delimited headers and rows with the new table; this approach is much faster. To add to the below list, I think the functions Table.setHeader(<tabdelimited string>) and Table.addRow(<tabdelimited string>), Table.updateRow(<rowindex>, <tabdelimited string>) would be useful for writing contents in batch. Also, perhaps Table.headings() could be complemented with Table.rows() to return all the rows (except the header) as tab-delimited strings concatenated by \n as well as Table.content() to return everything as a string (headers plus all the rows) Stein -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid Sent: 09. april 2018 16:33 To: [hidden email] Subject: Re: How to create a customised results table and add data to it within a macro Hi Stein, the Table.* functions are currently under development; they are in the daily build only. The list of currently implemented commands is in the Release notes: https://github.com/imagej/imagej1/blob/master/release-notes.html Table.create() - opens a new table Table.size() - number of rows in the table Table.title() - title of the current table Table.headings() - column headings as a tab-delimited string Table.get(columnName, rowIndex) - returns a numeric value Table.getString(columnName, rowIndex) - returns a string value Table.set(columnName, rowIndex, value) - sets numeric or string value Table.update() - updates table window Table.reset() - resets (clears) the table Table.applyMacro(macro) - applies macro code to table Table.rename(title1, title2) - renames a table Table.save(filePath) - saves the table Table.deleteRows(index1, index2) - deletes specified rows Table.deleteColumn(columnName) - deletes specified column Table.hideRowNumbers() - disables display of row numbers You can also specify the title of a table, this argument goes last. So e.g. the macro I had suggested last week has to be changed to: myName = "01.txt"; Table.applyMacro("_='"+myName+" '+_", "Results"); If no title is given, the commands refer the main "Results" table or to the current foreground window (if it has a table). Inside the macro of 'apply macro', if no title is given, the Table commands refer to the table processed by the macro. Note that these commands are still experimental. Things may still change, so you may have to adapt your macros in case of changes! Michael ________________________________________________________________ On 09/04/2018 12:43, Stein Rørvik wrote: > Table.applyMacro seems very useful, but I cannot see it documented in the > https://imagej.nih.gov/ij/developer/macro/functions.html webpage? > Are there any other Table.* functions implemented in ImageJ ? > > Stein > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid > Sent: 28. mars 2018 18:51 > To: [hidden email] > Subject: Re: How to create a customised results table and add data to it within a macro > > Hi Herbie & dschones, > > the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with > getResultLabel(row) and > setResult("Label", row, string). > > With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: > > myName = "01.txt"; > Table.applyMacro("Results", "_='"+myName+" '+_"); > > (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) > > This gives you a space, not a tab between the '01.txt' and the 'Y123' > > In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. > > By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: > setResult("X123", 1, "hello"); > > > Michael > ________________________________________________________________ > > > On 28/03/2018 17:58, Herbie wrote: >> Would it be ok to have the filename in a new first column: >> >> X936 X937 X938 >> 01.txt Y516 >> 01.txt Y517 >> 01.txt Y518 >> 01.txt Y519 >> 01.txt Y520 >> >> 02.txt Y516 >> 02.txt Y517 >> 02.txt Y518 >> 02.txt Y519 >> 02.txt Y520 >> >> or something like: >> >> X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt >> X938_02.txt (watch for line breaks) >> Y516 >> Y517 >> Y518 >> Y519 >> Y520 >> >> or something along these lines: >> >> 01.txt X936 X937 X938 02.txt X936 X937 X938 >> Y516 Y516 >> Y517 Y517 >> Y518 Y518 >> Y519 Y519 >> Y520 Y520 >> >> >> AFAIK it is not possible to have numbers and letters in the same column >> except in the column headers. >> >> Please be aware of the fact that ImageJ is not a spread-sheet program, >> but serves for image processing in the first place. >> >> Regards >> >> Herbie >> >> :::::::::::::::::::::::::::::::::::::: >> Am 28.03.18 um 17:35 schrieb dschones: >>> Hi Herbie, >>> >>> I'll just leave the generation of the results as they are and give the >>> reference to the way I found getting the filename into first line of the >>> results.txt >>> >>> https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files >>> >>> <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> >>> >>> >>> Good afternoon! :) >> >> -- >> 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 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Stein,
a few remarks on tables: Beware that there are two different types of tables in ImageJ: (1) Tables like the ResultsTable, the one you get from Plots with "List", and tables with contents filled in by the new macro Table... commands are essentially numeric (there is a predefined "label" column, which must be the first one, this one is text-only). One can have non-numeric (String) values in other columns, then Table.get(colName, row) will give you NaN (not a number) and you need Table.getString(colName, row). But one would not do the for numbers; and applyMacro will work with the numeric value. For this type of tables, the column headers are fixed. The underlying data structure currently does not support renaming column headers. The column headers are simply created by assigning values to columns (by column name); if a column does not exist, it is created. (2) On the other hand, if you create a table by macro print commands, it is a pure list of Strings, with no numeric values behind it. You can't do any calculations with it, and the Table... commands don't work with it. The purpose of this type of table is only displaying values and saving or copying to the clipboard. This means that all commands using Strings like "Table.addRow(<tabdelimited string>)" for numeric tables would be problematic: It would require conversion of text to numbers; note that number>text>number conversion induces a loss of precision (unless the data are integer or the number of digits is very large). So it would be better to copy numeric values as such, not via String manipulation. Michael ________________________________________________________________ On 09/04/2018 17:07, Stein Rørvik wrote: > Thanks, exactly what I need. These functions will be very useful for manipulating an existing results table. > I already tried Table.applyMacro("Results", "DoubleArea=Area*2") with daily build 1.52a39 and it worked as expected. > > Today I use a similar approach as Timothy outlined: I create a new table, read the results from the old one, and use the getResult / setResult functions to create a new table. I also sometimes split lines and use the print(tablename, ... ) syntax to print tab-delimited headers and rows with the new table; this approach is much faster. > > To add to the below list, I think the functions Table.setHeader(<tabdelimited string>) > and Table.addRow(<tabdelimited string>), Table.updateRow(<rowindex>, <tabdelimited string>) > would be useful for writing contents in batch. > > Also, perhaps Table.headings() could be complemented with > Table.rows() to return all the rows (except the header) as tab-delimited strings concatenated by \n > as well as Table.content() to return everything as a string (headers plus all the rows) > > Stein > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid > Sent: 09. april 2018 16:33 > To: [hidden email] > Subject: Re: How to create a customised results table and add data to it within a macro > > Hi Stein, > > the Table.* functions are currently under development; they are in the daily build only. > > The list of currently implemented commands is in the Release notes: > https://github.com/imagej/imagej1/blob/master/release-notes.html > > Table.create() - opens a new table > Table.size() - number of rows in the table > Table.title() - title of the current table > Table.headings() - column headings as a tab-delimited string > Table.get(columnName, rowIndex) - returns a numeric value > Table.getString(columnName, rowIndex) - returns a string value > Table.set(columnName, rowIndex, value) - sets numeric or string value > Table.update() - updates table window > Table.reset() - resets (clears) the table > Table.applyMacro(macro) - applies macro code to table > Table.rename(title1, title2) - renames a table > Table.save(filePath) - saves the table > Table.deleteRows(index1, index2) - deletes specified rows > Table.deleteColumn(columnName) - deletes specified column > Table.hideRowNumbers() - disables display of row numbers > > > You can also specify the title of a table, this argument goes last. > > So e.g. the macro I had suggested last week has to be changed to: > myName = "01.txt"; > Table.applyMacro("_='"+myName+" '+_", "Results"); > > If no title is given, the commands refer the main "Results" table or to the current foreground window (if it has a table). > Inside the macro of 'apply macro', if no title is given, the Table commands refer to the table processed by the macro. > > Note that these commands are still experimental. Things may still change, so you may have to adapt your macros in case of changes! > > > Michael > ________________________________________________________________ > On 09/04/2018 12:43, Stein Rørvik wrote: >> Table.applyMacro seems very useful, but I cannot see it documented in the >> https://imagej.nih.gov/ij/developer/macro/functions.html webpage? >> Are there any other Table.* functions implemented in ImageJ ? >> >> Stein >> >> -----Original Message----- >> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid >> Sent: 28. mars 2018 18:51 >> To: [hidden email] >> Subject: Re: How to create a customised results table and add data to it within a macro >> >> Hi Herbie & dschones, >> >> the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with >> getResultLabel(row) and >> setResult("Label", row, string). >> >> With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: >> >> myName = "01.txt"; >> Table.applyMacro("Results", "_='"+myName+" '+_"); >> >> (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) >> >> This gives you a space, not a tab between the '01.txt' and the 'Y123' >> >> In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. >> >> By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: >> setResult("X123", 1, "hello"); >> >> >> Michael >> ________________________________________________________________ >> >> >> On 28/03/2018 17:58, Herbie wrote: >>> Would it be ok to have the filename in a new first column: >>> >>> X936 X937 X938 >>> 01.txt Y516 >>> 01.txt Y517 >>> 01.txt Y518 >>> 01.txt Y519 >>> 01.txt Y520 >>> >>> 02.txt Y516 >>> 02.txt Y517 >>> 02.txt Y518 >>> 02.txt Y519 >>> 02.txt Y520 >>> >>> or something like: >>> >>> X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt >>> X938_02.txt (watch for line breaks) >>> Y516 >>> Y517 >>> Y518 >>> Y519 >>> Y520 >>> >>> or something along these lines: >>> >>> 01.txt X936 X937 X938 02.txt X936 X937 X938 >>> Y516 Y516 >>> Y517 Y517 >>> Y518 Y518 >>> Y519 Y519 >>> Y520 Y520 >>> >>> >>> AFAIK it is not possible to have numbers and letters in the same column >>> except in the column headers. >>> >>> Please be aware of the fact that ImageJ is not a spread-sheet program, >>> but serves for image processing in the first place. >>> >>> Regards >>> >>> Herbie >>> >>> :::::::::::::::::::::::::::::::::::::: >>> Am 28.03.18 um 17:35 schrieb dschones: >>>> Hi Herbie, >>>> >>>> I'll just leave the generation of the results as they are and give the >>>> reference to the way I found getting the filename into first line of the >>>> results.txt >>>> >>>> https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files >>>> >>>> <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> >>>> >>>> >>>> Good afternoon! :) >>> >>> -- >>> 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 >> > > -- > 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 |
Thank you for this clarification; I was not aware of this difference between string-based and numerical tables.
Could it still make sense with a Table.setHeader(<tabdelimited string>) command for newly created numerical tables? This would then create an empty table with the desired column headers in the desired order; instead of new columns just appearing in an arbitrary order at first use. One thing that annoys me with the existing Results table is that there is no Z column for calibrated Z positions, and the Feret shape parameters are not placed in any logical order. If one could pre-set the column order, that would fix this easily. For example, MinFeret, Feret, FeretAngle, FeretX, FeretY. Also, Table.applyMacro("Z=Slice*<MicronsPerPixelZ>","Result") would easily add the missing Z coordinate column. Stein -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid Sent: 09. april 2018 19:56 To: [hidden email] Subject: Re: How to create a customised results table and add data to it within a macro Hi Stein, a few remarks on tables: Beware that there are two different types of tables in ImageJ: (1) Tables like the ResultsTable, the one you get from Plots with "List", and tables with contents filled in by the new macro Table... commands are essentially numeric (there is a predefined "label" column, which must be the first one, this one is text-only). One can have non-numeric (String) values in other columns, then Table.get(colName, row) will give you NaN (not a number) and you need Table.getString(colName, row). But one would not do the for numbers; and applyMacro will work with the numeric value. For this type of tables, the column headers are fixed. The underlying data structure currently does not support renaming column headers. The column headers are simply created by assigning values to columns (by column name); if a column does not exist, it is created. (2) On the other hand, if you create a table by macro print commands, it is a pure list of Strings, with no numeric values behind it. You can't do any calculations with it, and the Table... commands don't work with it. The purpose of this type of table is only displaying values and saving or copying to the clipboard. This means that all commands using Strings like "Table.addRow(<tabdelimited string>)" for numeric tables would be problematic: It would require conversion of text to numbers; note that number>text>number conversion induces a loss of precision (unless the data are integer or the number of digits is very large). So it would be better to copy numeric values as such, not via String manipulation. Michael ________________________________________________________________ On 09/04/2018 17:07, Stein Rørvik wrote: > Thanks, exactly what I need. These functions will be very useful for manipulating an existing results table. > I already tried Table.applyMacro("Results", "DoubleArea=Area*2") with daily build 1.52a39 and it worked as expected. > > Today I use a similar approach as Timothy outlined: I create a new table, read the results from the old one, and use the getResult / setResult functions to create a new table. I also sometimes split lines and use the print(tablename, ... ) syntax to print tab-delimited headers and rows with the new table; this approach is much faster. > > To add to the below list, I think the functions Table.setHeader(<tabdelimited string>) > and Table.addRow(<tabdelimited string>), Table.updateRow(<rowindex>, <tabdelimited string>) > would be useful for writing contents in batch. > > Also, perhaps Table.headings() could be complemented with > Table.rows() to return all the rows (except the header) as tab-delimited strings concatenated by \n > as well as Table.content() to return everything as a string (headers plus all the rows) > > Stein > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid > Sent: 09. april 2018 16:33 > To: [hidden email] > Subject: Re: How to create a customised results table and add data to it within a macro > > Hi Stein, > > the Table.* functions are currently under development; they are in the daily build only. > > The list of currently implemented commands is in the Release notes: > https://github.com/imagej/imagej1/blob/master/release-notes.html > > Table.create() - opens a new table > Table.size() - number of rows in the table > Table.title() - title of the current table > Table.headings() - column headings as a tab-delimited string > Table.get(columnName, rowIndex) - returns a numeric value > Table.getString(columnName, rowIndex) - returns a string value > Table.set(columnName, rowIndex, value) - sets numeric or string value > Table.update() - updates table window > Table.reset() - resets (clears) the table > Table.applyMacro(macro) - applies macro code to table > Table.rename(title1, title2) - renames a table > Table.save(filePath) - saves the table > Table.deleteRows(index1, index2) - deletes specified rows > Table.deleteColumn(columnName) - deletes specified column > Table.hideRowNumbers() - disables display of row numbers > > > You can also specify the title of a table, this argument goes last. > > So e.g. the macro I had suggested last week has to be changed to: > myName = "01.txt"; > Table.applyMacro("_='"+myName+" '+_", "Results"); > > If no title is given, the commands refer the main "Results" table or to the current foreground window (if it has a table). > Inside the macro of 'apply macro', if no title is given, the Table commands refer to the table processed by the macro. > > Note that these commands are still experimental. Things may still change, so you may have to adapt your macros in case of changes! > > > Michael > ________________________________________________________________ > On 09/04/2018 12:43, Stein Rørvik wrote: >> Table.applyMacro seems very useful, but I cannot see it documented in the >> https://imagej.nih.gov/ij/developer/macro/functions.html webpage? >> Are there any other Table.* functions implemented in ImageJ ? >> >> Stein >> >> -----Original Message----- >> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid >> Sent: 28. mars 2018 18:51 >> To: [hidden email] >> Subject: Re: How to create a customised results table and add data to it within a macro >> >> Hi Herbie & dschones, >> >> the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with >> getResultLabel(row) and >> setResult("Label", row, string). >> >> With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: >> >> myName = "01.txt"; >> Table.applyMacro("Results", "_='"+myName+" '+_"); >> >> (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) >> >> This gives you a space, not a tab between the '01.txt' and the 'Y123' >> >> In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. >> >> By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: >> setResult("X123", 1, "hello"); >> >> >> Michael >> ________________________________________________________________ >> >> >> On 28/03/2018 17:58, Herbie wrote: >>> Would it be ok to have the filename in a new first column: >>> >>> X936 X937 X938 >>> 01.txt Y516 >>> 01.txt Y517 >>> 01.txt Y518 >>> 01.txt Y519 >>> 01.txt Y520 >>> >>> 02.txt Y516 >>> 02.txt Y517 >>> 02.txt Y518 >>> 02.txt Y519 >>> 02.txt Y520 >>> >>> or something like: >>> >>> X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt >>> X938_02.txt (watch for line breaks) >>> Y516 >>> Y517 >>> Y518 >>> Y519 >>> Y520 >>> >>> or something along these lines: >>> >>> 01.txt X936 X937 X938 02.txt X936 X937 X938 >>> Y516 Y516 >>> Y517 Y517 >>> Y518 Y518 >>> Y519 Y519 >>> Y520 Y520 >>> >>> >>> AFAIK it is not possible to have numbers and letters in the same column >>> except in the column headers. >>> >>> Please be aware of the fact that ImageJ is not a spread-sheet program, >>> but serves for image processing in the first place. >>> >>> Regards >>> >>> Herbie >>> >>> :::::::::::::::::::::::::::::::::::::: >>> Am 28.03.18 um 17:35 schrieb dschones: >>>> Hi Herbie, >>>> >>>> I'll just leave the generation of the results as they are and give the >>>> reference to the way I found getting the filename into first line of the >>>> results.txt >>>> >>>> https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files >>>> >>>> <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> >>>> >>>> >>>> Good afternoon! :) >>> >>> -- >>> 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 >> > > -- > 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Stein,
the standard headings of the ResultsTable are hardcoded. Unfortunately one cannot easily change this since it would break user plugins that access them by their number. This is also the reason for the non-intuitive ordering of the Feret items; "Feret" (min Feret diameter) was in ImageJ since the early days; the others were added later, when a few additional columns were already in between. (In principle this could be changed, but it would be some effort; it would require a translation table from the old numbers to the corresponding headings). Scaled Z: Yes, you can have a macro for this like, e.g. Table.applyMacro("x=0; y=0; Z=Slice-1; toScaled(x,y,Z);"); (It assumes that the current image window has the same calibration as the Results table; it also accounts for any offset of the origin in z direction). Michael ________________________________________________________________ On 09/04/2018 22:32, Stein Rørvik wrote: > Thank you for this clarification; I was not aware of this difference between string-based and numerical tables. > > Could it still make sense with a Table.setHeader(<tabdelimited string>) command for newly created numerical tables? > > This would then create an empty table with the desired column headers in the desired order; instead of new columns just appearing in an arbitrary order at first use. One thing that annoys me with the existing Results table is that there is no Z column for calibrated Z positions, and the Feret shape parameters are not placed in any logical order. If one could pre-set the column order, that would fix this easily. For example, MinFeret, Feret, FeretAngle, FeretX, FeretY. Also, Table.applyMacro("Z=Slice*<MicronsPerPixelZ>","Result") would easily add the missing Z coordinate column. > > Stein > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid > Sent: 09. april 2018 19:56 > To: [hidden email] > Subject: Re: How to create a customised results table and add data to it within a macro > > Hi Stein, > > a few remarks on tables: > > Beware that there are two different types of tables in ImageJ: > > (1) Tables like the ResultsTable, the one you get from Plots with "List", and tables with contents filled in by the new macro Table... > commands are essentially numeric (there is a predefined "label" column, which must be the first one, this one is text-only). > > One can have non-numeric (String) values in other columns, then Table.get(colName, row) will give you NaN (not a number) and you need Table.getString(colName, row). But one would not do the for numbers; and applyMacro will work with the numeric value. > > For this type of tables, the column headers are fixed. The underlying data structure currently does not support renaming column headers. > The column headers are simply created by assigning values to columns (by column name); if a column does not exist, it is created. > > (2) On the other hand, if you create a table by macro print commands, it is a pure list of Strings, with no numeric values behind it. You can't do any calculations with it, and the Table... commands don't work with it. The purpose of this type of table is only displaying values and saving or copying to the clipboard. > > > This means that all commands using Strings like "Table.addRow(<tabdelimited string>)" for numeric tables would be > problematic: It would require conversion of text to numbers; note that > number>text>number conversion induces a loss of precision (unless the > data are integer or the number of digits is very large). > > So it would be better to copy numeric values as such, not via String > manipulation. > > > Michael > ________________________________________________________________ > > > On 09/04/2018 17:07, Stein Rørvik wrote: >> Thanks, exactly what I need. These functions will be very useful for manipulating an existing results table. >> I already tried Table.applyMacro("Results", "DoubleArea=Area*2") with daily build 1.52a39 and it worked as expected. >> >> Today I use a similar approach as Timothy outlined: I create a new table, read the results from the old one, and use the getResult / setResult functions to create a new table. I also sometimes split lines and use the print(tablename, ... ) syntax to print tab-delimited headers and rows with the new table; this approach is much faster. >> >> To add to the below list, I think the functions Table.setHeader(<tabdelimited string>) >> and Table.addRow(<tabdelimited string>), Table.updateRow(<rowindex>, <tabdelimited string>) >> would be useful for writing contents in batch. >> >> Also, perhaps Table.headings() could be complemented with >> Table.rows() to return all the rows (except the header) as tab-delimited strings concatenated by \n >> as well as Table.content() to return everything as a string (headers plus all the rows) >> >> Stein >> >> -----Original Message----- >> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid >> Sent: 09. april 2018 16:33 >> To: [hidden email] >> Subject: Re: How to create a customised results table and add data to it within a macro >> >> Hi Stein, >> >> the Table.* functions are currently under development; they are in the daily build only. >> >> The list of currently implemented commands is in the Release notes: >> https://github.com/imagej/imagej1/blob/master/release-notes.html >> >> Table.create() - opens a new table >> Table.size() - number of rows in the table >> Table.title() - title of the current table >> Table.headings() - column headings as a tab-delimited string >> Table.get(columnName, rowIndex) - returns a numeric value >> Table.getString(columnName, rowIndex) - returns a string value >> Table.set(columnName, rowIndex, value) - sets numeric or string value >> Table.update() - updates table window >> Table.reset() - resets (clears) the table >> Table.applyMacro(macro) - applies macro code to table >> Table.rename(title1, title2) - renames a table >> Table.save(filePath) - saves the table >> Table.deleteRows(index1, index2) - deletes specified rows >> Table.deleteColumn(columnName) - deletes specified column >> Table.hideRowNumbers() - disables display of row numbers >> >> >> You can also specify the title of a table, this argument goes last. >> >> So e.g. the macro I had suggested last week has to be changed to: >> myName = "01.txt"; >> Table.applyMacro("_='"+myName+" '+_", "Results"); >> >> If no title is given, the commands refer the main "Results" table or to the current foreground window (if it has a table). >> Inside the macro of 'apply macro', if no title is given, the Table commands refer to the table processed by the macro. >> >> Note that these commands are still experimental. Things may still change, so you may have to adapt your macros in case of changes! >> >> >> Michael >> ________________________________________________________________ >> On 09/04/2018 12:43, Stein Rørvik wrote: >>> Table.applyMacro seems very useful, but I cannot see it documented in the >>> https://imagej.nih.gov/ij/developer/macro/functions.html webpage? >>> Are there any other Table.* functions implemented in ImageJ ? >>> >>> Stein >>> >>> -----Original Message----- >>> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid >>> Sent: 28. mars 2018 18:51 >>> To: [hidden email] >>> Subject: Re: How to create a customised results table and add data to it within a macro >>> >>> Hi Herbie & dschones, >>> >>> the first column with the 'Y123' etc. is the "row label", not a standard column. In a macro, you can get and set it with >>> getResultLabel(row) and >>> setResult("Label", row, string). >>> >>> With today's daily build (Help>Update ImageJ), you can also modify it without a loop over all rows: >>> >>> myName = "01.txt"; >>> Table.applyMacro("Results", "_='"+myName+" '+_"); >>> >>> (Since the "row label" column has an empty name in this case, its name is mapped to an underscore as variable name.) >>> >>> This gives you a space, not a tab between the '01.txt' and the 'Y123' >>> >>> In principle, one could add a tab, but that would shift all columns to the right. The headers won't get shifted, and I don't think that one could also shift the headers. >>> >>> By the way, you can have Strings and numbers mixed in one column, but it won't help you here. E.g., if there is a column "X123", this works: >>> setResult("X123", 1, "hello"); >>> >>> >>> Michael >>> ________________________________________________________________ >>> >>> >>> On 28/03/2018 17:58, Herbie wrote: >>>> Would it be ok to have the filename in a new first column: >>>> >>>> X936 X937 X938 >>>> 01.txt Y516 >>>> 01.txt Y517 >>>> 01.txt Y518 >>>> 01.txt Y519 >>>> 01.txt Y520 >>>> >>>> 02.txt Y516 >>>> 02.txt Y517 >>>> 02.txt Y518 >>>> 02.txt Y519 >>>> 02.txt Y520 >>>> >>>> or something like: >>>> >>>> X936_01.txt X937_01.txt X938_01.txt X936_02.txt X937_02.txt >>>> X938_02.txt (watch for line breaks) >>>> Y516 >>>> Y517 >>>> Y518 >>>> Y519 >>>> Y520 >>>> >>>> or something along these lines: >>>> >>>> 01.txt X936 X937 X938 02.txt X936 X937 X938 >>>> Y516 Y516 >>>> Y517 Y517 >>>> Y518 Y518 >>>> Y519 Y519 >>>> Y520 Y520 >>>> >>>> >>>> AFAIK it is not possible to have numbers and letters in the same column >>>> except in the column headers. >>>> >>>> Please be aware of the fact that ImageJ is not a spread-sheet program, >>>> but serves for image processing in the first place. >>>> >>>> Regards >>>> >>>> Herbie >>>> >>>> :::::::::::::::::::::::::::::::::::::: >>>> Am 28.03.18 um 17:35 schrieb dschones: >>>>> Hi Herbie, >>>>> >>>>> I'll just leave the generation of the results as they are and give the >>>>> reference to the way I found getting the filename into first line of the >>>>> results.txt >>>>> >>>>> https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files >>>>> >>>>> <https://askubuntu.com/questions/1019727/inserting-file-name-in-first-line-of-merged-txt-files> >>>>> >>>>> >>>>> Good afternoon! :) >>>> >>>> -- >>>> 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 >>> >> >> -- >> 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 > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |