3DBasic Scripting Tool
3DBasic is a Basic-like scripting language implemented to allow programming with 3D-DOCTOR’s advanced image processing functions. This enables the user to perform sophisticated tasks in batch mode. A 3DBasic program can be created using a text editor, such as Windows NotePad or use 3D-DOCTOR’s 3DBasic/Create command. Use 3DBasic/Run to run an existing 3DBasic program directly.
3DBasic supports
most of the standard Basic commands,
including
ASSIGNMENT (=), PRINT, INPUT, IF, THEN, FOR, NEXT, TO, GOTO, GOSUB, RETURN, END and REM.
In addition, 3DBasic provides a new set of commands to provide enhanced functionality for programming and image processing . The new commands include:
LOGFILE, OPENIMAGE, SHOWIMAGE, CLOSEIMAGE, SAVEIMAGE, SAVEIMAGEPLANE, SETIMAGEPLANE, GETPIXEL, SETPIXEL, SIZEIMAGEUP, SIZEIMAGEDOWN, ROTATEIMAGE, CROPIMAGE, SEGMENTIMAGE, IMAGEDIM, OPENBOUNDARY, SAVEBOUNDARY, DECONVNN, DECONVMAX, SURFSIMPLE, SURFCOMPLEX and more are being implemented.
3DBasic supports different variable types, including INTEGER (32-bit long), FLOAT (64-bit double), STRING (variable length text string) and IMAGE3D (a data container for 3D images, boundaries, and other data).
The following are some examples of some commonly used 3DBasic programs.
Example for Image Segmentation:
- LOGFILE "c:\output.log"
- PRINT "THIS IS A 3D SEGMENTATION EXAMPLE"
- STRING FILENAME
- INTEGER X1, X2
- X1 = 51
- X2 = 186
- IMAGE3D image1
- INPUT "Enter image file name:", FILENAME
- PRINT FILENAME
- OPENIMAGE image1 FILENAME
- SEGMENTIMAGE image1 X1 X2
- SAVEBOUNDARY image1 "c:\test.bnd"
- SHOWIMAGE image1
- PRINT "FINISHED"
- END
Example for Simple Surface Rendering:
- LOGFILE "c:\ output.log"
- PRINT "THIS IS A SURFACE RENDERING PROGRAM"
- STRING FILENAME
- IMAGE3D image1
- INPUT "Enter image file name:", FILENAME
- PRINT FILENAME
- OPENIMAGE image1 FILENAME
- REM Assuming boundary data has been generated
- OPENBOUNDARY image1 "d:\test.bnd"
- SURFSIMPLE image1 "d:\test.suf"
- CLOSEIMAGE image1
- PRINT "FINISHED"
- END
Example for saving image slices to separate image files:
- LOGFILE "c:\output.log"
- INTEGER X
- STRING FILENAME, NAME1, NAME
- IMAGE3D image1
- NAME = "testimg"
- INPUT "Enter image file name:", FILENAME
- PRINT FILENAME
- OPENIMAGE image1 FILENAME
- REM saves image slices 1 to 10 to files testimage1 to testimage10
- FOR X = 1 TO 10
- NAME1 = NAME + X
- PRINT NAME1
- SAVEIMAGE image1 X X NAME1
- NEXT
- END
1. REM statement
This command indicates that the entire line following REM is only comment and will not affect the program execution.
Syntax:
- REM comment text
Example:
- REM this is a sample comment
- REM PRINT "This"
- REM the above line will do nothing
2. LOGFILE statement
This command defines the output file where it stores all information generated by the PRINT command. Besides the PRINT command, all error messages will also be saved to the log file.
Syntax:
- LOGFILE "c:\output.log"
- LOGFILE outputname
where, STRING outputname
This command can be used more than once in a program to define different log files for PRINT output.
3. INTEGER statement
INTEGER is used to declare integer variables.
Syntax:
- INTEGER I, J, K1
where, I, J, and K are the names of integer variables.
An integer variable is 32-bit long and must be declared before it is used in the program.
Example:
- LOGFILE "c:\output.log"
- INTEGER I, J
- I = 25
- J = I + 101
- PRINT "I=", I, "J=", J
- END
4. FLOAT statement
FLOAT is used to declare float variables.
Syntax:
- FLOAT X1, Y, y1
where, X1, Y, and y1 are the names of float variables.
Example:
- LOGFILE "c:\output.log"
- FLOAT X, Y
- INPUT "Enter X", X
- Y = X + 25.0
- PRINT "X=", X, "Y=", Y
- END
5. STRING statement
STRING is used to declare variables that are text string.
Syntax:
- STRING Name1, note, name2
where, Name1, note, and name2 are text strings.
Example:
- LOGFILE "c:\output.log"
- STRING Name1, Note
- INPUT "Enter Name", Name1
- Note = "The name is"
- Name1 = Note + Name1
- PRINT "New string is", Name1
- END
6. IMAGE3D statement
IMAGE3D is used to declare 3D image variables. IMAGE3D variables can contain image data, boundary data, and other types of data created using 3D-DOCTOR’s processing functions.
Syntax:
- IMAGE3D image1, Image10, T1
where, image1, Image10, and T1 are images.
Example:
- LOGFILE "c:\output.log"
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SHOWIMAGE image1
- END
7 ASSIGNMENT statement
Assignment statements are used to assign a value to a declared variable, which can be an integer, float, or string.
Syntax:
- <Variable> = <Expression>
Example:
- LOGFILE "c:\output.log"
- STRING Note
- INTEGER N
- FLOAT F1, F2
- Note = "This is the value for Note"
- N = 200
- F1 = 1.2*N
- F2 = F1 + N
- PRINT Note, N, F1, F2
- END
8. PRINT statement
The PRINT statement prints values of variables, expressions, and text strings to the file defined by the LOGFILE statement.
Syntax:
- PRINT <parameters>
Example:
- INTEGER I,
- FLOAT F
- STRING note
- I = 25
- F = 25.0
- note = "Just a note"
- PRINT "Test Print", note, I, F
- END
9. INPUT statement
The INPUT statement allows interactive assignment of values to variables.
Syntax:
- INPUT <Variable>
- INPUT "Prompt Text", <Variable>
Example:
- INTEGER I,
- FLOAT F
- STRING note
- INPUT "Enter I", I
- INPUT "Enter F", F
- INPUT "Enter Note", note
- PRINT "Test Input", note, I, F
- END
10. GOTO statement
The GOTO statement is one of several ways implemented in 3DBasic to control program flow.
Syntax:
- GOTO <Label>
where, the Label is a numeric value indicating the line where the program continues. 3DBasic does not require a Label for each line. Only a line that is a target line of a GOTO statement must have a label.
Example:
- INTEGER I
- INPUT "Enter I", I
- GOTO 200
- I = I*I
- 200 I = I+I
- PRINT "I =", I
- END
11. IF statement
The IF statement implemented in 3DBasic is slightly different from the standard Basic format. The ELSE statement is not supported and only "<", ">" and "=" can be used as operators.
Syntax:
- IF <Expression> <Operator> <Expression> THEN <LineLabel>
Example:
- INTEGER I
- INPUT "Enter I", I
- IF I > 10 THEN 200
- I = I * I
- PRINT "I < 10, I*I=", I
- 200 I = I + I
- PRINT "I > 10, I+I=", I
- END
12. FOR loop statement
The FOR loop allows implementing sophisticated programs to repeat certain operations with different variable values.
Syntax:
- FOR <Control Variable> = <Starting Value> TO <Ending Value>
- …
- Operations
- …
- NEXT
where, the "Control Variable" will start with the "Starting Value", and run the program through the "NEXT" statement and then increment the "Control Variable" by 1, and repeat the operation until the "Control Variable" is the same as the "Ending Value".
Example:
- INTEGER I, J
- FOR I = 0 TO 100
- J = J*I
- PRINT "J=", J
- NEXT
- END
13. GOSUB and RETURN statements
Same as the standard Basic, the use of GOSUB and RETURN allows implementation of subroutines.
Syntax:
- GOSUB <Label>
- …
- …
- <Label> (Subroutine starts)
- Subroutine body
- RETURN
Example:
- INTEGER I
- GOSUB 200
- PRINT "I=", I
- END
- 200 INPUT "I=", I
- RETURN
14. OPENIMAGE statement
This command opens an image or project file for processing. It is similar to the File/Open Image function.
Syntax:
- OPENIMAGE imagevar "filename"
- OPENIMAGE imagevar filename
where, IMAGE3D imagevar
STRING filename
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SHOWIMAGE image1
- END
15. SAVEIMAGE statement
This command saves specified image planes to a file where both start and end planes are included. The image must be currently open and the start and end planes must exist. If the start plane is the same as the end plane, then only this plane is saved. This command is similar to File/Save Image As command.
Syntax:
- SAVEIMAGE imagevar "filename" startplane endplane
- SAVEIMAGE imagevar filename startplane endplane
where, IMAGE3D imagevar, STRING filename, INTEGER startplane endplane
Example:
- LOGFILE "c:output.log"
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SAVEIMAGE image1 "c:\newfile.tif" 1 3
- END
16. SAVEIMAGEPLANE statement
This command saves the current active image plane to a file. An image plane can be set to active by using the SETIMAGEPLANE command.
Syntax:
- SAVEIMAGEPLANE imagevar "filename"
- SAVEIMAGEPLANE imagevar filename
where, IMAGE3D imagevar, STRING filename
Example:
- LOGFILE "c:output.log"
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SETIMAGEPLANE image1 3
- REM save image plane 3 to file
- SAVEIMAGEPLANE image1 "c:\3ddoctor\plane3.tif"
- END
17. SETIMAGEPLANE statement
This command sets a specified image plane as current for processing functions like GETPIXEL, SETPIXEL, and SAVEIMAGEPLANE. The image plane number must exist.
Syntax:
- SETIMAGEPLANE image planenum
where, IMAGE3D image, INTEGER planenum
Example:
- LOGFILE "c:output.log"
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- REM set image plane to 3
- SETIMAGEPLANE image1 3
- REM save image plane 3 to file
- SAVEIMAGEPLANE image1 "c:\3ddoctor\plane3.tif"
- END
18. IMAGEDIM statement
This function retrieves the image dimension values, including the number of columns, number of rows, and number of planes. The image must be opened before this command is used. This command is similar to Image/Information but with less parameters.
Syntax:
- IMAGEDIM image x y z
where, IMAGE3D image, INTEGER x y z
Example:
- LOGFILE "c:output.log"
- IMAGE3D image1
- INTEGER cols, rows, planes
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- IMAGEDIM image1 cols rows planes
- PRINT "Cols=", cols, "Rows=", rows, "Planes=", planes
- END
19. GETPIXEL statement
This function retrieves a pixel from the current plane of an opened image. The image must be opened before this command is used. To work on another image plane, use SETIMAGEPLANE to set the plane as current first and then use the GETPIXEL function.
Syntax:
- GETPIXEL image col row value
where, IMAGE3D image, INTEGER col row value, the col and row defines the pixel location.
Example:
- LOGFILE "c:output.log"
- IMAGE3D image1
- INTEGER col, row, pix
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SETIMAGEPLANE image1 2
- FOR col = 0 TO 20
- FOR row = 0 TO 20
- GETPIXEL image1 col row pix
- PRINT "pixel (", col, ",", row, ")=", pix
- NEXT
- END
20. SETPIXEL statement
This function sets a pixel value in the current plane of an opened image. The image must be open before this command is used. To work on another image plane, use SETIMAGEPLANE to set the plane as current first and then use this function.
Syntax:
- SETPIXEL image col row value
where, IMAGE3D image, INTEGER col row value, the col and row defines the pixel location.
- Example:
- LOGFILE "c:output.log"
- IMAGE3D image1
- INTEGER col, row, pix
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SETIMAGEPLANE image1 2
- pix = 255
- FOR col = 0 TO 20
- FOR row = 0 TO 20
- SETPIXEL image1 col row pix
- NEXT
- END
21. SHOWIMAGE statement
This command sends the currently opened image to display. Once an image is used by this command, it will be automatically closed and will no longer be available to the same program. It should be opened again if the image needs to be used by the same program.
Syntax:
- SHOWIMAGE imagevar
where, IMAGE3D imagevar
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SHOWIMAGE image1
- END
22. CLOSEIMAGE statement
This command closes a currently opened image when it is no longer needed. This will free up all memory allocated by the image.
Syntax:
- CLOSEIMAGE imagevar
where, IMAGE3D imagevar
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- CLOSEIMAGE image1
- END
23. SIZEIMAGEUP statement
This command enlarges an image by a specified scaling factor. For example, if the scaling factor is 2, then the resized image will be doubled in all three dimensions. This command is similar to Image/Resize Volume command.
Syntax:
- SIZEIMAGEUP imagevar "filename" 2
- SIZEIMAGEUP imagevar filename scalar
-
where, IMAGE3D imagevar, STRING filename, INTEGER scalar
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SIZEIMAGEUP image1 "c:\size2.tif" 2
- END
24. SIZEIMAGEDOWN statement
This command reduces the size of an image by a specified scaling factor. For example, if the scaling factor is 2, then the resized image will be scaled down by 2 in all three dimensions. This command is similar to Image/Resize Volume command.
Syntax:
- SIZEIMAGEDOWN imagevar "filename" 2
- SIZEIMAGEDOWN imagevar filename scalar
where, IMAGE3D imagevar, STRING filename, INTEGER scalar
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SIZEIMAGEDOWN image1 "c:\size2.tif" 2
- END
25. ROTATEIMAGEX and ROTATEIMAGEY statements
The ROTATEIMAGEX and ROTATEIMAGEY commands rotate a 3D volume around the X-axis and Y-axis, respectively. They are similar to Image/Reslice/Reslice X Axis and Image/Reslice/Reslice Y Axis commands.
Syntax:
- ROTATEIMAGEX imagevar "filename"
- ROTATEIMAGEX imagevar filename
- ROTATEIMAGEY imagevar "filename"
- ROTATEIMAGEY imagevar filename
where, IMAGE3D imagevar, STRING filename
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- ROTATEIMAGEX image1 "c:\topview.tif"
- ROTATEIMAGEY image1 "c:\sizeview.tif"
- END
26. CROPIMAGE statement
This command crops a sub-volume from an image and save the volume to a new image file. This command is similar to the Image/Crop Image/Crop Volume command.
Syntax:
- CROPIMAGE imagevar "filename" x1 x2 y1 y2 z1 z2
- CROPIMAGE imagevar filename x1 x2 y1 y2 z1 z2
where, IMAGE3D imagevar, STRING outputfile
INTEGER x1 x2 y1 y2 z1 z2; defines the volume
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- CROPIMAGE image1 "c:\crop.tif" 10 50 10 50 1 15
- END
27. SEGMENTIMAGE statement
This command segments an image using specified low and high thresholds. The generated object boundary lines are stored in the IMAGE3D variable and can be used by surface or volume rendering commands. This command is similar to the 3D Rendering/Interactive Segment command.
Syntax:
- SEGMENTIMAGE image low high alllines
- SEGMENTIMAGE image 50 189 0
where, IMAGE3D image, INTEGER low high
INTEGER alllines (0: only outline, 1: all boundaries)
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SEGMENTIMAGE image1 50 189 0
- SAVEBOUNDARY image1 "c:\object1.bnd"
- SHOWIMAGE image1
- END
28. OPENBOUNDARY statement
This command loads object boundary data into an IMAGE3D variable from a boundary file. This command is similar to the File/Boundary/Import Boundary command.
Syntax:
- OPENBOUNDARY imagevar "filename"
- OPENBOUNDARY imagevar filename
where, IMAGE3D imagevar, STRING filename
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- OPENBOUNDARY image1 "c:\3ddoctor\head3d.bnd"
- SHOWIMAGE image1
- END
29. SAVEBOUNDARY statement
This command saves object boundary data into a boundary file. This command is similar to the File/Boundary/Export Boundary command.
Syntax:
- SAVEboundary imagevar "filename"
- SAVEboundary imagevar filename
where, IMAGE3D imagevar, STRING filename
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SEGMENTIMAGE image1 50 189 0
- SAVEBOUNDARY image1 "c:\object1.bnd"
- SHOWIMAGE image1
- END
30. DECONVNN statement
This command performs a nearest neighbor deconvolution. It is similar to the Image/Deconvolution//Fast Nearest Neighbor command.
Syntax:
- DECONVNN "sourcefile" "psffile" "outputfile" areasize kernelsize scalar
- DECONVNN sourcefile psffile outputfile 32 11 0.0001
where, STRING sourcefile, psffile, outputfile, INTEGER areasize, kernelsize, FLOAT scalar
Example:
- LOGFILE "c:\output.log"
- DECONVNN "c:\image.tif" "c:\psf.tif" "c:\output.tif" 32 11 0.0001
- END
31. DECONVMAX statement
This command performs a maximum entropy based deconvolution. It is similar to the Image/Deconvolution/Maximum Entropy command.
Syntax:
DECONVMAX "sourcefile" "psffile" "outputfile" iterations feedback
DECONVMAX sourcefile psffile outputfile 15 0.05
where, STRING sourcefile, psffile, outputfile, INTEGER iterations, FLOAT feedback; this value should be less than 1.
Example:
- LOGFILE "c:\output.log"
- DECONVMAX "c:\image.tif" "c:\psf.tif" "c:\output.tif" 15 0.05
- END
32. SURFSIMPLE statement
This command performs a simple surface rendering using boundary data stored in an IMAGE3D object. It is similar to the 3D Rendering/Surface Rendering/Simple Surface command, but the surface modeling data is saved directly to a file, instead of being displayed in a window.
Syntax:
- SURFSIMPLE imagevar "filename"
- SURFSIMPLE imagevar filename
where, IMAGE3D imagevar, STRING filename
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SEGMENTIMAGE image1 50 189 0
- surfsimple image1 "c:\3ddoctor\head3d.suf"
- END
33. SURFCOMPLEX statement
This command performs a complex surface rendering using boundary data stored in an IMAGE3D object. It is similar to the 3D Rendering/Surface Rendering/(Fast or Full) Complex Surface command, but the surface modeling data is saved directly to a file, instead of being displayed in a window.
Syntax:
- SURFCOMPLEX imagevar "filename"
- SURFCOMPLEX imagevar filename
where, IMAGE3D imagevar, STRING filename
Example:
- IMAGE3D image1
- OPENIMAGE image1 "c:\3ddoctor\head3d.tif"
- SEGMENTIMAGE image1 50 189 0
- surfCOMPLEX image1 "c:\3ddoctor\head3d.suf"
- END
34. END statement
This command indicates the end of the program.
Syntax:
- END
Example:
- PRINT"This
is a test"
END