Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 1941:d7b176f7dd1b
test dicom patterns
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Mar 2016 11:27:38 +0100 |
parents | 5514d37176b4 |
children | a1c1c606ce98 |
comparison
equal
deleted
inserted
replaced
1940:5514d37176b4 | 1941:d7b176f7dd1b |
---|---|
766 } | 766 } |
767 } | 767 } |
768 | 768 |
769 | 769 |
770 | 770 |
771 TEST(TestImages, PatternGrayscale8) | |
772 { | |
773 static const char* PATH = "UnitTestsResults/PatternGrayscale8.dcm"; | |
774 | |
775 Orthanc::Image image(Orthanc::PixelFormat_Grayscale8, 256, 256); | |
776 | |
777 for (int y = 0; y < 256; y++) | |
778 { | |
779 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y)); | |
780 for (int x = 0; x < 256; x++, p++) | |
781 { | |
782 *p = y; | |
783 } | |
784 } | |
785 | |
786 Orthanc::ImageAccessor r = image.GetRegion(32, 32, 64, 192); | |
787 Orthanc::ImageProcessing::Set(r, 0); | |
788 r = image.GetRegion(160, 32, 64, 192); | |
789 Orthanc::ImageProcessing::Set(r, 255); | |
790 | |
791 { | |
792 ParsedDicomFile f(true); | |
793 f.Replace(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); | |
794 f.Replace(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); | |
795 f.Replace(DICOM_TAG_PATIENT_ID, "ORTHANC"); | |
796 f.Replace(DICOM_TAG_PATIENT_NAME, "Orthanc"); | |
797 f.Replace(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); | |
798 f.Replace(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale8"); | |
799 f.EmbedImage(image); | |
800 | |
801 f.SaveToFile(PATH); | |
802 } | |
803 | |
804 { | |
805 std::string s; | |
806 Orthanc::Toolbox::ReadFile(s, PATH); | |
807 Orthanc::ParsedDicomFile f(s); | |
808 | |
809 std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); | |
810 ASSERT_EQ(256, decoded->GetWidth()); | |
811 ASSERT_EQ(256, decoded->GetHeight()); | |
812 ASSERT_EQ(Orthanc::PixelFormat_Grayscale8, decoded->GetFormat()); | |
813 | |
814 for (int y = 0; y < 256; y++) | |
815 { | |
816 const void* a = image.GetConstRow(y); | |
817 const void* b = decoded->GetConstRow(y); | |
818 ASSERT_EQ(0, memcmp(a, b, 256)); | |
819 } | |
820 } | |
821 } | |
822 | |
823 | |
824 TEST(TestImages, PatternRGB) | |
825 { | |
826 static const char* PATH = "UnitTestsResults/PatternRGB24.dcm"; | |
827 | |
828 Orthanc::Image image(Orthanc::PixelFormat_RGB24, 384, 256); | |
829 | |
830 for (int y = 0; y < 256; y++) | |
831 { | |
832 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y)); | |
833 for (int x = 0; x < 128; x++, p += 3) | |
834 { | |
835 p[0] = y; | |
836 p[1] = 0; | |
837 p[2] = 0; | |
838 } | |
839 for (int x = 128; x < 128 * 2; x++, p += 3) | |
840 { | |
841 p[0] = 0; | |
842 p[1] = 255 - y; | |
843 p[2] = 0; | |
844 } | |
845 for (int x = 128 * 2; x < 128 * 3; x++, p += 3) | |
846 { | |
847 p[0] = 0; | |
848 p[1] = 0; | |
849 p[2] = y; | |
850 } | |
851 } | |
852 | |
853 { | |
854 ParsedDicomFile f(true); | |
855 f.Replace(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); | |
856 f.Replace(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); | |
857 f.Replace(DICOM_TAG_PATIENT_ID, "ORTHANC"); | |
858 f.Replace(DICOM_TAG_PATIENT_NAME, "Orthanc"); | |
859 f.Replace(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); | |
860 f.Replace(DICOM_TAG_SERIES_DESCRIPTION, "RGB24"); | |
861 f.EmbedImage(image); | |
862 | |
863 f.SaveToFile(PATH); | |
864 } | |
865 | |
866 { | |
867 std::string s; | |
868 Orthanc::Toolbox::ReadFile(s, PATH); | |
869 Orthanc::ParsedDicomFile f(s); | |
870 | |
871 std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); | |
872 ASSERT_EQ(384, decoded->GetWidth()); | |
873 ASSERT_EQ(256, decoded->GetHeight()); | |
874 ASSERT_EQ(Orthanc::PixelFormat_RGB24, decoded->GetFormat()); | |
875 | |
876 for (int y = 0; y < 256; y++) | |
877 { | |
878 const void* a = image.GetConstRow(y); | |
879 const void* b = decoded->GetConstRow(y); | |
880 ASSERT_EQ(0, memcmp(a, b, 3 * 384)); | |
881 } | |
882 } | |
883 } | |
884 | |
885 | |
771 TEST(TestImages, PatternUint16) | 886 TEST(TestImages, PatternUint16) |
772 { | 887 { |
773 static const char* PATH = "UnitTestsResults/PatternGrayscale16.dcm"; | 888 static const char* PATH = "UnitTestsResults/PatternGrayscale16.dcm"; |
774 | 889 |
775 Orthanc::Image image(Orthanc::PixelFormat_Grayscale16, 256, 256); | 890 Orthanc::Image image(Orthanc::PixelFormat_Grayscale16, 256, 256); |
789 r = image.GetRegion(160, 32, 64, 192); | 904 r = image.GetRegion(160, 32, 64, 192); |
790 Orthanc::ImageProcessing::Set(r, 65535); | 905 Orthanc::ImageProcessing::Set(r, 65535); |
791 | 906 |
792 { | 907 { |
793 ParsedDicomFile f(true); | 908 ParsedDicomFile f(true); |
909 f.Replace(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); | |
910 f.Replace(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); | |
794 f.Replace(DICOM_TAG_PATIENT_ID, "ORTHANC"); | 911 f.Replace(DICOM_TAG_PATIENT_ID, "ORTHANC"); |
795 f.Replace(DICOM_TAG_PATIENT_NAME, "Orthanc"); | 912 f.Replace(DICOM_TAG_PATIENT_NAME, "Orthanc"); |
796 f.Replace(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); | 913 f.Replace(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); |
797 f.Replace(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale16"); | 914 f.Replace(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale16"); |
798 f.EmbedImage(image); | 915 f.EmbedImage(image); |
816 const void* b = decoded->GetConstRow(y); | 933 const void* b = decoded->GetConstRow(y); |
817 ASSERT_EQ(0, memcmp(a, b, 512)); | 934 ASSERT_EQ(0, memcmp(a, b, 512)); |
818 } | 935 } |
819 } | 936 } |
820 } | 937 } |
938 | |
939 | |
940 TEST(TestImages, PatternInt16) | |
941 { | |
942 static const char* PATH = "UnitTestsResults/PatternSignedGrayscale16.dcm"; | |
943 | |
944 Orthanc::Image image(Orthanc::PixelFormat_SignedGrayscale16, 256, 256); | |
945 | |
946 int16_t v = -32768; | |
947 for (int y = 0; y < 256; y++) | |
948 { | |
949 int16_t *p = reinterpret_cast<int16_t*>(image.GetRow(y)); | |
950 for (int x = 0; x < 256; x++, v++, p++) | |
951 { | |
952 *p = htole16(v); // Orthanc uses Little-Endian transfer syntax to encode images | |
953 } | |
954 } | |
955 | |
956 Orthanc::ImageAccessor r = image.GetRegion(32, 32, 64, 192); | |
957 Orthanc::ImageProcessing::Set(r, -32768); | |
958 r = image.GetRegion(160, 32, 64, 192); | |
959 Orthanc::ImageProcessing::Set(r, 32767); | |
960 | |
961 { | |
962 ParsedDicomFile f(true); | |
963 f.Replace(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7"); | |
964 f.Replace(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998"); | |
965 f.Replace(DICOM_TAG_PATIENT_ID, "ORTHANC"); | |
966 f.Replace(DICOM_TAG_PATIENT_NAME, "Orthanc"); | |
967 f.Replace(DICOM_TAG_STUDY_DESCRIPTION, "Patterns"); | |
968 f.Replace(DICOM_TAG_SERIES_DESCRIPTION, "SignedGrayscale16"); | |
969 f.EmbedImage(image); | |
970 | |
971 f.SaveToFile(PATH); | |
972 } | |
973 | |
974 { | |
975 std::string s; | |
976 Orthanc::Toolbox::ReadFile(s, PATH); | |
977 Orthanc::ParsedDicomFile f(s); | |
978 | |
979 std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0)); | |
980 ASSERT_EQ(256, decoded->GetWidth()); | |
981 ASSERT_EQ(256, decoded->GetHeight()); | |
982 ASSERT_EQ(Orthanc::PixelFormat_SignedGrayscale16, decoded->GetFormat()); | |
983 | |
984 for (int y = 0; y < 256; y++) | |
985 { | |
986 const void* a = image.GetConstRow(y); | |
987 const void* b = decoded->GetConstRow(y); | |
988 ASSERT_EQ(0, memcmp(a, b, 512)); | |
989 } | |
990 } | |
991 } |