pwem.emlib.image.image_readers module
- class pwem.emlib.image.image_readers.EMANImageReader[source]
Bases:
ImageReaderImage reader for eman file formats
- class pwem.emlib.image.image_readers.ImageReader[source]
Bases:
object- classmethod canOpenSlices()[source]
Returns True if the reader can open slices optimally. Without loading the whole file. If so, openSlice method should be implemented
- static getCompatibleExtensions() list[source]
Returns a list of the compatible extensions the reader can handle
- classmethod open(path)[source]
Opens the image in the path and returns a numpy array with the whole file (all slices included)
- 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:
objectClass to register image readers to provide basic information about an image like dimensions or getting an image
- classmethod addReader(imageReader: ImageReader)[source]
- classmethod getReader(filePath) ImageReader[source]
Returns the reader or None able to deal with filePath based on the extension.
- classmethod open(filePath) ImageStack[source]
Opens an image or image stack from the given file path.
This method serves as a public interface and delegates the actual loading to a cached internal method. It extracts the file last modification time (mtime) to ensure the cache is invalidated if the file changes.
- Parameters:
- filePath (str): Path to the image file. Can include a slice index in the format
‘1@path/to/image.ext’ to request a specific slice.
- Returns:
ImageStack: The loaded image data, either a single slice or a full 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:
objectClass 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
- classmethod asPilImage(npArray, normalize=True)[source]
Returns the npArray a numpy image :param npArray: 2d numpy array (image) :param normalize: by default it has to be normalized. Cancel this is you are sure it hase been normalized before
- flip(vertically=True)[source]
Flip all images of an ImageStack horizontally or vertically. Vertically is up-down, horizontally is left-right.
- highlight(stds=2)[source]
Increases de contrast of all slices :param stds: number of STD to apply the contrast
- classmethod highlightSlice(npImage: ndarray, stds=2)[source]
- Parameters
npImage – image as 2d numpy array
stds – number of STD to apply the contrast
- multiply(factor: float)[source]
Multiplies the image stack by a factor :param: factor: to multiply values by it
- rotate(angle, mode=ROT_MODE.FIXED, bg=None)[source]
rotates all its images the angle (deg) passed and returns a new ImageStack rotated
- classmethod rotateSlice(npArray: ndarray, angle: float, mode=ROT_MODE.CONDITIONAL, bg=None) ndarray[source]
Rotates a numpy array
- scale(factors, anti_aliasing=True)[source]
Scales the stack by the factors :param: factors: Scale factors for spatial dimensions.
- classmethod scaleSlice(npImage, factors, anti_aliasing=True)[source]
Scales the npImage by the factor/s :param npImage: 2d numpy array :param factors: float or sequence
The zoom factor along the axes. If a float, zoom is the same for each axis. If a sequence, zoom should contain one value for each axis.
- Parameters
anti_aliasing –
- shift(shifts)[source]
Shifts the whole stack x and y returning a new stack.
- Parameters
shift – The shift along the axes. If a float, shift is the same for each axis. If a sequence, shift should contain one value for each axis.
- classmethod shiftSlice(image: ndarray, shifts: float, bg=None) ndarray[source]
Shifts a numpy array :param shifts = float or sequence. If a sequence, first value should be X shift and second Y shift
- classmethod thumbnailSlice(npImage, width, height, normalize=True)[source]
Calls PIl thumbnail. It is less precise but faster than scaleSlice
- transform(shifts, angle, mode=ROT_MODE.FIXED)[source]
rotates all its images the angle (deg) passed and returns a new ImageStack rotated
- class pwem.emlib.image.image_readers.MRCImageReader[source]
Bases:
ImageReaderImage reader for MRC files
- classmethod canOpenSlices()[source]
Returns True if the reader can open slices optimally. Without loading the whole file. If so, openSlice method should be implemented
- static getCompatibleExtensions() list[source]
Returns a list of the compatible extensions the reader can handle
- classmethod open(path: str)[source]
Opens the image in the path and returns a numpy array with the whole file (all slices included)
- class pwem.emlib.image.image_readers.PILImageReader[source]
Bases:
ImageReaderPIL image reader
- static getCompatibleExtensions() list[source]
Returns a list of the compatible extensions the reader can handle
- classmethod open(filePath: str)[source]
Opens the image in the path and returns a numpy array with the whole file (all slices included)
- 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.ROT_MODE(value)[source]
Bases:
EnumAn enumeration.
- CONDITIONAL = 3
- FIXED = 1
- NATURAL = 2
- class pwem.emlib.image.image_readers.STKImageReader(fileName)[source]
Bases:
ImageReader- FLOAT32_BYTES = 4
- HEADER_OFFSET = 1024
- IMG_BYTES = None
- TYPE = None
- classmethod canOpenSlices()[source]
Returns True if the reader can open slices optimally. Without loading the whole file. If so, openSlice method should be implemented
- classmethod getCompatibleExtensions() list[source]
Returns a list of the compatible extensions the reader can handle
- header_info = None
- classmethod openSlice(path, slice)[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:
ImageReaderTiff image reader
- static getCompatibleExtensions() list[source]
Returns a list of the compatible extensions the reader can handle
- classmethod open(path: str)[source]
Opens the image in the path and returns a numpy array with the whole file (all slices included)
- 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