Skip to main content
Version: 2023.09.1

Custom

Run Script

If Run Script is selected as the post process step, Visiopharm will execute an R-script, hence allowing you to create your own post process operation. The file follows the standard UTF8 text file format, and uses US locale for all numbers (. As Decimal separator). The file can contain any number of lines and variables in any format. Anything after a # in a line will be regarded as comments. The label, ROI and input image are passed as arguments when running the R script. Extract them with the line:

args <- commandArgs(trailingOnly=TRUE)

Where args[1] contains the label image, args[2] the ROI image and args[3] the input image. Load these images as arrays of type 'double' with the function readTIFF. This requires that the tiff package for R is installed and loaded (used instead of rtiff package). The package is installed and loaded with the following commands:

install.packages("tiff")
library(tiff)

The modified images can be written back to the arguments with the writeTIFF command. This line will write the label image back:

writeTIFF(label, args[1])

If your R script throws a warning, the execution will stop even though the script can be executed. To run the script ignoring warnings use the command

Options(warn=-1)