Image
Описание¶
Image используется для представления изображения внутри фреймворка.
Основные способы создания:
Image.from_path(path)— загрузка с дискаImage.from_base64(data)— загрузка из base64-строкиimage.show()— вывод через matplotlib (корректно работает в Jupyter, в отличие отcv2.imshow)image.save(path)— сохранение в файл
При помощи метода from_path в память может быть загружено изображение в форматах: .jpg / .jpeg, .png, .tif / .tiff и .dcm. По умолчанию загружаемые файлы проверяются на соответствие допустимым MIME-типам — невалидные файлы отклоняются при strict=True.
from hyppopipe.data.image import Image
image = Image.from_path("fundus.tif")
image.show()
image.save("preview.png")
Документация¶
Medical and general-purpose image loading as torch tensors.
Image
dataclass
¶
Bases: DataResource
Immutable image container with optional sample metadata.
Example
Load from disk and display::
img = Image.from_path("scan.png")
img.show()
other_img = Image.from_base64("...")
other_img.show()
Attributes:
| Name | Type | Description |
|---|---|---|
body |
Tensor
|
Image tensor, typically uint8 CHW from decoders. |
sample_id |
str | None
|
Optional identifier (filename stem when loaded from a path). |
legend |
dict[str, Any] | None
|
Optional arbitrary metadata attached to the sample. |
as_gray
property
¶
Single-channel grayscale tensor derived from body.
base64
property
¶
Base64-encoded tensor archive (round-trips with :meth:from_base64).
base64png
property
¶
Base64-encoded PNG (decodable with OpenCV, Pillow, etc.).
shape
property
¶
Shape of body.
tensor
property
¶
Underlying image tensor.
from_base64(payload)
classmethod
¶
Load an image from base64.
Accepts payloads produced by :attr:base64 (numpy array archive) or
standard base64-encoded image files (PNG, JPEG, etc.).
from_path(path, *, strict=True)
classmethod
¶
Load an image from a supported file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
File path (JPEG, PNG, TIFF, or DICOM). |
required |
strict
|
bool
|
If True, verify content type matches the extension. |
True
|
Returns:
| Type | Description |
|---|---|
Self
|
Loaded image with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path is invalid or the format is unsupported. |
save(path)
¶
show(**kwargs)
¶
Display the image with matplotlib.