GE Image processing module

Module GE: GE Image processing

This is a module for reading files and quick processing of data from the GE angiography detector in use at sector 1. It requires the NumPy package. It does not require the PyEpics package. Most functions in this module work directly with data files created by the GE detectors, with the exceptions of PlotGEimage() and PlotROIsums(), which plot images and ROI values, respectively, from other functions in this module.

Summary

Routines Description
Count_Frames() Determine the number of frames in a GE image file
getGEimage() Read a single entire GE image file
getGE_ROI() Read a section (region of interest) of a GE image file
PlotGEimage() Plot an image or ROI
sumGE_ROIs() Report the average intensity for ROIs in a GE image frame
sumAllGE_ROIs() Reports the average intensity for ROIs for all frames in a file
PlotROIsums() Plots the ROIs values from sumAllGE_ROIs()

Complete Function Descriptions

The functions available in this module are listed below.

APSpy.GE.Count_Frames(filename)[source]

Determine the number of frames in a GE file by looking at the file size.

Parameters:filename (str) – The filename containing the as-recorded GE images
Returns:the number of frames (int).

Example:

>>> ifil = '/Users/toby/software/work/1ID/data/AZ91_01306.ge2'
>>> GE.Count_Frames(ifil)
220
APSpy.GE.PlotGEimage(img, title, tablbl, plotlist, region=None, size=(700, 700), imgwin=None)[source]

Create a plot of an image in tabbed window

Parameters:
  • img (array) – An image, as a numpy array or matplotlib compatible object. Usually this will be created by getGEimage() or getGE_ROI().
  • title (str) – A string with a title for the window
  • tablbl (str) – A string with the title for the new tab (should be short)
  • plotlist (list) – A list of _ImagePlot objects. As new plots are created in this routine they are added to this list. The list is used to assign color maps.
  • region (list) –

    A list for four numbers which describes the ROI location for use in adding offsets for the plot axes labeling. The numbers are:

    element # label description
    0 xmid x value for central pixel
    1 ymid y value for central pixel
    2 xwid half-width of ROI in pixels
    3 ywid half-width of ROI in pixels

    The default is to label the pixels starting from zero.

  • size (list) – A list, tuple or wx.size object with the size of the window to be created in pixels. The default is (700,700)
  • imgwin (object) – A plotnotebook object that has been created using plotnotebook.MakePlotWindow(), usually in a prior call to PlotGEimage(). A value of None (default) causes a new frame (window) to be created.
Returns:

A reference to the plot window (a plotnotebook object), which will be either imgwin or the new one created in plotnotebook.MakePlotWindow().

Examples:

>>> import plotnotebook
>>> import GE
>>> plotlist = []
>>> ifil = '/Users/toby/software/work/1ID/data/AZ91_01306.ge2'
>>> img = GE.getGEimage(ifil,2)
>>> imgwin = GE.PlotGEimage(img,'image window','full image',plotlist)
>>> plotnotebook.ShowPlots()
>>> import plotnotebook
>>> import GE
>>> plotlist = []
>>> ifil = '/Users/toby/software/work/1ID/data/AZ91_01306.ge2'
>>> ROI = GE.getGE_ROI(ifil,2,(100,200,5,7))
>>> imgwin = GE.PlotGEimage(ROI ,'','ROI',plotlist, (100,200,4,6))
>>> plotnotebook.ShowPlots()
APSpy.GE.PlotROIsums(datarray, tablbl='ROIs', title='', captions=None, size=(700, 700), imgwin=None)[source]

Plots a series of ROIs

Parameters:
  • datarray (array) – a list of MxN array of average intensity values, as returned by sumAllGE_ROIs(), where M is the number of frames and N is the number of ROI region(s).
  • tablbl (str) – A string with the title for the new tab. (Should be short; default is “ROIs”.)
  • title (str) – A string with a title for the window. Defaults to blank.
  • captions (list) – A list of N strings, where each string specifies a legend caption for each of the N ROI regions. (Default is “ROI #”.)
  • size (list) – A list, tuple or wx.size object with the size of the window to be created in pixels. The default is (700,700)
  • imgwin (object) – A plotnotebook object that has been created using plotnotebook.MakePlotWindow(), usually in a prior call to PlotGEimage(). A value of None (default) causes a new frame (window) to be created.
Returns:

A reference to the plot window (a plotnotebook object), which will be either imgwin or the new one created in plotnotebook.MakePlotWindow().

Example:

>>> regionlist = [ROI_rect(1335,1525,50,50),ROI_rect(1435,1525,50,50),
...               ROI_rect(335,1525,50,50),ROI_rect(1935,1525,50,50)]
>>> caps = [str(i[0])+','+str(i[1]) for i in regionlist]
>>> ROIarr = GE.sumAllGE_ROIs(imgfile,regionlist)
>>> GE.PlotROIsums(ROIarr, captions=caps)
>>> import plotnotebook
>>> plotnotebook.ShowPlots()
class APSpy.GE.ROI_rect(xmid, ymid, xwid, ywid)[source]

Defines the rectangle of a region of interest (ROI) by midpoint and width

Each ROI region consists of 4 elements:

element # label description
0 xmid x value for central pixel
1 ymid y value for central pixel
2 xwid half-width of ROI in pixels
3 ywid half-width of ROI in pixels
get_bounds()[source]

return the boundaries (start and end) of an ROI

APSpy.GE.getGE_ROI(filename, frame, region)[source]

Read a section (region of interest) of a GE image from a file. This is usually faster than reading an entire image.

Parameters:
  • filename (str) – The filename containing as-recorded GE images
  • frame (int) – the image number on the file, counted starting at 1
  • region (list) –

    describes the region to be extracted

    element # label description
    0 xmid x value for central pixel
    1 ymid y value for central pixel
    2 xwid half-width of ROI in pixels
    3 ywid half-width of ROI in pixels

    The extracted ROI will be pixels img[ymid-ywid:ymid+ywid,xmid-xwid:xmid+xwid] where img is the full image.

Returns:

An image as a (2*ywid)x(2*xwid) numpy memmap (behaves like an array) of intensities

Example:

>>> ifil = '/Users/toby/software/work/1ID/data/AZ91_01306.ge2'
>>> GE.getGE_ROI(ifil,2,(100,200,4,6))
memmap([[1755, 1762, 1763, 1761, 1766, 1762, 1761, 1756],
   [1761, 1763, 1760, 1764, 1765, 1769, 1755, 1758],
   [1762, 1762, 1763, 1758, 1769, 1769, 1757, 1756],
   [1760, 1767, 1764, 1763, 1763, 1765, 1762, 1756],
   [1760, 1764, 1760, 1763, 1763, 1762, 1758, 1758],
   [1761, 1760, 1766, 1762, 1761, 1767, 1761, 1761],
   [1754, 1761, 1765, 1754, 1760, 1768, 1760, 1759],
   [1763, 1764, 1764, 1763, 1766, 1762, 1765, 1761],
   [1760, 1757, 1761, 1765, 1766, 1766, 1761, 1759],
   [1761, 1761, 1761, 1761, 1761, 1763, 1757, 1758],
   [1757, 1765, 1760, 1767, 1764, 1768, 1758, 1760],
   [1762, 1765, 1764, 1760, 1764, 1766, 1761, 1761]], dtype=uint16)
APSpy.GE.getGEimage(filename, frame)[source]

Read a single entire GE image from a file

Parameters:
  • filename (str) – The filename containing as-recorded GE images
  • frame (int) – the image number on the file, counted starting at 1 An exception is raised if frame is greater than the number of frames in the file.
Returns:

An image as a 2048x2048 numpy array of intensities

Example:

>>> ifil = '/Users/toby/software/work/1ID/data/AZ91_01306.ge2'
>>> GE.getGEimage(ifil,2)
array([[1699, 1713, 1713, ..., 1701, 1697, 1695],
   [1708, 1717, 1717, ..., 1708, 1703, 1705],
   [1715, 1719, 1719, ..., 1708, 1707, 1707],
   ..., 
   [1714, 1720, 1714, ..., 1698, 1702, 1697],
   [1714, 1718, 1716, ..., 1702, 1703, 1702],
   [1701, 1704, 1697, ..., 1684, 1685, 1687]], dtype=uint16)
APSpy.GE.sumAllGE_ROIs(filename, regionlist, processes=1)[source]

Computes the average intensity for each ROI specified in the regionlist for every frame in a raw GE image file.

Parameters:
  • filename (str) – The filename containing as-recorded GE images
  • regionlist ([ROI_rect]) – A list of ROI_rect objects
  • processes (int) – specifies the number of simultaneous processes that can be used to perform ROI integration using the Python multiprocessing module. The default, 1, will not use this module and all computations are done in the current thread. Values >1 can show significant gains in speed on multicore/multicpu computers.
Returns:

a list of MxN array of average intensity values, where M is the number of frames and N is the number of ROI region(s) in regionlist.

Examples:

>>> ifil = '/Users/toby/software/work/1ID/data/AZ91_01306.ge2'
>>> GE.sumAllGE_ROIs(ifil, [(100,200,4,6), (1335,1525,50,50)])
array([[ 1794.57291667,  1801.2036    ],
   [ 1761.80208333,  1792.6894    ],
   [ 1760.5       ,  1791.7353    ],
   [ 1760.36458333,  1791.4961    ],
   [ 1760.03125   ,  1791.6162    ],
   ...
   [ 1760.0625    ,  1779.0867    ],
   [ 1759.72916667,  1779.1182    ],
   [ 1759.5       ,  1779.2508    ]])

In the example above, two ROIs are integrated for all frames in a file in the current Python interpreter.

>>> import GE
>>> import numpy as np
>>> import time
>>> imgfile = '/tmp/AZ91_01306'
>>> regionlist = [ROI_rect(1335,1525,50,50),ROI_rect(1435,1525,50,50),
...    ROI_rect(335,1525,50,50),ROI_rect(1935,1525,50,50)]
>>> nframe = GE.Count_Frames(imgfile)
>>> l = {}
>>> for proc in range(10):
...    st = time.time()
...    l[proc] = GE.sumAllGE_ROIs(imgfile,regionlist, proc)
...    print 'sec per frame, processors=',proc,(time.time()-st)/float(nframe)
...    assert(np.allclose(l[0],l[proc]))

The example above integrates 4 ROIs and compares running with all computations in the current Python thread (processes=0 and 1) with running with up to 9 concurrent processes. Usually one sees a speed-up with ~1.5 times the actual number of cores for multiprocessing. The assert is used to confirm the computation returns the same results independent of the number of processes.

APSpy.GE.sumGE_ROIs(filename, frame, regionlist)[source]

Reads a frame from a raw GE image file and returns a list of the average intensity for each ROI specified in the regionlist.

Parameters:
  • filename (str) – The filename containing as-recorded GE images
  • frame (int) – the image number on the file, counted starting at 1
  • regionlist ([ROI_rect]) – A list of ROI_rect objects
Returns:

a list of N average intensity values, one for each ROI region in regionlist.

Example:

>>> ifil = '/Users/toby/software/work/1ID/data/AZ91_01306.ge2'
>>> regionlist = [ROI_rect(1335,1525,50,50),ROI_rect(1435,1525,50,50),]
>>> GE.sumGE_ROIs(ifil,2,regionlist)
[1792.6894, 1780.4342]
APSpy.GE.sumGE_ROIs_wrapper(args)[source]

Provides an interface to sumGE_ROIs() that allows it to be called with a single argument. This is needed for use with the multiprocessing module and sumAllGE_ROIs()

Parameters:args (tuple) – A tuple or list containing a filename, frame, and regionlist, as defined in sumGE_ROIs().
Returns:a list of N average intensity values, one for each ROI region in regionlist.

Table Of Contents

Previous topic

Module AD: Area-Detector access

Next topic

Module CrossReference: simple support for cross-references

This Page