comparison OrthancStone/Sources/Toolbox/DicomInstanceParameters.cpp @ 1822:0489fe25ce48

support of pixel spacing in ultrasound images from tag SequenceOfUltrasoundRegions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 May 2021 18:13:35 +0200
parents 36430d73e36c
children 2789b4b0e0a8
comparison
equal deleted inserted replaced
1821:36430d73e36c 1822:0489fe25ce48
704 } 704 }
705 705
706 return true; 706 return true;
707 } 707 }
708 } 708 }
709
710
711 void DicomInstanceParameters::SetPixelSpacing(double pixelSpacingX,
712 double pixelSpacingY)
713 {
714 data_.hasPixelSpacing_ = true;
715 data_.pixelSpacingX_ = pixelSpacingX;
716 data_.pixelSpacingY_ = pixelSpacingY;
717 }
718
719
720 static const Json::Value* LookupDicomWebSingleValue(const Json::Value& dicomweb,
721 const std::string& tag,
722 const std::string& vr)
723 {
724 static const char* const VALUE = "Value";
725 static const char* const VR = "vr";
726
727 if (dicomweb.type() == Json::objectValue &&
728 dicomweb.isMember(tag) &&
729 dicomweb[tag].type() == Json::objectValue &&
730 dicomweb[tag].isMember(VALUE) &&
731 dicomweb[tag].isMember(VR) &&
732 dicomweb[tag][VR].type() == Json::stringValue &&
733 dicomweb[tag][VR].asString() == vr &&
734 dicomweb[tag][VALUE].type() == Json::arrayValue &&
735 dicomweb[tag][VALUE].size() == 1u)
736 {
737 return &dicomweb[tag][VALUE][0];
738 }
739 else
740 {
741 return NULL;
742 }
743 }
744
745
746 void DicomInstanceParameters::EnrichUsingDicomWeb(const Json::Value& dicomweb)
747 {
748 /**
749 * Use DICOM tag "SequenceOfUltrasoundRegions" (0018,6011) in
750 * order to derive the pixel spacing on ultrasound (US) images
751 **/
752
753 if (!data_.hasPixelSpacing_)
754 {
755 const Json::Value* region = LookupDicomWebSingleValue(dicomweb, "00186011", "SQ");
756 if (region != NULL)
757 {
758 const Json::Value* physicalUnitsXDirection = LookupDicomWebSingleValue(*region, "00186024", "US");
759 const Json::Value* physicalUnitsYDirection = LookupDicomWebSingleValue(*region, "00186026", "US");
760 const Json::Value* physicalDeltaX = LookupDicomWebSingleValue(*region, "0018602C", "FD");
761 const Json::Value* physicalDeltaY = LookupDicomWebSingleValue(*region, "0018602E", "FD");
762
763 if (physicalUnitsXDirection != NULL &&
764 physicalUnitsYDirection != NULL &&
765 physicalDeltaX != NULL &&
766 physicalDeltaY != NULL &&
767 physicalUnitsXDirection->type() == Json::intValue &&
768 physicalUnitsYDirection->type() == Json::intValue &&
769 physicalUnitsXDirection->asInt() == 0x0003 && // Centimeters
770 physicalUnitsYDirection->asInt() == 0x0003 && // Centimeters
771 physicalDeltaX->isNumeric() &&
772 physicalDeltaY->isNumeric())
773 {
774 // Scene coordinates are expressed in millimeters => multiplication by 10
775 SetPixelSpacing(10.0 * physicalDeltaX->asDouble(),
776 10.0 * physicalDeltaY->asDouble());
777 }
778 }
779 }
780 }
709 } 781 }