Mercurial > hg > orthanc
comparison Core/Images/ImageProcessing.cpp @ 4080:f18eaade6153
simplification in ImageProcessing::ShiftScale()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 22 Jun 2020 19:04:09 +0200 |
parents | 73c22208272f |
children | 2e1564f57542 |
comparison
equal
deleted
inserted
replaced
4079:73c22208272f | 4080:f18eaade6153 |
---|---|
384 } | 384 } |
385 } | 385 } |
386 | 386 |
387 | 387 |
388 // Computes "a * x + b" at each pixel => Note that this is not the | 388 // Computes "a * x + b" at each pixel => Note that this is not the |
389 // same convention as in "ShiftScale()" | 389 // same convention as in "ShiftScale()", but it is the convention of |
390 // "ShiftScale2()" | |
390 template <typename TargetType, | 391 template <typename TargetType, |
391 typename SourceType, | 392 typename SourceType, |
392 bool UseRound, | 393 bool UseRound, |
393 bool Invert> | 394 bool Invert> |
394 static void ShiftScaleInternal(ImageAccessor& target, | 395 static void ShiftScaleInternal(ImageAccessor& target, |
1365 throw OrthancException(ErrorCode_NotImplemented); | 1366 throw OrthancException(ErrorCode_NotImplemented); |
1366 } | 1367 } |
1367 } | 1368 } |
1368 | 1369 |
1369 | 1370 |
1370 void ImageProcessing::ShiftScale(ImageAccessor& image, | 1371 void ImageProcessing::ShiftScale2(ImageAccessor& image, |
1371 float offset, | 1372 float offset, |
1372 float scaling, | 1373 float scaling, |
1373 bool useRound) | 1374 bool useRound) |
1374 { | 1375 { |
1375 // Rewrite "(x + offset) * scaling" as "a * x + b" | 1376 // We compute "a * x + b" |
1376 | |
1377 const float a = scaling; | 1377 const float a = scaling; |
1378 const float b = offset * scaling; | 1378 const float b = offset; |
1379 | 1379 |
1380 switch (image.GetFormat()) | 1380 switch (image.GetFormat()) |
1381 { | 1381 { |
1382 case PixelFormat_Grayscale8: | 1382 case PixelFormat_Grayscale8: |
1383 if (useRound) | 1383 if (useRound) |
1428 throw OrthancException(ErrorCode_NotImplemented); | 1428 throw OrthancException(ErrorCode_NotImplemented); |
1429 } | 1429 } |
1430 } | 1430 } |
1431 | 1431 |
1432 | 1432 |
1433 void ImageProcessing::ShiftScale(ImageAccessor& target, | 1433 void ImageProcessing::ShiftScale2(ImageAccessor& target, |
1434 const ImageAccessor& source, | 1434 const ImageAccessor& source, |
1435 float offset, | 1435 float offset, |
1436 float scaling, | 1436 float scaling, |
1437 bool useRound) | 1437 bool useRound) |
1438 { | 1438 { |
1439 // Rewrite "(x + offset) * scaling" as "a * x + b" | 1439 // We compute "a * x + b" |
1440 | |
1441 const float a = scaling; | 1440 const float a = scaling; |
1442 const float b = offset * scaling; | 1441 const float b = offset; |
1443 | 1442 |
1444 switch (target.GetFormat()) | 1443 switch (target.GetFormat()) |
1445 { | 1444 { |
1446 case PixelFormat_Grayscale8: | 1445 case PixelFormat_Grayscale8: |
1447 | 1446 |
1468 throw OrthancException(ErrorCode_NotImplemented); | 1467 throw OrthancException(ErrorCode_NotImplemented); |
1469 } | 1468 } |
1470 } | 1469 } |
1471 | 1470 |
1472 | 1471 |
1473 void ImageProcessing::ShiftScale2(ImageAccessor& image, | 1472 void ImageProcessing::ShiftScale(ImageAccessor& image, |
1474 float offset, | 1473 float offset, |
1475 float scaling, | 1474 float scaling, |
1476 bool useRound) | 1475 bool useRound) |
1477 { | 1476 { |
1478 if (std::abs(scaling) < 0.001f) | 1477 // Rewrite "(x + offset) * scaling" as "a * x + b" |
1479 { | 1478 |
1480 Set(image, offset); | 1479 const float a = scaling; |
1481 } | 1480 const float b = offset * scaling; |
1482 else | 1481 ShiftScale2(image, b, a, useRound); |
1483 { | 1482 } |
1484 ShiftScale(image, offset / scaling, scaling, useRound); | 1483 |
1485 } | 1484 |
1486 } | 1485 void ImageProcessing::ShiftScale(ImageAccessor& target, |
1487 | 1486 const ImageAccessor& source, |
1488 | 1487 float offset, |
1489 void ImageProcessing::ShiftScale2(ImageAccessor& target, | 1488 float scaling, |
1490 const ImageAccessor& source, | 1489 bool useRound) |
1491 float offset, | 1490 { |
1492 float scaling, | 1491 // Rewrite "(x + offset) * scaling" as "a * x + b" |
1493 bool useRound) | 1492 |
1494 { | 1493 const float a = scaling; |
1495 if (std::abs(scaling) < 0.0001f) | 1494 const float b = offset * scaling; |
1496 { | 1495 ShiftScale2(target, source, b, a, useRound); |
1497 Set(target, offset); | |
1498 } | |
1499 else | |
1500 { | |
1501 ShiftScale(target, source, offset / scaling, scaling, useRound); | |
1502 } | |
1503 } | 1496 } |
1504 | 1497 |
1505 | 1498 |
1506 | 1499 |
1507 void ImageProcessing::Invert(ImageAccessor& image, int64_t maxValue) | 1500 void ImageProcessing::Invert(ImageAccessor& image, int64_t maxValue) |