ITK Pre-Processing Algorithm Wrappers in Python
m |
m |
||
Line 71: | Line 71: | ||
==='''How to run the scripts?'''=== | ==='''How to run the scripts?'''=== | ||
− | All the scripts are written in Python, and to run these one must have a version of Python installed in their machine. In addition, one should also have an installation of ITK along with the Python wrappers using CSwig enabled. For more details about how to install ITK with the Python wraps, please visit the [http://www.vtk.org/Wiki/ITK_Python_Wrapping | + | |
+ | '''Requirements''' | ||
+ | All the scripts are written in Python, and to run these one must have a version of Python installed in their machine. In addition, one should also have an installation of ITK along with the Python wrappers using CSwig enabled. For more details about how to install ITK with the Python wraps, please visit the [http://www.vtk.org/Wiki/ITK_Python_Wrapping ITK Python Wrapping] page. Please note that the Python that is used for running the scripts mentioned in this page, and the Python version used in the ITK installation should be the same. Once these are setup, we move to actually run the scripts. | ||
+ | |||
+ | '''Execution''' | ||
+ | The main script is process.py, which is the function to be called. Based on the arguments to the function, the user will be asked to enter the parameters to the algorithm. There are two main ways of executing the scripts - | ||
+ | *1. Not specifying parameters - in the method, the user does not specify the parameters, and the script will ask the user to input the algorithm of choice, and also the parameters. There are multiple ways of running the script. Here are a couple of ways. | ||
+ | ''python'' process.py | ||
+ | *This is the simplest way of implementing the code, assuming the user is in the same directory as the file process.py. Else the user will have to specify the path to the file process.py. This command will initiate a GUI that will ask the user to input an algorithm of choice. A URL is available on the right side of the page (currently points to this page) for help with the wrappers. On selecting an algorithm, one more URL appears providing a link to the wiki page for the corresponding filter. Once the user selects the algorithm, he/she presses the OK button to continue. A screenshot of the GUI is shows in Fig. 1. The figure shows the user having selected the sigmoid filter. | ||
+ | |||
+ | [[Image:Screenshot_listofalgorithms.JPG|center|frame|Fig. 1: GUI requesting user to enter the algorithm of choice.]] | ||
+ | * On selecting the filter, the interface now requests the user to enter the parameters of the algorithm. An example (for the sigmoid filter) is given in Fig. 2. Note that there are a lot of entries in the page. We describe each one of them below. | ||
+ | **1. Name of the algorithm - this describes the name of the algorithm, or to be more precise, the class in ITK that implements this algorithm. | ||
+ | **2. Key of the algorithm - the key to the algorihtm is used to access the algorithm details (the user need not worry about this for the time being). | ||
+ | **3. URL for help - on the right side, a URL is present for help on the filter chosen. | ||
+ | **4. Parameters - the next few lines show the various parameters of the algorithm and request the user to enter the values. For the time being, we have not implemented checks for the validity of the input in the scripts. In case a wrong value is entered, the ITK code will catch it and an error will be returned. The | ||
+ | [[Image:Screenshot_enterparameters.JPG|center|frame|Fig. 2: GUI requesting user to enter the details of the sigmoid algorithm.]] | ||
+ | **5. Output Image Pixel Type - this describes the image pixel type in the output image. For example, by choosing "8-bit" the user is expecting the output image to be store each pixel intensity in 1 byte. Note that only certain image formats are compatible with the float data-type. | ||
+ | **6. Input/Output image dimension - in the algorithms that are being considered, the input and output image dimensions are the same. This parameter gives the user the option to choose the dimension of the image. | ||
+ | **7. Input stack image and Output stack image - if the input/output image dimension is 3, then these check-boxes are activated and allow the user to input an image or output an image as a stack. | ||
+ | **8. Input file name/format - the name of the input file to be processed. The user can either type the path of the file, or use the "Browse" button to open a file dialog box from which he/she can choose the file name. Note that for image stacks, the user should enter the image file format in this column. For example, if the image files are named img0001.png, img0002.png, and so on, the format would be img%04d.png, where ''img'' is the prefix of the name, ''04'' indicates that the indices occupy 4 digits, and the leading digits are filled with zeros, and the extension of the files in ''png''. The path will still have to be specified. | ||
+ | **9. Output file name/format - this is the name of the ouput file name. The description is similar to the Input file name above. | ||
+ | **10. Start, End, and Increment Indices - these are activated when either the input or the output stack image check-boxes are selected. For example, if a user had a stack of 50 input images, with names img0001.png, img0002.png, ..., img0050.png, the start, end, and increment indices would be 1, 50, and 1, respectively. | ||
+ | **11. Filter Button - once all the parameters have been selected, the user should press the ''Filter'' button to start the filtering operation. |
Revision as of 06:34, 4 June 2009
Introduction
There are various pre-processing algorithms in the Insight Segmentation and Registration Toolkit (ITK). Python wraps for these algorithms exist; however, from a user's perspective, it is complicated and not so easy to run these algorithms. We intend to provide a Python script that can be used for invoking the Python wrappers to many of these algorithms, using a very simple interface. The user can just specify the smoothing algorithm to be used. For the parameters, the user can give the name of an XML file containing details of the algorithm, or alternatively, enter the details using a simple GUI. This page contains details about the algorithms that can be run using these scripts, and also help on how to run these scripts.
Here is a list of the pre-processing algorithms that have been added to the interface.
Algorithm Name | Algorithm key | ITK Class Name |
---|---|---|
Mean | Mean | itkMeanImageFilter |
Median | Median | itkMedianImageFilter |
Laplacian | Laplacian | itkLaplacianImageFilter |
Smoothing Recursive Gaussian | SmoothingRecursiveGaussian | itkSmoothingRecursiveGaussianImageFilter |
Grayscale Erode | GrayscaleErode | itkGrayscaleErodeImageFilter |
Grayscale Dilate | GrayscaleDilate | itkGrayscaleDilateImageFilter |
Flip | Flip | itkFlipImageFilter |
Normalize | Normalize | itkNormalizeFilter |
Shift and scale | ShiftScale | itkShiftScaleImageFilter |
Sobel Edge Detection | SobelEdgeDetection | itkSobelEdgeDetectionImageFilter |
Sigmoid | Sigmoid | itkSigmoidImageFilter |
Gradient Anisotropic Diffusion | GradientAnisotropicDiffusion | itkGradientAnisotropicDiffusionImageFilter |
Curvature Anisotropic Diffusion | CurvatureAnisotropicDiffusion | itkCurvatureAnisotropicDiffusionImageFilter |
Curvature Flow | CurvatureFlow | itkCurvatureFlowImageFilter |
Min-max Curvature Flow | MinMaxCurvatureFlow | itkMinMaxCurvatureFlowImageFilter |
How to run the scripts?
Requirements All the scripts are written in Python, and to run these one must have a version of Python installed in their machine. In addition, one should also have an installation of ITK along with the Python wrappers using CSwig enabled. For more details about how to install ITK with the Python wraps, please visit the ITK Python Wrapping page. Please note that the Python that is used for running the scripts mentioned in this page, and the Python version used in the ITK installation should be the same. Once these are setup, we move to actually run the scripts.
Execution The main script is process.py, which is the function to be called. Based on the arguments to the function, the user will be asked to enter the parameters to the algorithm. There are two main ways of executing the scripts -
- 1. Not specifying parameters - in the method, the user does not specify the parameters, and the script will ask the user to input the algorithm of choice, and also the parameters. There are multiple ways of running the script. Here are a couple of ways.
python process.py
- This is the simplest way of implementing the code, assuming the user is in the same directory as the file process.py. Else the user will have to specify the path to the file process.py. This command will initiate a GUI that will ask the user to input an algorithm of choice. A URL is available on the right side of the page (currently points to this page) for help with the wrappers. On selecting an algorithm, one more URL appears providing a link to the wiki page for the corresponding filter. Once the user selects the algorithm, he/she presses the OK button to continue. A screenshot of the GUI is shows in Fig. 1. The figure shows the user having selected the sigmoid filter.
- On selecting the filter, the interface now requests the user to enter the parameters of the algorithm. An example (for the sigmoid filter) is given in Fig. 2. Note that there are a lot of entries in the page. We describe each one of them below.
- 1. Name of the algorithm - this describes the name of the algorithm, or to be more precise, the class in ITK that implements this algorithm.
- 2. Key of the algorithm - the key to the algorihtm is used to access the algorithm details (the user need not worry about this for the time being).
- 3. URL for help - on the right side, a URL is present for help on the filter chosen.
- 4. Parameters - the next few lines show the various parameters of the algorithm and request the user to enter the values. For the time being, we have not implemented checks for the validity of the input in the scripts. In case a wrong value is entered, the ITK code will catch it and an error will be returned. The
- 5. Output Image Pixel Type - this describes the image pixel type in the output image. For example, by choosing "8-bit" the user is expecting the output image to be store each pixel intensity in 1 byte. Note that only certain image formats are compatible with the float data-type.
- 6. Input/Output image dimension - in the algorithms that are being considered, the input and output image dimensions are the same. This parameter gives the user the option to choose the dimension of the image.
- 7. Input stack image and Output stack image - if the input/output image dimension is 3, then these check-boxes are activated and allow the user to input an image or output an image as a stack.
- 8. Input file name/format - the name of the input file to be processed. The user can either type the path of the file, or use the "Browse" button to open a file dialog box from which he/she can choose the file name. Note that for image stacks, the user should enter the image file format in this column. For example, if the image files are named img0001.png, img0002.png, and so on, the format would be img%04d.png, where img is the prefix of the name, 04 indicates that the indices occupy 4 digits, and the leading digits are filled with zeros, and the extension of the files in png. The path will still have to be specified.
- 9. Output file name/format - this is the name of the ouput file name. The description is similar to the Input file name above.
- 10. Start, End, and Increment Indices - these are activated when either the input or the output stack image check-boxes are selected. For example, if a user had a stack of 50 input images, with names img0001.png, img0002.png, ..., img0050.png, the start, end, and increment indices would be 1, 50, and 1, respectively.
- 11. Filter Button - once all the parameters have been selected, the user should press the Filter button to start the filtering operation.