Normalize image for visualization and save as PNG
(self, image, filename)
| 104 | return image |
| 105 | |
| 106 | def normalize_and_save(self, image, filename): |
| 107 | """Normalize image for visualization and save as PNG""" |
| 108 | norm_image = image |
| 109 | |
| 110 | # Handle different pixel types similar to C++ implementation |
| 111 | if image.GetPixelIDValue() == SimpleITK.sitkLabelUInt8: |
| 112 | norm_image = SimpleITK.Cast(image, SimpleITK.sitkUInt8) |
| 113 | elif image.GetPixelIDValue() == SimpleITK.sitkLabelUInt16: |
| 114 | norm_image = SimpleITK.Cast(image, SimpleITK.sitkUInt16) |
| 115 | elif image.GetPixelIDValue() == SimpleITK.sitkLabelUInt32: |
| 116 | norm_image = SimpleITK.Cast(image, SimpleITK.sitkUInt32) |
| 117 | elif image.GetPixelIDValue() == SimpleITK.sitkLabelUInt64: |
| 118 | norm_image = SimpleITK.Cast(image, SimpleITK.sitkUInt64) |
| 119 | elif (image.GetPixelIDValue() == SimpleITK.sitkComplexFloat64 or |
| 120 | image.GetPixelIDValue() == SimpleITK.sitkComplexFloat32): |
| 121 | norm_image = SimpleITK.ComplexToModulus(image) |
| 122 | elif image.GetNumberOfComponentsPerPixel() != 1: |
| 123 | # Use magnitude for vector images |
| 124 | norm_image = SimpleITK.VectorMagnitude(image) |
| 125 | |
| 126 | # Extract center slice |
| 127 | norm_image = self.extract_slice(norm_image) |
| 128 | |
| 129 | # Rescale to 0-255 and convert to uint8 |
| 130 | out_image = SimpleITK.RescaleIntensity(norm_image, 0, 255) |
| 131 | out_image = SimpleITK.Cast(out_image, SimpleITK.sitkUInt8) |
| 132 | |
| 133 | SimpleITK.WriteImage(out_image, filename) |
| 134 | |
| 135 | def assert_image_tolerance_match(self, test_filename, baseline_filename, tolerance, test_tag, data_finder): |
| 136 | """Assert that test image matches baseline within tolerance using sitkCompareDriver executable""" |
nothing calls this directly
no test coverage detected