pysdic.Image.to_file#
- Image.to_file(file_path)[source]#
Save the image to a file using OpenCV, with its own dtype.
The data are written without any conversion, so the format given by the file extension must support the dtype of the image:
numpy.uint8: every format supported by OpenCV.numpy.uint16:.png,.tif,.tiff,.jp2,.pgm,.ppm,.pnm.numpy.float32:.tif,.tiff,.exr,.pfm,.hdr.numpy.float64:.tif,.tiff.
Convert the image yourself (with
to_array()) to save it with another dtype.Warning
OpenCV writes color images in BGR order (BGRA with an alpha channel). Use the same channel order as
from_file()to get the same colors.Note
Requires the optional dependency
cv2(pip install opencv-python).- Parameters:
file_path (Union[str, os.PathLike]) – The path where the image will be saved. The extension selects the format.
- Raises:
ValueError – If the extension does not support the dtype of the image or if OpenCV fails to write the file.
TypeError – If the dtype of the image cannot be written by OpenCV.
- Return type:
None