Skip to content

Commit

Permalink
Sort DICOMs with IPPSorter
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Mar 18, 2024
1 parent 4dfc374 commit 4837dd0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
23 changes: 19 additions & 4 deletions packages/dicom/gdcm/image-sets-normalization.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"

#include "gdcmIPPSorter.h"

int main(int argc, char *argv[])
{
itk::wasm::Pipeline pipeline("image-sets-normalization", "Group DICOM files into image sets", argc, argv);
Expand All @@ -35,13 +37,26 @@ int main(int argc, char *argv[])

ITK_WASM_PARSE(pipeline);

gdcm::IPPSorter ipps;

ipps.SetComputeZSpacing(true);
bool success = ipps.Sort(files);
std::cout << "success: " << success << std::endl;

std::vector<std::string> sortedFileNames = ipps.GetFilenames();

rapidjson::Document imageSetsJson;
imageSetsJson.SetObject();
rapidjson::Document::AllocatorType &allocator = imageSetsJson.GetAllocator();
imageSetsJson.SetObject();

rapidjson::Value sortedFileNameArray(rapidjson::kArrayType);
for (const std::string& fileName : sortedFileNames) {
rapidjson::Value fileNameValue;
fileNameValue.SetString(fileName.c_str(), fileName.size(), allocator);
sortedFileNameArray.PushBack(fileNameValue, allocator);
}

rapidjson::Value almostEqualValue;
almostEqualValue.SetBool(false);
imageSetsJson.AddMember("", almostEqualValue, allocator);
imageSetsJson.AddMember("sortedFileNames", sortedFileNameArray, allocator);

rapidjson::StringBuffer stringBuffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(stringBuffer);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

def test_image_sets_normalization():
files = [
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.3.dcm",
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm",
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm",
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.3.dcm",
]

assert files[0].exists()

output_text = image_sets_normalization(files)
assert output_text
image_sets = image_sets_normalization(files)
assert image_sets

sorted_file_names = image_sets.get("sortedFileNames")
assert sorted_file_names == [
str(files[1]),
str(files[2]),
str(files[0]),
]

0 comments on commit 4837dd0

Please sign in to comment.