pystiche.image
¶
Utilities¶
- pystiche.image.edge_to_image_size(edge_size, aspect_ratio, edge='short')¶
I/O¶
- pystiche.image.read_image(file, device='cpu', make_batched=True, size=None, interpolation_mode='bilinear')¶
Read an image from file with
PIL.Image
and return it asTensor
.- Parameters
file (
str
) – Path to image file to be read.device (
Union
[device
,str
]) – Device that the image is transferred to. Defaults to CPU.make_batched (
bool
) – IfTrue
, a fake batch dimension is added to the image.size (
Optional
[Union
[int
]]) – Optional size the image is resized to.interpolation_mode (
str
) – Interpolation mode that is used to perform the optional resizing. Valid modes are"nearest"
,"bilinear"
, and"bicubic"
. Defaults to"bilinear"
.
- Return type
- pystiche.image.write_image(image, file, mode=None, **save_kwargs)¶
Write a
Tensor
image to a file withPIL.Image
.- Parameters
image (
Tensor
) – Image to be written.file (
str
) – Path to image file.mode (
Optional
[str
]) – Optional image mode. See the Pillow documentation for details.**save_kwargs – Other parameters that are passed to
PIL.Image.Image.save()
.
- Return type
- pystiche.image.show_image(image, title=None, mode=None, size=None, interpolation_mode='bilinear')¶
Show an image and optionally read it from file first.
Note
show_image
usesmatplotlib.pyplot.imshow()
as primary means to show images. If that is not available the nativePIL.Image.Image.show()
is used as a fallback.- Parameters
image (
Union
[Tensor
,str
]) – Image to be shown. Ifstr
this is treated as a path to an image and is read byread_image()
.Optional image mode. See the Pillow documentation for details.
size (
Optional
[Union
[int
]]) – Optional size the image is resized to.interpolation_mode (
str
) – Interpolation mode that is used to perform the optional resizing. Valid modes are"nearest"
,"bilinear"
, and"bicubic"
. Defaults to"bilinear"
.
- Return type
Guides¶
- pystiche.image.verify_guides(guides, verify_coverage=True, verify_overlap=True)¶
Verify if guides cover the whole canvas and if they do not overlap with each other.
- Parameters
- Raises
RuntimeError – If at least on check is not successful.
- Return type
- pystiche.image.read_guides(dir, device='cpu', make_batched=True, size=None, interpolation_mode='nearest')¶
Read all guides from a directory using
read_image()
and return them as dictionary. The filename without extensions is used as region key.- Parameters
dir (
str
) – Path to root directory of the guide files.device (
Union
[device
,str
]) – Device that the guides are transferred to. Defaults to CPU.make_batched (
bool
) – IfTrue
, a fake batch dimension is added to every guide.size (
Optional
[Union
[int
]]) – Optional size the guides are resized to.interpolation_mode (
str
) – Interpolation mode that is used to perform the optional resizing. Valid modes are"nearest"
,"bilinear"
, and"bicubic"
. Defaults to"nearest"
.
- Return type
- pystiche.image.write_guides(guides, dir, ext='.png', mode='L', **save_kwargs)¶
Write guides to directory using
write_image()
. The region key is used as filename.- Parameters
dir (
str
) – Path to root directory of the guide files.ext (
str
) – Extension that is appended to the filename. Defaults to".png"
.mode (
str
) –Optional image mode. See the Pillow documentation for details. Defaults to
"L"
.**save_kwargs – Other parameters that are passed to
PIL.Image.Image.save()
.
- Return type
- pystiche.image.guides_to_segmentation(guides, color_map=None)¶
Combines multiple guides into one segmentation image.
- pystiche.image.segmentation_to_guides(seg, region_map=None)¶
Splits a segmentation image in multiple guides.