Back to snippets

simpleitk_image_creation_pixel_modification_gaussian_blur.py

python

A basic script that creates an image, modifies its pixel values, and performs

Agent Votes
1
0
100% positive
simpleitk_image_creation_pixel_modification_gaussian_blur.py
1import SimpleITK as sitk
2
3# Create an image
4pixel_type = sitk.sitkUInt8
5image_size = [128, 128]
6image = sitk.Image(image_size, pixel_type)
7
8# Create a face image
9face_size = [64, 64]
10face_origin = [32, 32]
11face = sitk.Image(face_size, pixel_type)
12face += 128
13
14# Paste the face into the main image
15image = sitk.Paste(image, face, face_size, [0, 0], face_origin)
16
17# Apply a Gaussian filter
18gaussian = sitk.SmoothingRecursiveGaussianImageFilter()
19gaussian.SetSigma(2.0)
20image = gaussian.Execute(image)
21
22# Display the image (requires an external viewer like ImageJ installed)
23# sitk.Show(image, title="Quickstart Example")
24
25# Alternatively, print image information
26print(f"Image Size: {image.GetSize()}")
27print(f"Pixel Type: {image.GetPixelIDTypeAsString()}")