Define an Image class for python. Try to keep all the functionality in fabian and ImageD11 but share the read/write code so we can share the bug fixes.
Name Fabio = Fable io
Have a base class for all our 2D diffraction greyscale images. This consists of a 2D array (either Numeric, or numpy in the near future) and a python dictionary of header information in (string key, string value) pairs.
class fabioimage # [should this be PyImage, FableImage, Fabric, DiffrnImage, DetectorImage ?
Needs a name which will not to be confused with an RGB color image.
Contains member data elements:
data -> 2D array
header -> dictionary
rows, columns, dim1, dim2 -> data.shape
header_keys -> header.keys() used to retain the order of the header when writing an image to disk
bytecode -> data.typecode()
m, minval, maxval, stddev -> image statistics, could add others, eg roi[slice]
Offers member functions:
integrate_area() -> return sum(self.data) within slice
rebin(fact) -> rebins data, adjusts dims
toPIL16() -> returns a PILimage
getheader() -> returns self.header
resetvals() -> resets the statistics
getmean() -> (computes) returns self.m
getmin() -> (computes) returns self.minval
getmax() -> (computes) returns self.maxval
getstddev() -> (computes) returns self.stddev
read() -> read image from file [or stream, or shared memory]
write() -> write image to file [or stream, or shared memory]
readheader() -> read only the header [much faster for scanning files]
Each individual file format would then "inherit" all the functionality of this class and just make new read and write methods.
It would also be useful to take the fileseries thing from fabian and have it deal also with streams and shared memory.
New functionalities/ classes which could be useful:
We could try to contact the various manufacturers to see if they can offer any advice or test images? For each format we should have at least one image with known dimensions, min, max, stddev and mean values. Reading this in would be a quick way to check on the code. In some cases, several images with different quirks (eg overflows) could be added.
Methods from fabian which seem to be common for any 16 bit greyscale image would be:
add(otherimage) -> modifies self.data, no return val
integrate_area(coords)-> return sum(self.data) within coords
rebin(fact) -> rebins data, adjusts dims
toPIL16() -> returns a PILimage
These ones should also be in ImageD11.data
getheader() -> returns k,v dictionary
resetvals() -> resets the next 4
getmean() -> (computes) returns self.m
getmin() -> (computes) returns self.minval
getmax() -> (computes) returns self.maxval
getstddev() -> (computes) returns self.stddev
Member variables which match those in ImageD11:
data -> A numeric array
header -> A dictionary of key, value pairs
header_keys -> assert set(self.header.keys()) == set(self.header_keys)
Fabian specific stuff, that seems mirror other information:
bytecode -> assert self.bytecode == self.data.typecode()
(dim1,dim2) -> assert (self.dim1,self.dim2) == self.data.shape
Fabian cached data:
m [mean], maxval, minval, stddev
Specific to each format would be:
read -> fills in self.header
self.data
self.dim1
self.dim2
self.header_keys
write -> creates a file
Member functions :
__add__ -> new data object, header from first arg, data is sum
__sub__ -> new data object, header from first arg, data is difference
__mul__ -> new data object, header from first arg, data is product
__div__ -> new data object, header from first arg, data is quotient
getheader()-> returns the header
These ones should also be in fabian
getheader() -> returns k,v dictionary
resetvals() -> resets the next 4
getmean() -> (computes) returns self.m
getmin() -> (computes) returns self.minval
getmax() -> (computes) returns self.maxval
getstddev() -> (computes) returns self.stddev
Member variables:
data -> A numeric array
header -> A dictionary of key, value pairs
header_keys -> assert set(self.header.keys()) == set(self.header_keys)