| 213 | // Helper function to compute RMSE |
| 214 | template <typename TScalarType, typename CPUImageType, typename GPUImageType> |
| 215 | TScalarType |
| 216 | ComputeRMSE(const CPUImageType * cpuImage, const GPUImageType * gpuImage, TScalarType & rmsRelative) |
| 217 | { |
| 218 | ImageRegionConstIterator<CPUImageType> cit(cpuImage, cpuImage->GetLargestPossibleRegion()); |
| 219 | ImageRegionConstIterator<GPUImageType> git(gpuImage, gpuImage->GetLargestPossibleRegion()); |
| 220 | |
| 221 | TScalarType rmse = 0.0; |
| 222 | TScalarType sumCPUSquared = 0.0; |
| 223 | |
| 224 | for (cit.GoToBegin(), git.GoToBegin(); !cit.IsAtEnd(); ++cit, ++git) |
| 225 | { |
| 226 | auto cpu = static_cast<TScalarType>(cit.Get()); |
| 227 | TScalarType err = cpu - static_cast<TScalarType>(git.Get()); |
| 228 | rmse += err * err; |
| 229 | sumCPUSquared += cpu * cpu; |
| 230 | } |
| 231 | |
| 232 | rmse = std::sqrt(rmse / cpuImage->GetLargestPossibleRegion().GetNumberOfPixels()); |
| 233 | rmsRelative = rmse / std::sqrt(sumCPUSquared / cpuImage->GetLargestPossibleRegion().GetNumberOfPixels()); |
| 234 | |
| 235 | return rmse; |
| 236 | } // end ComputeRMSE() |
| 237 | |
| 238 | |
| 239 | //------------------------------------------------------------------------------ |