-
Notifications
You must be signed in to change notification settings - Fork 390
feat(adapters): overlapping segs with labelmap images #1815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sedghi
merged 27 commits into
cornerstonejs:main
from
pedrokohler:feat-overlapping-segs
Mar 13, 2025
Merged
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
534ddec
fix: method signature
pedrokohler be0dfbd
feat: functional overlapping segs per image
pedrokohler 2fbf21b
refactor: improve nomenclature and separate code
pedrokohler c591aaa
fix: test file name
pedrokohler 4b6a761
fix: segmentationStack example
pedrokohler 3113419
feat: make stack viewport work
pedrokohler ec8b82a
feat: use only necessary duplicated images
pedrokohler ce22e68
Merge branch 'main' of github.com:cornerstonejs/cornerstone3D into fe…
pedrokohler 8b6ebfb
fix: wrong imports
pedrokohler 7d3304e
chore: remove useless comment
pedrokohler 5188892
fix: empty image filter
pedrokohler 12b61ca
some wip
sedghi cfd78e0
Merge branch 'main' of github.com:cornerstonejs/cornerstone3D into fe…
pedrokohler 5352864
fix: type error
pedrokohler 033ef09
feat: skip overlapping checks
pedrokohler 691cb0f
Merge remote-tracking branch 'origin' into feat-overlapping-segs
pedrokohler ea4c5b8
run test again
pedrokohler a67ccb7
fix: jest test environment
pedrokohler e351d05
fix: labelmap data modified callback
pedrokohler b52d1fa
temp: simulate test on example
pedrokohler c93c014
fix
sedghi 7012781
run
sedghi b92d191
Revert "temp: simulate test on example"
pedrokohler ef76281
fix
sedghi 86bbf31
Merge branch 'feat-overlapping-segs' of https://github.com/pedrokohle…
sedghi 896a595
run checks again
pedrokohler 7906c81
fix: ignore prettier
pedrokohler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable */ | ||
const base = require("../../jest.config.base.js"); | ||
const path = require("path"); | ||
|
||
module.exports = { | ||
...base, | ||
displayName: "adapters", | ||
moduleNameMapper: { | ||
"^@cornerstonejs/(.*)$": path.resolve(__dirname, "../$1/src") | ||
}, | ||
testEnvironment: undefined | ||
}; |
81 changes: 81 additions & 0 deletions
81
packages/adapters/src/adapters/Cornerstone3D/Segmentation/compactMergeSegData.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const checkHasOverlapping = ({ largerArray, currentTestedArray, newArray }) => | ||
largerArray.some((_, currentImageIndex) => { | ||
const originalImagePixelData = currentTestedArray[currentImageIndex]; | ||
|
||
const newImagePixelData = newArray[currentImageIndex]; | ||
|
||
if (!originalImagePixelData || !newImagePixelData) { | ||
return false; | ||
} | ||
|
||
return originalImagePixelData.some( | ||
(originalPixel, currentPixelIndex) => { | ||
const newPixel = newImagePixelData[currentPixelIndex]; | ||
return originalPixel && newPixel; | ||
} | ||
); | ||
}); | ||
|
||
export const compactMergeSegmentDataWithoutInformationLoss = ({ | ||
arrayOfSegmentData, | ||
newSegmentData | ||
}) => { | ||
if (arrayOfSegmentData.length === 0) { | ||
arrayOfSegmentData.push(newSegmentData); | ||
return; | ||
} | ||
|
||
for ( | ||
let currentTestedIndex = 0; | ||
currentTestedIndex < arrayOfSegmentData.length; | ||
currentTestedIndex++ | ||
) { | ||
const currentTestedArray = arrayOfSegmentData[currentTestedIndex]; | ||
|
||
const originalArrayIsLarger = | ||
currentTestedArray.length > newSegmentData.length; | ||
const largerArray = originalArrayIsLarger | ||
? currentTestedArray | ||
: newSegmentData; | ||
|
||
const hasOverlapping = checkHasOverlapping({ | ||
currentTestedArray, | ||
largerArray, | ||
newArray: newSegmentData | ||
}); | ||
|
||
if (hasOverlapping) { | ||
continue; | ||
} | ||
|
||
largerArray.forEach((_, currentImageIndex) => { | ||
const originalImagePixelData = | ||
currentTestedArray[currentImageIndex]; | ||
const newImagePixelData = newSegmentData[currentImageIndex]; | ||
|
||
if ( | ||
(!originalImagePixelData && !newImagePixelData) || | ||
!newImagePixelData | ||
) { | ||
return; | ||
} | ||
|
||
if (!originalImagePixelData) { | ||
currentTestedArray[currentImageIndex] = newImagePixelData; | ||
return; | ||
} | ||
|
||
const mergedPixelData = originalImagePixelData.map( | ||
(originalPixel, currentPixelIndex) => { | ||
const newPixel = newImagePixelData[currentPixelIndex]; | ||
return originalPixel || newPixel; | ||
} | ||
); | ||
|
||
currentTestedArray[currentImageIndex] = mergedPixelData; | ||
}); | ||
return; | ||
} | ||
|
||
arrayOfSegmentData.push(newSegmentData); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.