Comparing images
1. Comparing images
How do you tell if your images are registered well? How would you compare an automatically segmented image with a hand-labeled one? To directly compare two arrays, you have to generate measures of image similarity.2. Comparing images
Here are two slices of the same person's brain, taken on separate occasions. You can see that they are similar objects but not aligned with each other. To quantify exactly how imperfect this alignment is, we need to apply a function that will compare the two images.3. Summary metrics
At the pixel level, there can be thousands and thousands of comparison points between two images. Our need is to summarize all of these comparisons into a single number. As with other areas of data science, such as machine learning, there are many ways to evaluate our data. There are cost functions, such as the mean absolute error or mean squared error, which should be minimized. Objective functions, such as the intersection of the union, are supposed to be maximized.4. Mean absolute error
Let's return to our two images, and calculate similarity using a cost function: the mean absolute error. First, we read in the images. Then, we find the error at each pixel by subtracting im2 from im1. Next, we take the absolute value of the error, because we care about whether the images differ from each other in any way, not whether one is larger than the other. Finally, we take the mean of the entire error image to get a single summary measure of similarity.5. Mean absolute error
The goal is not to achieve a mean absolute error of zero. In fact, that would mean the images were identical, which is not the case. Instead, you want to minimize the cost function by altering one or both images. Let's shift and rotate the first image, then re-compute the cost. We calculate the mean absolute error in the same way as before, using our new image. The new cost is lower than the previous one, suggesting that the two are better aligned than before.6. Intersection of the union
One issue with the mean absolute error approach is that tissues with high-intensity values will contribute more towards the error than other types. One remedy is to compare the image masks. The intersection of the union is a measure particularly well-suited to this. It is calculated by dividing the number of shared pixels between two masks by the total number of masked pixels. First, we create image masks by selecting pixels greater than 0. Second, we take the intersection of the two masks: that is, the pixels that appear in both masks. Next, we find the union: the pixels that appear in either mask. Finally, we divide the sum of the intersection by the sum of the union. The result is a number between 0 and 1, with 0 representing no shared mask pixels, and 1 representing perfect agreement.7. Let's practice!
The principle here is that summarizing image similarity with a single number gives you something to optimize when processing your images. Good luck with the exercises!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.