MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / compareImages

Function compareImages

Source/Tools/ImageCompare/ImageCompare.cpp:301–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

299}
300
301static bool compareImages(
302 const std::filesystem::path& pathA,
303 const std::filesystem::path& pathB,
304 ErrorMetric metric,
305 float threshold,
306 bool alpha,
307 const std::filesystem::path& heatMapPath
308)
309{
310 auto loadImage = [](const std::filesystem::path& path)
311 {
312 try
313 {
314 return Image::loadFromFile(path);
315 }
316 catch (const std::runtime_error& e)
317 {
318 std::cerr << "Cannot load image from '" << path.string() << "' (Error: " << e.what() << ")." << std::endl;
319 return std::shared_ptr<Image>{};
320 }
321 };
322
323 auto saveImage = [](const Image& image, const std::filesystem::path& path)
324 {
325 try
326 {
327 image.saveToFile(path);
328 }
329 catch (const std::runtime_error& e)
330 {
331 std::cerr << "Cannot save image to '" << path.string() << "' (Error: " << e.what() << ")." << std::endl;
332 }
333 };
334
335 // Load images.
336 auto imageA = loadImage(pathA);
337 if (!imageA)
338 return false;
339 auto imageB = loadImage(pathB);
340 if (!imageB)
341 return false;
342
343 // Check resolution.
344 if (imageA->getWidth() != imageB->getWidth() || imageA->getHeight() != imageB->getHeight())
345 {
346 std::cerr << "Cannot compare images with different resolutions." << std::endl;
347 return false;
348 }
349
350 uint32_t width = imageA->getWidth();
351 uint32_t height = imageB->getHeight();
352
353 // Compare images.
354 std::unique_ptr<float[]> errorMap = heatMapPath.empty() ? nullptr : std::make_unique<float[]>(width * height);
355 double error = metric.compare(*imageA, *imageB, alpha, errorMap.get());
356
357 // Generate heat map.
358 if (errorMap)

Callers 1

mainFunction · 0.85

Calls 11

generateHeatMapFunction · 0.85
whatMethod · 0.80
getWidthMethod · 0.80
getHeightMethod · 0.80
isnanFunction · 0.50
isinfFunction · 0.50
stringMethod · 0.45
saveToFileMethod · 0.45
emptyMethod · 0.45
compareMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected