Phriction Projects Wikis Bioimaging And Optics Platform ImageJ Tools Biop Library Functions History Version 1 vs 7
Version 1 vs 7
Version 1 vs 7
Edits
Edits
- Move Away by romainGuiet, Version 7
- Aug 9 2017 14:17
- Edit by oburri, Version 1
- Jan 17 2017 11:02
- ·First commit
Edit Older Version 1... |
Content Changes
Content Changes
= Using the BIOP Library =
Before you start using the BIOP library, you need to define a function called `toolName()` that returns a string.
This string will serve as the name of the text window that will contain the parameters
```lang=javascript
function toolName() {
return "My Custom Tool";
}
```
= Data Handling =
== getData(key) ==
Based on an example by Wayne Rasband, we use the "getData" and "setData" functions to read and write data to and from an opened text window. This allows us to save parameters for an ActionBar in a visible way for the user, instead of relying on IJ.prefs.
```lang=java
something = getData("Something");
```
==getDataD(key, default) ==
When getData does not find the key, it returns an empty string `""`. This function makes sure that a default value is returned in case that the key does not exist. **Recommended over getData()**.
== getBool(key) ==
Getter for boolean values. When there is a value of //true// it records //Yes// on the text window and in case of //false// it records //No//
==getBoolD(key, default) ==
Getter for boolean values with defaults
== getDataArray(key,separator) ==
This function recovers the string associated with the requested key and returns an array by splitting the string using the provided separator argument.
== getDataArray(key,separator, defaultArray) ==
Getter for array with defaults.
== setData(key, value) ==
Sets the current key to the current value. Can be string or number. Incase of boolean, use **setBool** instead.
== setBool(key, bool) ==
Sets the key to //Yes// or //No//, depending on the value of bool.
== setDataArray(key,array, separator) ==
In case you want to save Arrays, this function explodes it into a String with the chosen separator. Use the same separator to retrieve it.
== promptParameters(names, types, defaults) ==
Allows to automatically create a dialog with defined names and defaults, and also stores them directly into the text window. It also remembers the previous settings if you call it again.
Each of the 3 arguments is an array with the same number of elements.
=== names ===
Contains an array with the names (keys) of the parameters you want to promt the user.
(NOTE) `names = newArray("Gaussian Filter Size", "Channel of Interest", "Threshold Method");`
=== Types ===
Shoud be an array with the following strings , of the same size as **names**
|String| Meaning |
|-------|-----------|
|"s"| String Dialog|
|"c" | Checkbox|
|"n" | Number|
|"m" | Message|
|"thr" | Threshold List|
|"lut" | LUT List|
(NOTE) `types = newArray("n", "n", "thr");`
=== Defaults ===
This should be an array with the default values for each key you have entered. Again, it should have the same length as the **names** argument.
(NOTE) `defaults = newArray(2.0, 1, "Otsu");`
==loadParameters()==
Loads a text file with a previous parameter set.
== saveParameters()
Shows the user a file save dialog where they can save a text file with the currently active parameters.
= File Handling =
== getImageFolder() ==
Returns the current value of the 'Image Folder' key in the parameters window. If it's not set, it calls **setImageFolder**.
== setImageFolder(title) ==
Displays a getDirectory dialog box and save the value under the 'Image Folder' key in the parameters window.
== getSaveFolder() ==
Returns the current value of the 'Save Folder' key in the parameters window. If it's not set, it calls **setSaveFolder**.
== setSaveFolder() ==
Sets the Save folder as a subfolder of the Image Folder and adds a 'Save Folder' key to the parameters window.
==getNumberImages() ==
Returns the number of image files in the 'Image Folder'.
== isImage(filename) ==
Returns //true// if the current file is an image. It is mostly used internally.
== openImage(n) ==
By using **isImage** and **getNumberImages**, we can now open the nth image from a folder easily. This is useful when running a batch on a folder
== getImagesList() ==
This function returns a list of image names from the current image folder. Mostly internal.
== selectImageDialog() ==
Displays a simple dialog to open images and their associated RoiSets in the current folder.
== saveCurrentImage() ==
Saves the current image as a TIFF in the SaveFolder
==saveCurrentImageAs(fileFormat) ==
Saves the current image as a Specified Format in the SaveFolder
= ROI Functions ==
== hasRoiSet(file)
Simple function to check the presence of a ROI set.
The macros here use a function called getRoiDir to get which is the folder that should contain the ROI sets.
The ROI set must have EXACTLY the same name as the filename and end in '.zip'.
== openRoiSet(file) ==
Opens the ROIs associated with the image 'file' if it exists
== getRoiFolder(mode) ==
Returns the directory where the ROIs are stored, a subfolder of the image folder.
===mode===
either "Open" which returns the ROIset Directory from the 'Image Folder', "Save" which returns the ROIset Directory from the 'Processed' folder.
== saveRois(mode) ==
Saves the ROIs of the current image.
===mode===
either "Open" which will associate the ROIset with the original image, or "Save" which saves the ROIset in the 'Processed' folder.
== renameLastRoi(name) ==
Allows for easily renaming the last added ROI
== renameROI(firstROI,lastRoi,patternName,separator, padding) ==
Allows for easily renaming ROIs , from the firstROI to the lastRoi (included) using patternName, the given separator and choice of padding
(NOTE) `renameROI(0,10,"MyROI", "-", 00);` //Renames 11 ROIs to 'MyROI-XX'
== findRoiWithName(roiName) ==
Returns index of first ROI that matches the given regular expression
==findRoisWithName(roiName) ==
Returns an array of indexes of ROIs that match the given regular expression
== DrawRoisL(category) ==
Function to draw ROIs using right click button. Give it a category name and it will do the rest.
The user draws the ROI and right, clicks when he is ready to store it in the RoiManager. When the user wants to stop, he can press ALT.
== convexHullEachRoi() ==
This function calculates the convex hull of each ROI in the RoiManager and updates them
= Results Table and Results Functions =
== writeResults(tableName, column, row, value) ==
This function writes a result to a results table called 'tableName', at the given column.
=== row ===
it can be:
- a specified row (specify a number)
- the current row (nResults-1)
- the next row (nResults)
== prepareTable(tableName) ==
Prepare a new table or an existing table to receive results. We can then use getResult, setResults, nResults as wanted.
== closeTable(tableName) ==
Once we are done updating the results, close the results table, and give it its final name
== initializeResultsFile(savingPath, fileName, columnsNamesArray) ==
Initializes such a file, using an array containing the Columns names.
The function requires the function(s) :
- getSaveFolder();
The required arguments are:
- fileName (as a string)
- columns names (as a array)
The file is deleted if it already exists!
It makes a string from the column names and appends this string to the file that makes it the 1st row of the file!
== appendRowToResultsFile(savingPath, fileName, array) ==
Appends an array to the existing file.
The required arguments are:
- fileName (as a string)
- the results for each columns (as an array)
== getValueFromArray(key,columnNames,array) ==
To store data in multiple tables faster than using the ImageJ Results tables we can write directly a row within a file.
getValueFromArray can be a usefull function to retrieve a value if you know the :
- the columns names
- the key for the value of interest
== setValueInArray(key,value,columnNames, array) ==
To store data in multiple tables faster than using the ImageJ Results tables we can write directly a row within a file.
getValueFromArray can be a usefull function to retrieve a value if you know :
- the columns names
- the key for the value of interest
== findIndex(key,columnNames) ==
Can be a usefull function to store a value in an array if you know. Mostly internal.
- the columns names
- the key for the value of interest
= Using the BIOP Library =
Before you start using the BIOP library, you need to define a function called `toolName()` that returns a string.
This string will serve as the name of the text window that will contain the parameters
```lang=javascript
function toolName() {
return "My Custom Tool";
}
```
= Data Handling =
== getData(key) ==
Based on an example by Wayne Rasband, we use the "getData" and "setData" functions to read and write data to and from an opened text window. This allows us to save parameters for an ActionBar in a visible way for the user, instead of relying on IJ.prefs.
```lang=java
something = getData("Something");
```
==getDataD(key, default) ==
When getData does not find the key, it returns an empty string `""`. This function makes sure that a default value is returned in case that the key does not exist. **Recommended over getData()**.
== getBool(key) ==
Getter for boolean values. When there is a value of //true// it records //Yes// on the text window and in case of //false// it records //No//
==getBoolD(key, default) ==
Getter for boolean values with defaults
== getDataArray(key,separator) ==
This function recovers the string associated with the requested key and returns an array by splitting the string using the provided separator argument.
== getDataArray(key,separator, defaultArray) ==
Getter for array with defaults.
== setData(key, value) ==
Sets the current key to the current value. Can be string or number. Incase of boolean, use **setBool** instead.
== setBool(key, bool) ==
Sets the key to //Yes// or //No//, depending on the value of bool.
== setDataArray(key,array, separator) ==
In case you want to save Arrays, this function explodes it into a String with the chosen separator. Use the same separator to retrieve it.
== promptParameters(names, types, defaults) ==
Allows to automatically create a dialog with defined names and defaults, and also stores them directly into the text window. It also remembers the previous settings if you call it again.
Each of the 3 arguments is an array with the same number of elements.
=== names ===
Contains an array with the names (keys) of the parameters you want to promt the user.
(NOTE) `names = newArray("Gaussian Filter Size", "Channel of Interest", "Threshold Method");`
=== Types ===
Shoud be an array with the following strings , of the same size as **names**
|String| Meaning |
|-------|-----------|
|"s"| String Dialog|
|"c" | Checkbox|
|"n" | Number|
|"m" | Message|
|"thr" | Threshold List|
|"lut" | LUT List|
(NOTE) `types = newArray("n", "n", "thr");`
=== Defaults ===
This should be an array with the default values for each key you have entered. Again, it should have the same length as the **names** argument.
(NOTE) `defaults = newArray(2.0, 1, "Otsu");`
==loadParameters()==
Loads a text file with a previous parameter set.
== saveParameters()
Shows the user a file save dialog where they can save a text file with the currently active parameters.
= File Handling =
== getImageFolder() ==
Returns the current value of the 'Image Folder' key in the parameters window. If it's not set, it calls **setImageFolder**.
== setImageFolder(title) ==
Displays a getDirectory dialog box and save the value under the 'Image Folder' key in the parameters window.
== getSaveFolder() ==
Returns the current value of the 'Save Folder' key in the parameters window. If it's not set, it calls **setSaveFolder**.
== setSaveFolder() ==
Sets the Save folder as a subfolder of the Image Folder and adds a 'Save Folder' key to the parameters window.
==getNumberImages() ==
Returns the number of image files in the 'Image Folder'.
== isImage(filename) ==
Returns //true// if the current file is an image. It is mostly used internally.
== openImage(n) ==
By using **isImage** and **getNumberImages**, we can now open the nth image from a folder easily. This is useful when running a batch on a folder
== getImagesList() ==
This function returns a list of image names from the current image folder. Mostly internal.
== selectImageDialog() ==
Displays a simple dialog to open images and their associated RoiSets in the current folder.
== saveCurrentImage() ==
Saves the current image as a TIFF in the SaveFolder
==saveCurrentImageAs(fileFormat) ==
Saves the current image as a Specified Format in the SaveFolder
= ROI Functions ==
== hasRoiSet(file)
Simple function to check the presence of a ROI set.
The macros here use a function called getRoiDir to get which is the folder that should contain the ROI sets.
The ROI set must have EXACTLY the same name as the filename and end in '.zip'.
== openRoiSet(file) ==
Opens the ROIs associated with the image 'file' if it exists
== getRoiFolder(mode) ==
Returns the directory where the ROIs are stored, a subfolder of the image folder.
===mode===
either "Open" which returns the ROIset Directory from the 'Image Folder', "Save" which returns the ROIset Directory from the 'Processed' folder.
== saveRois(mode) ==
Saves the ROIs of the current image.
===mode===
either "Open" which will associate the ROIset with the original image, or "Save" which saves the ROIset in the 'Processed' folder.
== renameLastRoi(name) ==
Allows for easily renaming the last added ROI
== renameROI(firstROI,lastRoi,patternName,separator, padding) ==
Allows for easily renaming ROIs , from the firstROI to the lastRoi (included) using patternName, the given separator and choice of padding
(NOTE) `renameROI(0,10,"MyROI", "-", 00);` //Renames 11 ROIs to 'MyROI-XX'
== findRoiWithName(roiName) ==
Returns index of first ROI that matches the given regular expression
==findRoisWithName(roiName) ==
Returns an array of indexes of ROIs that match the given regular expression
== DrawRoisL(category) ==
Function to draw ROIs using right click button. Give it a category name and it will do the rest.
The user draws the ROI and right, clicks when he is ready to store it in the RoiManager. When the user wants to stop, he can press ALT.
== convexHullEachRoi() ==
This function calculates the convex hull of each ROI in the RoiManager and updates them
= Results Table and Results Functions =
== writeResults(tableName, column, row, value) ==
This function writes a result to a results table called 'tableName', at the given column.
=== row ===
it can be:
- a specified row (specify a number)
- the current row (nResults-1)
- the next row (nResults)
== prepareTable(tableName) ==
Prepare a new table or an existing table to receive results. We can then use getResult, setResults, nResults as wanted.
== closeTable(tableName) ==
Once we are done updating the results, close the results table, and give it its final name
== initializeResultsFile(savingPath, fileName, columnsNamesArray) ==
Initializes such a file, using an array containing the Columns names.
The function requires the function(s) :
- getSaveFolder();
The required arguments are:
- fileName (as a string)
- columns names (as a array)
The file is deleted if it already exists!
It makes a string from the column names and appends this string to the file that makes it the 1st row of the file!
== appendRowToResultsFile(savingPath, fileName, array) ==
Appends an array to the existing file.
The required arguments are:
- fileName (as a string)
- the results for each columns (as an array)
== getValueFromArray(key,columnNames,array) ==
To store data in multiple tables faster than using the ImageJ Results tables we can write directly a row within a file.
getValueFromArray can be a usefull function to retrieve a value if you know the :
- the columns names
- the key for the value of interest
== setValueInArray(key,value,columnNames, array) ==
To store data in multiple tables faster than using the ImageJ Results tables we can write directly a row within a file.
getValueFromArray can be a usefull function to retrieve a value if you know :
- the columns names
- the key for the value of interest
== findIndex(key,columnNames) ==
Can be a usefull function to store a value in an array if you know. Mostly internal.
- the columns names
- the key for the value of interest
c4science · Help