Mercurial > hg > orthanc-dicomweb
changeset 356:df5c69b5c9c3
taking rescale slope/intercept into account to render windowing
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Tue, 27 Aug 2019 15:32:47 +0200 |
| parents | 9b401e49a8e3 |
| children | ce9e8f6b4dff |
| files | Plugin/WadoRsRetrieveRendered.cpp |
| diffstat | 1 files changed, 75 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugin/WadoRsRetrieveRendered.cpp Mon Aug 26 10:24:55 2019 +0200 +++ b/Plugin/WadoRsRetrieveRendered.cpp Tue Aug 27 15:32:47 2019 +0200 @@ -61,6 +61,8 @@ float windowCenter_; float windowWidth_; WindowingMode windowingMode_; + float rescaleSlope_; + float rescaleIntercept_; static bool GetIntegerValue(int& target, std::vector<std::string>& tokens, @@ -122,7 +124,9 @@ quality_(90), // Default quality for JPEG previews (the same as in Orthanc core) windowCenter_(128), windowWidth_(256), - windowingMode_(WindowingMode_Linear) + windowingMode_(WindowingMode_Linear), + rescaleSlope_(1), + rescaleIntercept_(0) { static const std::string VIEWPORT("\"viewport\" in WADO-RS Retrieve Rendered Transaction"); static const std::string WINDOWING("\"windowing\" in WADO-RS Retrieve Rendered Transaction"); @@ -359,6 +363,26 @@ { return windowingMode_; } + + void SetRescaleSlope(float v) + { + rescaleSlope_ = v; + } + + float GetRescaleSlope() const + { + return rescaleSlope_; + } + + void SetRescaleIntercept(float v) + { + rescaleIntercept_ = v; + } + + float GetRescaleIntercept() const + { + return rescaleIntercept_; + } }; } @@ -408,7 +432,9 @@ const Orthanc::ImageAccessor& source, float c, float w, - WindowingMode mode) + WindowingMode mode, + float rescaleSlope, + float rescaleIntercept) { assert(target.GetFormat() == Orthanc::PixelFormat_Grayscale8 && source.GetFormat() == SourceFormat); @@ -484,6 +510,8 @@ for (unsigned int x = 0; x < width; x++) { float a = Orthanc::ImageTraits<SourceFormat>::GetFloatPixel(source, x, y); + a = rescaleSlope * a + rescaleIntercept; + float b; switch (mode) @@ -571,7 +599,17 @@ case Orthanc::PixelFormat_Grayscale16: ApplyWindowing<Orthanc::PixelFormat_Grayscale16>(scaled, region, parameters.GetWindowCenter(), parameters.GetWindowWidth(), - parameters.GetWindowingMode()); + parameters.GetWindowingMode(), + parameters.GetRescaleSlope(), + parameters.GetRescaleIntercept()); + break; + + case Orthanc::PixelFormat_SignedGrayscale16: + ApplyWindowing<Orthanc::PixelFormat_SignedGrayscale16>(scaled, region, parameters.GetWindowCenter(), + parameters.GetWindowWidth(), + parameters.GetWindowingMode(), + parameters.GetRescaleSlope(), + parameters.GetRescaleIntercept()); break; default: @@ -622,6 +660,9 @@ int frame, const OrthancPluginHttpRequest* request) { + static const char* const RESCALE_INTERCEPT = "0028,1052"; + static const char* const RESCALE_SLOPE = "0028,1053"; + OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); if (request->method != OrthancPluginHttpMethod_Get) @@ -674,6 +715,37 @@ { buffer.GetDicomInstance(instanceId); + Json::Value tags; + buffer.DicomToJson(tags, OrthancPluginDicomToJsonFormat_Short, OrthancPluginDicomToJsonFlags_None, 255); + + if (tags.isMember(RESCALE_SLOPE) && + tags[RESCALE_SLOPE].type() == Json::stringValue) + { + try + { + parameters.SetRescaleSlope + (boost::lexical_cast<float> + (Orthanc::Toolbox::StripSpaces(tags[RESCALE_SLOPE].asString()))); + } + catch (boost::bad_lexical_cast&) + { + } + } + + if (tags.isMember(RESCALE_INTERCEPT) && + tags[RESCALE_INTERCEPT].type() == Json::stringValue) + { + try + { + parameters.SetRescaleIntercept + (boost::lexical_cast<float> + (Orthanc::Toolbox::StripSpaces(tags[RESCALE_INTERCEPT].asString()))); + } + catch (boost::bad_lexical_cast&) + { + } + } + OrthancPlugins::OrthancImage dicom; dicom.DecodeDicomImage(buffer.GetData(), buffer.GetSize(), static_cast<unsigned int>(frame - 1));
