Hello,
I am registering some images using the method below. Everything works fine, except that for some reason, there is a file called TransformParameters.0.txt
that is being created in the same directory where I run my script. I would like for that file to not be stored, since I do not need it. Would it be possible to indicate to SimpleElastix to not store such intermediate files?
def register_images(x: blosc2.NDArray, output: Path, reference_index: int, overwrite: bool, keep: bool) -> blosc2.NDArray:
"""Registers images using the method described by Schöll et. al.
This method applies the following steps:
1. Compute and apply affine transformation using SIFT between reference image and target image
2. Apply high pass filter to affine registered image and reference image
3. Compute elastic registration transformation between filtered images
4. Apply elastic transformation to affine registered image
[] https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5435296/
:param x: array containing images to register
:param output: folder where results are stored
:param reference_index: index used to identify the reference image from :code:`x` (first axis).
:param overwrite: whether contents of output should be overwritten
:return: path to file where registered images are stored
"""
# create object to store data
output_file = output.parent / (output.stem + "_registered.b2nd")
if output_file.is_file() and not overwrite and keep:
raise ValueError(f"File already exists: {output_file}")
elif keep:
data_storage = ArrayToB2ND(file_path=output_file, mode="w")
else:
data_storage = ArrayToB2ND()
# process reference image
reference = x[reference_index, ...].astype(np.uint16)
reference_blur = cv2.GaussianBlur(reference, **BLUR_ARGS)
reference_diff = reference - reference_blur
# Create elastic transformation object
#TODO do not store intermediate files
elastic_filter = sitk.ElastixImageFilter()
elastic_filter.SetFixedImage(sitk.GetImageFromArray(reference_diff))
parameter_map_vector = sitk.VectorOfParameterMap()
parameter_map = sitk.GetDefaultParameterMap('bspline')
parameter_map["WriteResultImage"] = "false"
parameter_map_vector.append(parameter_map)
elastic_filter.SetParameterMap(parameter_map_vector)
elastic_filter.LogToConsoleOn()
elastic_transform_image_filter = sitk.TransformixImageFilter()
for i in track(range(0, x.shape[0]), description="registering images"):
im = x[i, ...].astype(np.uint16)
if i == 0:
im_elastic = sitk.GetImageFromArray(im.astype("float32"))
else:
im_blur = cv2.GaussianBlur(im, **BLUR_ARGS)
diff = im_blur - reference_blur
# compute elastic transformation
elastic_filter.SetMovingImage(sitk.GetImageFromArray(diff))
elastic_filter.Execute()
transform_map = elastic_filter.GetTransformParameterMap()
# apply elastic transformation
elastic_transform_image_filter.SetTransformParameterMap(transform_map)
elastic_transform_image_filter.SetMovingImage(sitk.GetImageFromArray(im))
elastic_transform_image_filter.Execute()
im_elastic = elastic_transform_image_filter.GetResultImage()
# store results
data_storage.append_array(sitk.GetArrayFromImage(im_elastic))
data_storage.append_metadata(x.schunk.vlmeta)
return data_storage.b2nd
Cheers.