pwem.emlib.image.image_readers module

class pwem.emlib.image.image_readers.EMANImageReader[source]

Bases: ImageReader

Image reader for eman file formats

static getCompatibleExtensions() list[source]

Returns a list of the compatible extensions the reader can handle

static getDimensions(filePath)[source]

Returns the dimensions [X,Y,Z,N] of the file

class pwem.emlib.image.image_readers.ImageReader[source]

Bases: object

static getCompatibleExtensions() list[source]

Returns a list of the compatible extensions the reader can handle

static getDimensions(filePath)[source]

Returns the dimensions [X,Y,Z,N] of the file

static write(images: ImageStack, fileName: str, isStack: bool) None[source]

Generate a stack of images or a volume from a list of PIL images. :param images: An ImageStack instance with one or more images :param fileName: Path of the new stack :param isStack: Specifies whether to generate a volume or an image stack

class pwem.emlib.image.image_readers.ImageReadersRegistry[source]

Bases: object

Class to register image readers to provide basic information about an image like dimensions or getting an image

classmethod addReader(imageReader: ImageReader)[source]
classmethod getAvailableExtensions()[source]

Returns all the extensions it can handle

classmethod getReader(filePath) ImageReader[source]

Returns the reader or None able to deal with filePath based on the extension.

classmethod open(filePath)[source]

Opens the file and returns and image stack

classmethod write(imgStack: ImageStack, fileName: str, isStack=False) None[source]

Generate a stack of images from a list of PIL images.

class pwem.emlib.image.image_readers.ImageStack(images=None, properties=None)[source]

Bases: object

Class to hold image stacks. A single image is considered a stack of one image

Parameters
  • images – either None, an image as returned by the readers or a list of them. Images are numpy arrays

  • properties – optional: dictionary of key value pairs for header information for those files tha may need it

append(imgStack)[source]

Appends to its local list of images the images inside the imgStack passed as parameter

getImage(index=0, pilImage=False)[source]
getImages()[source]

Returns all the images

getProperties()[source]

Returns the properties dictionary

getProperty(property)[source]

Returns the property passed

class pwem.emlib.image.image_readers.MRCImageReader[source]

Bases: ImageReader

Image reader for MRC files

classmethod getArray(filename)[source]
static getCompatibleExtensions() list[source]

Returns a list of the compatible extensions the reader can handle

static getDimensions(filePath)[source]

Returns the dimensions [X,Y,Z,N] of the file

classmethod getMrcImage(fileName)[source]
classmethod open(path: str)[source]
classmethod write(imageStack: ImageStack, fileName: str, isStack=False) None[source]

Generate a stack of images or a volume from a list of PIL images.

class pwem.emlib.image.image_readers.PILImageReader[source]

Bases: ImageReader

PIL image reader

static getCompatibleExtensions() list[source]

Returns a list of the compatible extensions the reader can handle

static getDimensions(filePath)[source]

Returns the dimensions [X,Y,Z,N] of the file

classmethod open(filePath: str)[source]
classmethod write(imgStack: ImageStack, fileName: str, isStack=False) None[source]

Generate a stack of images or a volume from a list of PIL images. :param images: An ImageStack instance with one or more images :param fileName: Path of the new stack :param isStack: Specifies whether to generate a volume or an image stack

class pwem.emlib.image.image_readers.STKImageReader(fileName)[source]

Bases: ImageReader

FLOAT32_BYTES = 4
HEADER_OFFSET = 1024
IMG_BYTES = None
TYPE = None
classmethod getArray(filename)[source]
classmethod getCompatibleExtensions() list[source]

Returns a list of the compatible extensions the reader can handle

static getDimensions(filePath)[source]

Returns the dimensions [X,Y,Z,N] of the file

header_info = None
classmethod open(path)[source]
classmethod read(filename, id)[source]
Reads a given image

:param filename (str) –> Image to be read

classmethod readBinary(start, end)[source]
Read bytes between start and end

:param start (int) –> Start byte :param end (int) –> End byte :returns the bytes read

classmethod readHeader()[source]
Reads the header of the current file as a dictionary

:returns The current header as a dictionary

classmethod readImage(iid)[source]
Reads a given image in the stack according to its ID

:param iid (int) –> Image id to be read :returns Image as Numpy array

classmethod readNumpy(start, end)[source]
Read bytes between start and end as a Numpy array

:param start (int) –> Start byte :param end (int) –> End byte :returns decoded bytes as Numpy array

classmethod seek(pos)[source]
Move file pointer to a given position

:param pos (int) –> Byte to move the pointer to

stk_handler = None
class pwem.emlib.image.image_readers.TiffImageReader[source]

Bases: ImageReader

Tiff image reader

static getCompatibleExtensions() list[source]

Returns a list of the compatible extensions the reader can handle

static getDimensions(filePath)[source]

Returns the dimensions [X,Y,Z,N] of the file

classmethod open(path: str)[source]
classmethod write(imgStack: ImageStack, fileName: str, isStack=False) None[source]

Generate a stack of images or a volume from a list of PIL images. :param images: An ImageStack instance with one or more images :param fileName: Path of the new stack :param isStack: Specifies whether to generate a volume or an image stack

class pwem.emlib.image.image_readers.XMIPPImageReader[source]

Bases: ImageReader

static getCompatibleExtensions()[source]

Returns a list of the compatible extensions the reader can handle

static getDimensions(filePath)[source]

Returns the dimensions [X,Y,Z,N] of the file