Mercurial > hg > orthanc
changeset 1993:e2a3ff770b48
introducing float32 images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 14 May 2016 13:41:42 +0200 |
parents | 9161e3ef0d17 |
children | 4d099fee5eca |
files | Core/Enumerations.cpp Core/Enumerations.h Core/Images/ImageAccessor.cpp Core/Images/ImageProcessing.cpp |
diffstat | 4 files changed, 59 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Enumerations.cpp Mon May 09 17:56:32 2016 +0200 +++ b/Core/Enumerations.cpp Sat May 14 13:41:42 2016 +0200 @@ -37,6 +37,7 @@ #include "Toolbox.h" #include <string.h> +#include <cassert> namespace Orthanc { @@ -740,6 +741,9 @@ case PixelFormat_SignedGrayscale16: return "Grayscale (signed 16bpp)"; + case PixelFormat_Float32: + return "Grayscale (float 32bpp)"; + default: throw OrthancException(ErrorCode_ParameterOutOfRange); } @@ -913,6 +917,10 @@ case PixelFormat_RGBA32: return 4; + case PixelFormat_Float32: + assert(sizeof(float) == 4); + return 4; + default: throw OrthancException(ErrorCode_ParameterOutOfRange); }
--- a/Core/Enumerations.h Mon May 09 17:56:32 2016 +0200 +++ b/Core/Enumerations.h Sat May 14 13:41:42 2016 +0200 @@ -187,7 +187,13 @@ * {summary}{Graylevel, signed 16bpp image.} * {description}{The image is graylevel. Each pixel is signed and stored in two bytes.} **/ - PixelFormat_SignedGrayscale16 = 5 + PixelFormat_SignedGrayscale16 = 5, + + /** + * {summary}{Graylevel, floating-point image.} + * {description}{The image is graylevel. Each pixel is floating-point and stored in 4 bytes.} + **/ + PixelFormat_Float32 = 6 };
--- a/Core/Images/ImageAccessor.cpp Mon May 09 17:56:32 2016 +0200 +++ b/Core/Images/ImageAccessor.cpp Sat May 14 13:41:42 2016 +0200 @@ -65,7 +65,7 @@ for (unsigned int x = 0; x < source.GetWidth(); x++, p++) { - s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " "; + s += boost::lexical_cast<std::string>(static_cast<double>(*p)) + " "; } target.AddChunk(s); @@ -221,6 +221,10 @@ ToMatlabStringInternal<int16_t>(buffer, *this); break; + case PixelFormat_Float32: + ToMatlabStringInternal<float>(buffer, *this); + break; + case PixelFormat_RGB24: RGB24ToMatlabString(buffer, *this); break;
--- a/Core/Images/ImageProcessing.cpp Mon May 09 17:56:32 2016 +0200 +++ b/Core/Images/ImageProcessing.cpp Sat May 14 13:41:42 2016 +0200 @@ -75,9 +75,26 @@ } + template <typename SourceType> + static void ConvertGrayscaleToFloat(ImageAccessor& target, + const ImageAccessor& source) + { + for (unsigned int y = 0; y < source.GetHeight(); y++) + { + float* t = reinterpret_cast<float*>(target.GetRow(y)); + const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); + + for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) + { + *t = static_cast<float>(*s); + } + } + } + + template <typename TargetType> static void ConvertColorToGrayscale(ImageAccessor& target, - const ImageAccessor& source) + const ImageAccessor& source) { assert(source.GetFormat() == PixelFormat_RGB24); @@ -378,6 +395,27 @@ return; } + if (target.GetFormat() == PixelFormat_Float32 && + source.GetFormat() == PixelFormat_Grayscale8) + { + ConvertGrayscaleToFloat<uint8_t>(target, source); + return; + } + + if (target.GetFormat() == PixelFormat_Float32 && + source.GetFormat() == PixelFormat_Grayscale16) + { + ConvertGrayscaleToFloat<uint16_t>(target, source); + return; + } + + if (target.GetFormat() == PixelFormat_Float32 && + source.GetFormat() == PixelFormat_SignedGrayscale16) + { + ConvertGrayscaleToFloat<int16_t>(target, source); + return; + } + if (target.GetFormat() == PixelFormat_Grayscale8 && source.GetFormat() == PixelFormat_RGBA32) {