It is possible to view and optionally convert many other image formats. Image file format parameters are placed in an ASCII text file and are compiled at run time.
To include your own custom file format, enter the name of your file in the configuration file (\fpimage\bin\fpimage.cfg) preceded by the RAW keyword.
Example: RAW C:\FPIMAGE\BIN\SIEMENS.FMT
Up to 50 custom formats may be specified at one time. Each format
is searched for matches in the order that specified by the RAW
statements in the configuration file. As a rule of thumb, place the
most frequently encountered image files at the top of the list.
STATEMENTS:
Images may be identified using a combination of the filename extension and/or a bit pattern in the file itself. To identify a file by it’s extension, use the EXT statement. This statement is mandatory.
Examples:
EXT “IMA” # A file such as: 004796.ima
EXT “*” # Any filename
extension
To identify a file by a byte pattern use the ID statement. This is followed by the file location (in hex) and the matching pattern. The pattern may be expressed in ASCII (enclosed in quotes) or as a hex number.
Examples:
ID 0x00000298 "SOMATOM HIQ"
ID 0x00000000 0x42
The image dimensions are defined by using the WIDTH and HEIGHT statements. These are expressed in pixels.
Examples:
WIDTH 512
HEIGHT 512
The start of the pixel data is defined by using the OFFSET statement. This is defined in bytes from the beginning of the file.
Example: OFFSET
4096
The type of pixel data is defined by the TYPE statement.
This statement accepts the following parameters:
|
|
|
|
|
32 bit floating point |
|
|
16 bit signed integer |
|
|
8 bit byte |
The byte ordering is determined by the ENDIAN statement. Parameters are Little or Big. If the ENDIAN statement is omitted then default will be Little.
Example:
TYPE 2
ENDIAN LITTLE
Some file formats use unsigned integers. A file format may specify the CT number of air as 0 and water as +1024. A value may be added to each pixel by using the CORRECT statement.
Example: CORRECT -1024
When the above statements are not sufficient to view/process an image file in the original form, the user may specify a script file to convert the image to IMG format. Use the SCRIPT statement followed by the script filename. A $ character preceeding the filename replaces the base directory name (i.e C:\FPIMAGE).
Example: SCRIPT $\bin\somatom_hiq.imp
Note: The original filename will be listed as the first line of the temp\raw.q file. For more information see the sample script file listing
Complete sample file listing:
EXT "IMA"
ID 0x00000298 "SOMATOM HIQ"
WIDTH 512
HEIGHT 512
OFFSET 4096
TYPE 2
CORRECT -1024
RAW $\bin\SIGNA5X.UIF
Sample UIF file for User Defined Formats
EXT "*"
ID 0x00000000 "IMGF"
SCRIPT $\bin\SIGNA5X.IMP
#
# Signa5x.IMP
#
message "Reading Proprietary Format...."
# Get the filenames
$rawq = $temppath "\raw.q"
input_file $rawq
finput $sourcefile
$destfile = $temppath "\Signa5x.dcm"
# Open the input file
fopen 1 $sourcefile
# Open the output file
fopen 2 $destfile
# Read info and write dicom tags
gosub extractinfo
#
# Load the pixels into memory
#
fseek 1 offset
size = width * height
fread 1 memory(0) size s16 b
#
# Now write the pixels
#
group = 0x7FE0
fwrite 2 group u16
elem = 0x0000
fwrite 2 elem u16
fwrite 2 4 u32
a = (size * 2) + 8
fwrite 2 a u32
fwrite 2 group u16
elem = 0x0010
fwrite 2 elem u16
a = size * 2
fwrite 2 a u32
fwrite 2 memory(0) size s16
fclose 1
fclose 2
# And Display It!
viewer display $destfile
viewer notify
message "Ready..."
exit
###################################################
#
#
#
Sub-Routines
#
#
#
###################################################
*WriteTag
# Ascii from file (if data is present)
if tagvr = 3
fseek 1 tagloc
fread 1 memory(0) taglen u8
a = 0
loop begin taglen
if memory(a) = 0
loop break
endif
a = a + 1
loop end
if a < 1
return
endif
b = (round(a / 2) * 2)
if a > b
memory(a) = 0x20
a = a + 1
endif
fwrite 2 group u16
fwrite 2 elem u16
fwrite 2 a u32
fwrite 2 memory(0) a u8
grouplen = grouplen + a + 8
endif
# VR_US unsigned short (16 bits)
if tagvr = 4
fwrite 2 group u16
fwrite 2 elem u16
fwrite 2 2 u32
fwrite 2 val_us u16
grouplen = grouplen + 10
endif
# VR_UL unsigned long (32 bits)
if tagvr = 5
fwrite 2 group u16
fwrite 2 elem u16
fwrite 2 4 u32
fwrite 2 val_ul u32
grouplen = grouplen + 12
endif
# VR_XX User Defined Ascii
if tagvr = 0
txt2mem $tagtext 0 80
a = 0
loop begin 1024
if memory(a) = 0
loop break
endif
a = a + 1
loop end
if a < 1
return
endif
b = (round(a / 2) * 2)
if a > b
$tagtext = $tagtext "
"
a = a + 1
endif
fwrite 2 group u16
fwrite 2 elem u16
fwrite 2 a u32
fwrite 2 $tagtext a
grouplen = grouplen + a + 8
endif
# Date
if tagvr = 1
fseek 1 tagloc
fread 1 memory(0) 8 u8
year = (memory(6) * 10) + memory(7)
if year >= 70
$yr = "19"
endif
if year < 70
$yr = "20"
endif
fwrite 2 group u16
fwrite 2 elem u16
fwrite 2 8 u32
fwrite 2 $yr 2
fwrite 2 memory(6) 2 u8
fwrite 2 memory(0) 2 u8
fwrite 2 memory(3) 2 u8
grouplen = grouplen + 16
endif
# Time
if tagvr = 2
fseek 1 tagloc
fread 1 memory(0) 5 u8
fwrite 2 group u16
fwrite 2 elem u16
fwrite 2 6 u32
fwrite 2 memory(0) 2 u8
fwrite 2 memory(3) 2 u8
$sec = "00"
fwrite 2 $sec 2
grouplen = grouplen + 14
endif
# VR_FtoA Float to Ascii
if tagvr = 6
fseek 1 tagloc
fread 1 fval f32 b
$ftext = fval ".0000000000"
b = round(fval / 2) * 2
if fval < 0
b = b * -1
endif
if fval > b
$ftext = fval "000000000"
endif
fwrite 2 group u16
fwrite 2 elem u16
fwrite 2 8 u32
fwrite 2 $ftext 8
grouplen = grouplen + 16
endif
Return
*ExtractInfo
# Tag VR Types
VR_XX = 0
VR_CS = 3
VR_DA = 1
VR_TM = 2
VR_LO = 3
VR_PN = 3
VR_SH = 3
VR_LT = 3
VR_US = 4
VR_UL = 5
VR_FtoA = 6
# Read the image parameters
fread 1 $ID 4
fread 1 offset u32 b
fread 1 width u32 b
fread 1 height u32 b
# And header locations
fseek 1 124
fread 1 SuiteHdr u32 b
fseek 1 132
fread 1 ExamHdr u32 b
fseek 1 140
fread 1 SeriesHdr u32 b
fseek 1 148
fread 1 ImageHdr u32 b
#################################################################
#
# Start of Group 0x0008
#
group = 0x0008
elem = 0x0000
val_ul = 0
tagvr = VR_UL
gosub writetag
grouplen = 0
bookmark = 8
# { 0x0008, 0x0008, 'CS', "Image Type"
},
elem = 0x0008
tagvr = VR_XX
$tagtext = "ORIGINAL\PRIMARY"
gosub writetag
# { 0x0008, 0x0016, 'UI', "SOP Class
UID" },
elem = 0x0016
tagvr = VR_XX
$tagtext = "1.2.840.10008.5.1.4.1.1.4"
gosub writetag
# { 0x0008, 0x0018, 'UI', "SOP Instance
UID" },
elem = 0x0018
tagvr = VR_XX
$tagtext = "1.2.840.000000.0.0.0.0000000000.000.000000000.000"
gosub writetag
# { 0x0008, 0x0020, 'DA', "Study Date"
},
elem = 0x0020
tagvr = VR_DA
tagloc = ExamHdr + 3446
gosub writetag
# { 0x0008, 0x0021, 'DA', "Series Date"
},
elem = 0x0021
tagvr = VR_DA
tagloc = ExamHdr + 3446
gosub writetag
# { 0x0008, 0x0023, 'DA', "Image Date"
},
elem = 0x0023
tagvr = VR_DA
tagloc = ExamHdr + 3446
gosub writetag
# { 0x0008, 0x0030, 'TM', "Study Time"
},
elem = 0x0030
tagvr = VR_TM
tagloc = ExamHdr + 3456
gosub writetag
# { 0x0008, 0x0031, 'TM', "Series Time"
},
elem = 0x0031
tagvr = VR_TM
tagloc = ExamHdr + 3456
gosub writetag
# { 0x0008, 0x0033, 'TM', "Image Time"
},
elem = 0x0033
tagvr = VR_TM
tagloc = ExamHdr + 3456
gosub writetag
# { 0x0008, 0x0060, 'CS', "Modality"
},
elem = 0x0060
tagvr = VR_XX
$tagtext = "MR"
gosub writetag
# { 0x0008, 0x0070, 'LO', "Manufacturer"
},
elem = 0x0070
tagvr = VR_XX
$tagtext = "GE MEDICAL SYSTEMS"
gosub writetag
# { 0x0008, 0x0080, 'LO', "Institution
Name" },
elem = 0x0080
tagvr = VR_LO
tagloc = ExamHdr + 10
taglen = 33
gosub writetag
# { 0x0008, 0x0090, 'PN', "Referring
Physician's Name" },
elem = 0x0090
tagvr = VR_PN
tagloc = ExamHdr + 212
taglen = 33
gosub writetag
# { 0x0008, 0x1010, 'SH', "Station
Name" },
elem = 0x1010
tagvr = VR_SH
tagloc = ExamHdr + 0
taglen = 4
gosub writetag
# { 0x0008, 0x1030, 'LO', "Study Description"
},
elem = 0x1030
tagvr = VR_LO
tagloc = ExamHdr + 282
taglen = 23
gosub writetag
# { 0x0008, 0x103E, 'LO', "Series Description"
},
elem = 0x103E
tagvr = VR_LO
tagloc = SeriesHdr + 20
taglen = 30
gosub writetag
# { 0x0008, 0x1060, 'PN', "Name of
Physician(s) Reading Study" },
elem = 0x1060
tagvr = VR_PN
tagloc = ExamHdr + 245
taglen = 33
gosub writetag
# { 0x0008, 0x1070, 'PN', "Operator's
Name" },
elem = 0x1070
tagvr = VR_PN
tagloc = ExamHdr + 278
taglen = 4
gosub writetag
# { 0x0008, 0x1090, 'LO', "Manufacturer's
Model Name" },
elem = 0x1090
tagvr = VR_LO
tagloc = SuiteHdr + 7
taglen = 13
gosub writetag
#
# End of Group 0x0008
#
fseek 2 bookmark
fwrite 2 grouplen u32
fpos = bookmark + grouplen +
4
fseek 2 fpos
bookmark = fpos + 8
#
#
#
#################################################################
#
# Start of Group 0x0010
#
group = 0x0010
elem = 0x0000
tagvr = VR_UL
gosub writetag
grouplen = 0
# { 0x0010, 0x0010, 'PN', "Patient's
Name" },
elem = 0x0010
tagvr = VR_PN
tagloc = ExamHdr + 97
taglen = 25
gosub writetag
# { 0x0010, 0x0020, 'LO', "Patient
ID" },
elem = 0x0020
tagvr = VR_LO
tagloc = ExamHdr + 84
taglen = 13
gosub writetag
# { 0x0010, 0x0040, 'CS', "Patient's
Sex" },
elem = 0x0040
tagloc = ExamHdr + 126
fseek 1 tagloc
fread 1 sex u16 b
$tagtext = "M"
if sex = 2
$tagtext = "F"
endif
tagvr = VR_XX
gosub writetag
# { 0x0010, 0x1010, 'AS', "Patient's
Age" },
elem = 0x1010
tagloc = ExamHdr + 122
fseek 1 tagloc
fread 1 age u16
fread 1 agetype u16 b
$agetext = "Y"
if agetype = 1
$agetext = "M"
endif
if agetype = 2
$agetext = "D"
endif
$tagtext = age "" $agetext
tagvr = VR_XX
gosub writetag
# { 0x0010, 0x1030, 'DS', "Patient's
Weight" },
elem = 0x1030
tagloc = ExamHdr + 128
fseek 1 tagloc
fread 1 weight u32 b
$tagtext = weight
tagvr = VR_XX
gosub writetag
# { 0x0010, 0x21B0, 'LT', "Additional
Patient History" },
elem = 0x21B0
tagvr = VR_LT
tagloc = ExamHdr + 134
taglen = 61
gosub writetag
#
# End of Group 0x0010
#
fseek 2 bookmark
fwrite 2 grouplen u32
fpos = bookmark + grouplen +
4
fseek 2 fpos
bookmark = fpos + 8
#
#
#
#################################################################
#
# Start of Group 0x0018
#
group = 0x0018
elem = 0x0000
tagvr = VR_UL
gosub writetag
grouplen = 0
group = 0x0018
# { 0x0018, 0x0010, 'LO', "Contrast/Bolus
Agent" },
elem = 0x0010
tagvr = VR_LO
tagloc = ImageHdr + 72
taglen = 17
gosub writetag
# { 0x0018, 0x0020, 'CS', "Scanning
Sequence" },
elem = 0x0020
tagvr = VR_CS
tagloc = ImageHdr + 346
taglen = 4
gosub writetag
# { 0x0018, 0x0021, 'CS', "Sequence
Variant" },
# { 0x0018, 0x0022, 'CS', "Scan Options"
},
# { 0x0018, 0x0023, 'CS', "MR Acquisition
Type" },
elem = 0x0023
tagloc = ImageHdr + 298
fseek 1 tagloc
fread 1 imode u16 b
$tagtext = "2D"
if imode = 2
$tagtext = "3D"
endif
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x0024, 'SH', "Sequence
Name" },
elem = 0x0024
tagvr = VR_SH
tagloc = ImageHdr + 308
taglen = 33
gosub writetag
# { 0x0018, 0x0025, 'CS', "Angio Flag"
},
# { 0x0018, 0x0050, 'DS', "Slice Thickness"
},
elem = 0x0050
tagloc = ImageHdr + 26
tagvr = VR_FtoA
gosub writetag
# { 0x0018, 0x0080, 'DS', "Repetition
Time" }, seconds?
elem = 0x0080
tagloc = ImageHdr + 194
fseek 1 tagloc
fread 1 reptime u32 b
reptime = reptime * .000001
$tagtext = reptime
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x0081, 'DS', "Echo Time"
},
elem = 0x0081
tagloc = ImageHdr + 198
fseek 1 tagloc
fread 1 invtime u32 b
reptime = invtime * .000001
$tagtext = invtime
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x0083, 'DS', "Number of
Averages" },
elem = 0x0083
tagloc = ImageHdr + 218
tagvr = VR_FtoA
gosub writetag
# { 0x0018, 0x0084, 'DS', "Imaging
Frequency" },
# { 0x0018, 0x0085, 'SH', "Imaged
Nucleus" },
# { 0x0018, 0x0086, 'IS', "Echo Numbers(s)"
},
elem = 0x0086
tagloc = ImageHdr + 212
fseek 1 tagloc
fread 1 echonum u16 b
$tagtext = echonum
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x0087, 'DS', "Magnetic
Field Strength" },
# { 0x0018, 0x0088, 'DS', "Spacing
Between Slices" },
elem = 0x0088
tagloc = ImageHdr + 116
tagvr = VR_FtoA
gosub writetag
# { 0x0018, 0x0091, 'IS', "Echo Train
Length" },
elem = 0x0086
tagloc = ImageHdr + 640
fseek 1 tagloc
fread 1 etrain u16 b
$tagtext = etrain
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x0093, 'DS', "Percent
Sampling" },
# { 0x0018, 0x0094, 'DS', "Percent
Phase Field of View" },
# { 0x0018, 0x0095, 'DS', "Pixel Bandwidth"
},
elem = 0x0088
tagloc = ImageHdr + 394
tagvr = VR_FtoA
gosub writetag
# { 0x0018, 0x1020, 'LO', "Software
Versions(s)" },
elem = 0x1020
tagloc = ImageHdr + 212
fseek 1 tagloc
fread 1 sver u16 b
$tagtext = sver
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x1050, 'DS', "Spatial
Resolution" },
# { 0x0018, 0x1062, 'IS', "Nominal
Interval" },
# { 0x0018, 0x1088, 'IS', "Heart Rate"
},
elem = 0x1088
tagloc = ImageHdr + 212
fseek 1 tagloc
fread 1 hrate u16 b
$tagtext = hrate
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x1090, 'IS', "Cardiac
Number of Images" },
elem = 0x1090
tagloc = ImageHdr + 246
fseek 1 tagloc
fread 1 cnum u16 b
$tagtext = cnum
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x1094, 'IS', "Trigger
Window" },
elem = 0x1094
tagloc = ImageHdr + 240
fseek 1 tagloc
fread 1 trigwin u16 b
$tagtext = trigwin
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x1110, 'DS', "Distance
Source to Detector" },
elem = 0x1110
tagloc = ExamHdr + 58
tagvr = VR_FtoA
gosub writetag
# { 0x0018, 0x1250, 'SH', "Receiving
Coil" },
elem = 0x1250
tagvr = VR_SH
tagloc = ImageHdr + 362
taglen = 17
gosub writetag
# { 0x0018, 0x1151, 'SH', "Transmitting
Coil" },
# { 0x0018, 0x1310, 'US', "Acquisition
Matrix" },
elem = 0x1310
$tagtext = width "\" height
"\0"
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x1314, 'DS', "Flip Angle"
},
elem = 0x1094
tagloc = ImageHdr + 254
fseek 1 tagloc
fread 1 flipangle u16 b
$tagtext = flipangle
tagvr = VR_XX
gosub writetag
# { 0x0018, 0x1315, 'CS', "Variable
Flip Angle Flag" },
# { 0x0018, 0x1316, 'DS', "SAR" },
elem = 0x1316
tagloc = ImageHdr + 230
tagvr = VR_FtoA
gosub writetag
# { 0x0018, 0x5100, 'CS', "Patient Position" },
#
# End of Group 0x0018
#
fseek 2 bookmark
fwrite 2 grouplen u32
fpos = bookmark + grouplen +
4
fseek 2 fpos
bookmark = fpos + 8
#
#
#
#################################################################
#
# Start of Group 0x0020
#
group = 0x0020
elem = 0x0000
tagvr = VR_UL
gosub writetag
grouplen = 0
# { 0x0020, 0x000D, 'UI', "Study Instance
UID" },
elem = 0x000D
tagvr = VR_XX
taglen = 48
$tagtext = "1.2.840.000000.0.0.0.0000000000.000.000000000.000"
gosub writetag
# { 0x0020, 0x000E, 'UI', "Series Instance
UID" },
elem = 0x000E
tagvr = VR_XX
$tagtext = "1.2.840.000000.0.0.0.0000000000.000.000000000.000"
gosub writetag
# { 0x0020, 0x0010, 'SH', "Study ID"
},
elem = 0x0010
tagloc = ExamHdr + 8
fseek 1 tagloc
fread 1 examnum u16 b
$tagtext = examnum
tagvr = VR_XX
gosub writetag
# { 0x0020, 0x0011, 'IS', "Series Number"
},
elem = 0x0011
tagloc = SeriesHdr + 10
fseek 1 tagloc
fread 1 seriesnum u16 b
$tagtext = seriesnum
tagvr = VR_XX
gosub writetag
# { 0x0020, 0x0012, 'IS', "Acquisition
Number" },
# { 0x0020, 0x0013, 'IS', "Image Number"
},
elem = 0x0013
tagloc = ImageHdr + 12
fseek 1 tagloc
fread 1 imgnum u16 b
$tagtext = imgnum
tagvr = VR_XX
gosub writetag
# { 0x0020, 0x0032, 'DS', "Image Position
(Patient)" },
# { 0x0020, 0x0037, 'DS', "Image Orientation
(Patient)" },
# { 0x0020, 0x0052, 'UI', "Frame of
Reference UID" },
elem = 0x0052
tagvr = VR_XX
$tagtext = "1.2.840.000000.0.0.0.0000000000.000.000000000.000"
gosub writetag
# { 0x0020, 0x0060, 'CS', "Laterality"
},
# { 0x0020, 0x1040, 'LO', "Position
Reference Indicator" },
elem = 0x1040
tagvr = VR_LO
tagloc = SeriesHdr + 84
taglen = 2
gosub writetag
# { 0x0020, 0x1041, 'DS', "Slice Location"
},
elem = 0x1041
tagloc = ImageHdr + 126
tagvr = VR_FtoA
gosub writetag
#
# End of Group 0x0020
#
fseek 2 bookmark
fwrite 2 grouplen u32
fpos = bookmark + grouplen +
4
fseek 2 fpos
bookmark = fpos + 8
#
#
#
#################################################################
#
# Start of Group 0x0028
#
group = 0x0028
elem = 0x0000
tagvr = VR_UL
gosub writetag
grouplen = 0
# { 0x0028, 0x0002, 'US', "Samples
per Pixel" },
elem = 0x0002
val_us = 1
tagvr = VR_US
gosub writetag
# { 0x0028, 0x0004, 'CS', "Photometric
Interpretation" },
elem = 0x0004
tagvr = VR_XX
$tagtext = "MONOCHROME2 "
gosub writetag
# { 0x0028, 0x0010, 'US', "Rows" },
elem = 0x0010
val_us = width
tagvr = VR_US
gosub writetag
# { 0x0028, 0x0011, 'US', "Columns"
},
elem = 0x0011
val_us = height
tagvr = VR_US
gosub writetag
# { 0x0028, 0x0030, 'DS', "Pixel Spacing"
},
elem = 0x0030
tagloc = ImageHdr + 50
fseek 1 tagloc
fread 1 pixsize_x f32 b
fread 1 pixsize_y f32 b
$tagtext = pixsize_x "\" pixsize_y
tagvr = VR_XX
gosub writetag
# { 0x0028, 0x0100, 'US', "Bits Allocated"
},
elem = 0x0100
val_us = 16
tagvr = VR_US
gosub writetag
# { 0x0028, 0x0101, 'US', "Bits Stored"
},
elem = 0x0101
val_us = 16
tagvr = VR_US
gosub writetag
# { 0x0028, 0x0102, 'US', "High Bit"
},
elem = 0x0102
val_us = 15
tagvr = VR_US
gosub writetag
# { 0x0028, 0x0103, 'US', "Pixel Representation"
},
elem = 0x0103
val_us = 1
tagvr = VR_US
gosub writetag
#
# End of Group 0x0028
#
fseek 2 bookmark
fwrite 2 grouplen u32
fpos = bookmark + grouplen +
4
fseek 2 fpos
bookmark = fpos + 8
Return
# End of Script