MCPcopy Create free account
hub / github.com/SimpleITK/SimpleITK / save_image

Function save_image

docs/source/example_utils.py:29–46  ·  view source on GitHub ↗
(image: SimpleITK.Image, name: str, is_label: bool = False)

Source from the content-addressed store, hash-verified

27
28
29def save_image(image: SimpleITK.Image, name: str, is_label: bool = False):
30
31 if is_label:
32 output_img = SimpleITK.LabelToRGB(image)
33 elif image.GetPixelID() in [SimpleITK.sitkUInt8, SimpleITK.sitkVectorUInt8]:
34 output_img = image
35 else:
36 stats = SimpleITK.StatisticsImageFilter()
37 stats.Execute(image)
38
39 shift_scale = SimpleITK.ShiftScaleImageFilter()
40 shift_scale.SetOutputPixelType(SimpleITK.sitkUInt8)
41 shift_scale.SetShift(-stats.GetMinimum())
42 shift_scale.SetScale(255.0 / (stats.GetMaximum() - stats.GetMinimum()))
43
44 output_img = shift_scale.Execute(image)
45
46 SimpleITK.WriteImage(output_img, Path("..") / "images" / f"{name}.png")
47
48
49def run_example(module_name: str, func_name: str, args: list) -> dict:

Callers

nothing calls this directly

Calls 4

GetPixelIDMethod · 0.45
ExecuteMethod · 0.45
SetOutputPixelTypeMethod · 0.45
SetScaleMethod · 0.45

Tested by

no test coverage detected