Title: Images, images and still more images
1Images, images and still more images
2Presentation Outline
- Program imgutils-image_format_convert
- Data Format
- Endian problem
- Split/merging files
- Auxillary data (TR etc) recognition, insertion
and checking - Work to increase robustness of the programs
- Programming interface
- Some programming advices
- Current and future work
3Users vs Programs (programmers?)
- What the user expects
- Program accepts all file formats
- Program deals with all ways of presenting data
- What the program expects
- User provides only one file format
- A very specific way of dealing with data
IT IS GOING TO BE A COMPROMISE BETWEEN THIS TWO
EXTREME
4Image Data
- File Format
- What type of data it can holds? (integer, real
number) - Any auxillary data, such as TR?
- Machine Dependency
- Big Endian vs Little Endian
- Size of Data (sizeof(int)4??)
- How To Access These Data?
5File Formats in Use
- Analyze Format (.hdr, .img)
- Most widely used. Mainly due to SPM dominance.
- Bruker-enhanced Analyze
- Used to supplement Analyze. Unique to Cambridge
and perhaps Oxford. - UNC Format
- Used by BAMM.
- DICOM
- Emerging standard. But with SPMs dominance, it
is unlikely to be accepted in fMRI community.
6Analyze Format
- Advantage
- Simple and easy to program access routine
- Since image data is in separate file, very easy
to import it into other programs. - The most supported format in fMRI programs
- Disadvantage
- Experience says that header and image file can be
in different endian ! - It only carries structural Information
- Abused by SPM programmers because of
misinterpretation of specification, SPM-specific,
M-like, hijack of reserved fields.
7Bruker-enhanced Analyze
- Advantage
- Carries detail information about fMRI
- As a text file, easily viewed by user
- Disadvantage
- Very complex structure, difficult to program
access routine - Cannot find any documentation
8UNC Format
- Advantage
- Can hold any auxiliary data
- Disadvantage
- Only used (and abused) by BAMM.
- Unlike brkhdr, auxiliary data can only be seen
if you use a hex editor - There is completely no specification on what data
must be there for fMRI, PET etc.
9DICOM
- Advantage
- Very well documented Documentation run into 10
volumes!! - Have specific specification on what data must be
there for MRI, PET etc - Disadvantage
- Not easy to program access routines for auxiliary
data - Auxiliary data are coded and cannot be easily
seen.
10imgutils-image_format_convert
- Use it for
- File-format conversion
- Combining a set of N dimensional files to form a
N1 dimensional file and vice-versa. - Copying only a subset of the data
- Changing the endian of the data
- Inspecting, and if file format allows, insert new
field into the file. - Check and validate the auxiliary data
carried/inserted.
11Usage
- imgutils-image_format_convert options
ltInputImageStringgt ltOutputImageStringgt - All it does is to make available, in a technical
user-friendly format, all functionalities
available in Image File I/O, i.e., everything in
FileManager.cpp and its associated files.
12File Format Conversion
imgutils-image_format_convert input.brhdr
output.unc
13Combining And Splitting Files
imgutils-image_format_convert input3d??.img
output4d.img
14Endian Conversion
Solaris Big Endian
automatic
imgutils-image_format_convert
automatic
Intel Little Endian
--force-convert-endian --no-covert-endian
imgutils-image-format-convert input.hdr
output.hdr
15Options for imgutils-image_format_convert
- --input-analyze-spm99-compatible,
--output-analyze-spm99-compatible - the input/output analyze image will be spm99
complient - --input-unc-fmri3d
- user guarantee that the input UNC 3D image is a
fmMRI image - Technically speaking, all programmer accessible
options can be input as command line options
16BammL XML-based Data Description
- Human/Machine readable
- lt? xml ?gt
- ltBAMM_IMAGE_INFORMATIONgt
- ltdatagt
- ltdata_datatypegt
- ltnamegtFLOATlt/namegt
- ltsizegt4lt/sizegt
- lt/data_datatypegt
- ltdata_dimensiongt
- ltnum_dimensiongt3lt/num_dimensiongt
- ltwidthgtltnum_pixelgt128lt/num_pixelgtlt/widthgt
- ltheightgtltnum_pixelgt128lt/num_pixelgtlt/heightgt
- ltvolumegtltnum_pixelgt21lt/num_pixelgtlt/volumegt
- lt/data_dimensiongt
- lt/datagt
- lt/BAMM_IMAGE_INFORMATIONgt
17BammL Data Classification
- Classified into different classes.
- Each category contains guaranteed information.
- The guaranteed information are checked for
accuracy whenever possible - Simplify programming
18BammL Class Hierarchy
BAMM_IMAGE_INFORMATION Any image data (1D data
treated as special case)
BAMM_SCAN_INFORMATION Any medical scan data (PET,
MRI, CT etc, 2D and above)
BAMM_fMRI_SCAN_INFORMATION fMRI data(3D and 4D
data)
It is possible to replace the class represented
in the image file using a separate BammL file
19Programming Stuff BAMM
- Collection of Data Classes and algorithms to
build application - Aim to make program more robust by
- encouraging reuse of classes and algorithms
- automated background data test
- systematic catching and reporting of errors
- rigorous testing to prevent errors
- better documentation
- making program more readable
- Restructuring internal organization to better
cope with possible future change
20Programming Changes
- Current
- main()
-
- int Data4D, SIZE, Dim, DimSize
- File UNC
- if( (UNC imopen(a.unc)) NULL)
// - imdatainfo(UNC, DimSize, DType, Dim)
- if(DimSize ! 4) //
- if(DType ! INT) //
- SIZE Dim0Dim3
- Data4D new intSIZE
- imgetdata(UNC, Data4D)
- //there is still no guarantee that Data4D is
- //valid fMRI data
- //
- if(!imgetinfo(UNC,rep_time, TR)) //
- New
- main()
-
- fmri4dltintgt Data4D
- try
-
- FileManager FMgr
- FMgr.LoadFromFile(a.unc)
- FMgr.WriteDataTo(Data4D)
-
- catch(exception e)
- //
- //from here on Data4D is guaranteed
- //valid fMRI data
- //
- TR Data4D.GetRepetitionTime()
Could had been a.brkhdr
21Programming Advice
- Simple steps that will save you a lot of grief in
the long run. - They are just Rule of Thumb, meaning they are
useful at about 80 of the time
22Programming Advice I
- SAVE MULTIPLE VERSIONS OF THE SAME PROGRAM
- The aim is the ability to go back to a previous
version, if the version you are currently working
on goes horribly wrong - For larger projects, consider concurrent version
system (CVS)
23Programming Advice II
- Breakdown task to simple tasks, then code the
simple task separately - Example Converting BAMMs design matrix to SPM
design matrix (dmc-bamm2spm.pl) - Read in BAMM design matrix then
- Write SPM design matrix
- Dont read and write at the same time its
difficult to debug
24Programming Advice III
- Test, test and retest
- Testing should be done continuously on the whole
design/coding cycle - As soon as you finish writing a task, test that
the program really does the task. - Regression test If you find a possible failure
route for your program, devise a test procedure,
and then use the test procedure at regular
intervals to make sure the same problem does not
pop up again
25Programming Advice IV
- Document as much as you can
- User documentation how to use it as a program
- Program documentation
- What your program/subprogram does
- Whats the assumption you made
- How to use them
- Possible failure/bugs
26Current Work on BAMM
- Maintaining the already created classes and
routine - Making the programming documentation available on
the website - Write a user manual
27Possible Future Works for BAMM
- Incorporate more image formats such as BMP, PCX
and JPEG - Anonymizing tools to make Data Protection Act
compliance a easier task - More diagnostic routines to find out whats wrong
with your image - Rework current f/g/x/sbamm to the more robust
method if and only if it make sense to do so - More numeric routines, possibly from boost.org
28Other current works possible future work
- Current Work
- FTP server
- Allow upload/download of large chunks of data
- Analyzing Carolines new data
- Possible future work
- Incorporating spatial information when regressing
the fMRI model