Skip to content

Commit

Permalink
Fix bug when creating JSON output for merges.
Browse files Browse the repository at this point in the history
Fixed bug when creating the JSON for merged segments where more than
one file was produced. Instead of then splitting segments into different
entries in the outer array of the JSON, the segments have been written
to the inner array instead.
  • Loading branch information
michaelonken committed Nov 10, 2023
1 parent 35e761f commit c1f09ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
19 changes: 17 additions & 2 deletions apps/seg/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dcmqi_add_test(
--outputDICOM ${MODULE_TEMP_DIR}/liver_heart_seg_reordered.dcm
)


find_program(DCIODVFY_EXECUTABLE dciodvfy)

if(EXISTS ${DCIODVFY_EXECUTABLE})
Expand Down Expand Up @@ -139,6 +140,22 @@ dcmqi_add_test(
${itk2dcm}_makeSEG_multiple_segment_files_reordered
)

dcmqi_add_test(
NAME ${dcm2itk}_makeNRRD_merged_segment_file
MODULE_NAME ${MODULE_NAME}
COMMAND ${SEM_LAUNCH_COMMAND} $<TARGET_FILE:${dcm2itk}Test>
--compare ${BASELINE}/liver_seg.nrrd ${MODULE_TEMP_DIR}/makeNRRD_multiple_segments-1.nrrd
--compare ${BASELINE}/spine_seg.nrrd ${MODULE_TEMP_DIR}/makeNRRD_multiple_segments-2.nrrd
--compare ${BASELINE}/heart_seg.nrrd ${MODULE_TEMP_DIR}/makeNRRD_multiple_segments-3.nrrd
${dcm2itk}Test
--inputDICOM ${MODULE_TEMP_DIR}/liver_heart_seg.dcm
--outputDirectory ${MODULE_TEMP_DIR}
--prefix makeNRRD_merged_segment_file
--mergeSegments
TEST_DEPENDS
${itk2dcm}_makeSEG_multiple_segment_files
)

dcmqi_add_test(
NAME seg_meta_roundtrip
MODULE_NAME ${MODULE_NAME}
Expand All @@ -160,8 +177,6 @@ dcmqi_add_test(
${dcm2itk}_makeNRRD_multiple_segment_files
)



set(TEST_SEG_SIZES 24x38x3 23x38x3)

foreach(seg_size ${TEST_SEG_SIZES})
Expand Down
2 changes: 1 addition & 1 deletion include/dcmqi/JSONSegmentationMetaInformationHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace dcmqi {
// segGroupNumber starts with 0 and refers to the item in segmentsAttributesMappingList.
// if segGroupNumber is invalid, create segment within a newly created segmentation group
// otherwise add segment to the existing segmentation group identified by segGroupNumber
SegmentAttributes* createOrGetSegment(const int segGroupNumber, unsigned labelID);
SegmentAttributes* createOrGetSegment(const unsigned int segGroupNumber, unsigned labelID);

protected:

Expand Down
24 changes: 10 additions & 14 deletions libsrc/JSONSegmentationMetaInformationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,21 @@ namespace dcmqi {
return values;
}

SegmentAttributes *JSONSegmentationMetaInformationHandler::createOrGetSegment(const int segGroupNumber, const unsigned labelID) {
//std::cout << "DEBUG: num segmentations: " << this->segmentsAttributesMappingList.size() << std::endl;
/*
for (vector<map<unsigned,SegmentAttributes*> >::const_iterator vIt = this->segmentsAttributesMappingList.begin();
vIt != this->segmentsAttributesMappingList.end(); ++vIt) {
for(map<unsigned,SegmentAttributes*>::const_iterator mIt = vIt->begin();mIt!=vIt->end();++mIt){
SegmentAttributes *segmentAttributes = mIt->second;
if (segmentAttributes->getLabelID() == labelID)
return NULL;
}
}*/
SegmentAttributes *JSONSegmentationMetaInformationHandler::createOrGetSegment(const unsigned int segGroupNumber, const unsigned labelID) {
if (segGroupNumber < 1)
{
std::cerr << "ERROR: Segment group number must be >= 1" << std::endl;
return NULL;
}

SegmentAttributes *segment = new SegmentAttributes(labelID);
if (this->segmentsAttributesMappingList.size() < segGroupNumber+1) {
if (this->segmentsAttributesMappingList.size() < segGroupNumber) {
map<unsigned,SegmentAttributes*> tempMap;
tempMap[labelID] = segment;
this->segmentsAttributesMappingList.push_back(tempMap);
} else
this->segmentsAttributesMappingList[segGroupNumber][labelID] = segment;
} else {
this->segmentsAttributesMappingList[segGroupNumber-1][labelID] = segment;
}

return segment;
}
Expand Down
1 change: 0 additions & 1 deletion libsrc/OverlapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ OFCondition OverlapUtil::getSegmentsByPosition(SegmentsByPosition& result)
DCMSEG_DEBUG(ss.str());
}
DCMSEG_DEBUG("groupFramesByPosition(): Grouping segments by position took " << tm.getDiff() << " s");

return cond;
}

Expand Down

0 comments on commit c1f09ef

Please sign in to comment.