<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Import necessary libraries
Step1:  Some metadata is required before registration
Step2:  Load the sample data
Step3:  Preprocessing
This step preprocesses the input CLARITY images by resampling them to match the resolution of the atlas, bias correcting the images, and normalizing them by subtracting the mean and dividing by the standard deviation of the image intensities.
Step4:  Registration
We want to obtain the parameters to transform the original image to the new image. The transformation from the original image to the new image can be described as a composition of an affine transformation which can perform a combination of translation, scaling, rotation, and shear and deformable registration called LDDMM.
The output of this method is the atlas registered to the raw data
Step5:  Visualize registered image
The two images below should match if the registration worked successfully!
Step6:  Quantitative evaluation
Here, we print out the Mean Squared Error between both the atlas and the observed data. As we can see, this metric decreases from the unprocessed data (first cell below this one) to the final atlas registered to our data (3rd cell below this one)
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib
import ndreg
from ndreg import preprocessor, util, plotter
import SimpleITK as sitk
matplotlib.rcParams['figure.figsize'] = (10.0, 8.0)
def myshow(img, cmap='gray', colorbar=False):
    plt.imshow(sitk.GetArrayViewFromImage(img), cmap=cmap)
    if colorbar: plt.colorbar()
    plt.axis('off')
    plt.show()
Explanation: Import necessary libraries
End of explanation
params = {
    # input image path
    'image_path': './Thy1eYFP_Control_9.tiff',
    # voxel spacing is in mm and corresponds to (x, y, z) spacing
    'image_spacing': (0.04128, 0.04128, 0.04128),
    'image_orientation': 'rpi',
    # the modality can be 'lavision' or 'colm'
    'image_modality': 'lavision',
    'atlas_spacing': (0.05, 0.05, 0.05),
    'atlas_path': './ARA_50um.tiff',
}
Explanation: Some metadata is required before registration
End of explanation
img = util.imgRead(params['image_path'])
img.SetSpacing(params['image_spacing'])
atlas = util.imgRead(params['atlas_path'])
atlas.SetSpacing(params['atlas_spacing'])
plotter.imgShow(img, vmax=2000)
plotter.imgShow(atlas, vmax=400)
Explanation: Load the sample data
End of explanation
img_p = preprocessor.preprocess_brain(img, 
                                      params['atlas_spacing'], 
                                      params['image_modality'],
                                      params['image_orientation'])
Explanation: Preprocessing
This step preprocesses the input CLARITY images by resampling them to match the resolution of the atlas, bias correcting the images, and normalizing them by subtracting the mean and dividing by the standard deviation of the image intensities.
End of explanation
atlas_registered = ndreg.register_brain(atlas, img_p)
Explanation: Registration
We want to obtain the parameters to transform the original image to the new image. The transformation from the original image to the new image can be described as a composition of an affine transformation which can perform a combination of translation, scaling, rotation, and shear and deformable registration called LDDMM.
The output of this method is the atlas registered to the raw data
End of explanation
plotter.imgShow(atlas_registered)
plotter.imgShow(plotter.imgChecker(atlas_registered, img_p), vmax=2)
Explanation: Visualize registered image
The two images below should match if the registration worked successfully!
End of explanation
ndreg.imgMSE(sitk.Normalize(atlas), sitk.Normalize(img))
ndreg.imgMSE(sitk.Normalize(atlas), sitk.Normalize(img_p))
ndreg.imgMSE(sitk.Normalize(atlas_registered), sitk.Normalize(img_p))
Explanation: Quantitative evaluation
Here, we print out the Mean Squared Error between both the atlas and the observed data. As we can see, this metric decreases from the unprocessed data (first cell below this one) to the final atlas registered to our data (3rd cell below this one)
End of explanation
<END_TASK>