SRView's "Rotate - active image" Script
SRView's "Rotate - batch" Script
interp3d: A commandline interpolation and rotation program
Back to User's Manual Table of Contents
Additionally, the SRIP package includes a commandline program called interp3d, which can be used for transformation and interpolation of images. SRView's rotation scripts call interp3d to do the computations for rotation and resampling. interp3d can be called directly from the commandline of a terminal window.
When you run the script, a message is posted informing you that it will take a few minutes and that you can continue working while the rotated image is being calculated. When the calculations are done, the message disappears and the bell is sounded to alert you that the new image is ready.
The new image will appear under the Images menu with the same name as the original image except Rot is added to the end of the name, but before any extension introduced by a period.
The calculations are done using the standalone commandline program called
interp3d.
The new image will be sampled on a 256 x 256 x 256 matrix with 1 mm sampling
intervals in all directions. The resampling is done with cubic spline
interpolation. If you wish to specify a different matrix, different
sampling interval, or different interpolation, you must use the Rotate
- batch script.
Before invoking this script you should prepare a directory with images you wish to process. The images must have the usual .img extension. The rotation to be applied to each image must be stored as a 4x4 transformation matrix in a scan analysis file of the same name as the image, but with a .paf extension. This is the way things usually are if you have used SRView to view and dynamically rotate the image, and then saved the image from SRView with the desired rotation.If an image does not have a matching .paf file, one will be created for it containing an identity transformation.
If an image has a matching .paf file, but that file does not contain a transformation matrix, the image will not be processed.
The new, rotated images will be written to files with the same names as the unrotated images but with Rot appended prior to the .img extension. For example, if the original image were named foobar.img, the rotated image would be named foobarRot.img.
To prevent accidental reprocessing of images, the script excludes from processing all images for which there is a matching Rot image file, and all Rot image files. These restrictions make it possible to add more image files to an already processed directory, and run the script again to process the newly added images.

Directory
Enter the directory to process.Output image parameters
Enter the output image matrix dimensions, and sampling intervals you want.The text window
The text window shows a history of all the images processed. Also, error messages will logged in the text window.Input and output planes
The input and output plane buttons are popup option menus from which you can select axial, sagittal or coronal. These should be used only if you want the output image to be "resliced" to a different plane in addition to having the rotation applied from the transformation matrix.If input and output plane are the same, then no additional rotation is applied despite the specific setting of these options. For example, having input and output plane set to COR, is all right for processing axial, sagittal and coronal images since in all cases no additional rotation is being applied. The settings are only important when input plane and output plane are set to different values.
The matrix dimensions and sampling intervals specified in the output image parameters box are those of the final image after the application of the tranformation matrix from the .paf file and after rotations applied as a result of setting output plane different from input plane.
If you specify different input and output planes, that is implemented by modifying the transformation matrices stored in the .paf files to include the necessary rotation to achive the specified outplane. Therefore, after the processing is complete, the rotation matrices in the original .paf files will have been altered to reflect the true total rotation applied to the image. If you interrupt the processing by pressing the STOP button, that will leave the images that have been processed up to that point with .paf files with the new rotation matrix, and the rest with their original matrix. In that case you can recover the original .paf files for the images that have already been processed from copies that have been saved with .brTmp extensions. These temporary copies are automatically deleted on normal completion of processing, but are left around if you abort processing by pressing the STOP button. Keep in mind that all of this is only an issue if you specify an output plane different from the input plane.
Interpolation
The interpolation button is a popup option menu. Use it to select the type of interpolation you want for the image resampling. There are two choices: Nearest Neighbor and Cubic Spline. Nearest neighbor interpolation is very fast - on the order of 5 seconds - but gives a jagged looking image. The jagged look is especially noticeable for images with low matrix size in one or more dimensions. Cubic spline interpolation gives a very nice looking image without the jagged appearance, but takes three to five minutes for a typical 256x256 x256 image. The choice of interpolation method should be based on the intended use for the rotated image, not the processing time. For most purposes cubic spline interpolation is the more appropriate choice.RUN button
Press this to start the processing. This will turn to a STOP button while images are being processed.EXIT button
Press this to exit the script. This button is disabled while the script is running. You must STOP the script in order to exit.
The rotation calculations typically take several minutes per image. You cannot close out the user interface window while the script is running, since that is where messages are logged. However, while the script is running you may wish to iconify the interface window to get it out of the way.You can continue to work in SRView while the script is running. Be aware that what you do in SRView will be competing with the script for memory and CPU time, so depending on the capabilities of your computer, both SRView and the script calculations may be somewhat slower than when they are running by themselves.
A message is posted in the text window when processing is completed. The new images will be in the same directory as the originals, and will have the same names as the originals but with Rot appended prior to any extensions.