| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
""" |
| 4 |
Image format Plugin for DataLab (example) |
| 5 |
========================================= |
| 6 |
|
| 7 |
This plugin is an example of how to add a new image file format to DataLab. |
| 8 |
|
| 9 |
It provides a new image file format, Dürr NDT XYZ, from Dürr NDT GmbH & Co. KG |
| 10 |
(see `Dürr NDT website <https://www.duerr-ndt.com/>`_). |
| 11 |
""" |
| 12 |
|
| 13 |
import numpy as np |
| 14 |
from sigima.io.base import FormatInfo |
| 15 |
from sigima.io.image.base import SingleImageFormatBase |
| 16 |
|
| 17 |
|
| 18 |
class XYZImageFormat(SingleImageFormatBase): |
| 19 |
"""Object representing Dürr NDT XYZ image file type""" |
| 20 |
|
| 21 |
FORMAT_INFO = FormatInfo( |
| 22 |
name="Dürr NDT", |
| 23 |
extensions="*.xyz", |
| 24 |
readable=True, |
| 25 |
writeable=False, |
| 26 |
) |
| 27 |
|
| 28 |
@staticmethod |
| 29 |
def read_data(filename: str) -> np.ndarray: |
| 30 |
"""Read data and return it |
| 31 |
|
| 32 |
Args: |
| 33 |
filename (str): path to XYZ file |
| 34 |
|
| 35 |
Returns: |
| 36 |
np.ndarray: image data |
| 37 |
""" |
| 38 |
with open(filename, "rb") as fdesc: |
| 39 |
cols = int(np.fromfile(fdesc, dtype=np.uint16, count=1)[0]) |
| 40 |
rows = int(np.fromfile(fdesc, dtype=np.uint16, count=1)[0]) |
| 41 |
arr = np.fromfile(fdesc, dtype=np.uint16, count=cols * rows) |
| 42 |
arr = arr.reshape((rows, cols)) |
| 43 |
return np.fliplr(arr) |