-
Notifications
You must be signed in to change notification settings - Fork 462
fix palette color image loading #2610
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
+193
−80
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d65319c
refactor the solution given
rodrigobasilio2022 e8cd341
fix fetch color tables
rodrigobasilio2022 57fb6f8
important refactors to optimize worker functionality
rodrigobasilio2022 d558195
refactor fetch palette data
rodrigobasilio2022 ec0af2e
fix clearly wrong test values
rodrigobasilio2022 f7fd308
refactor as reviewer suggestions
rodrigobasilio2022 21c90a1
Merge remote-tracking branch 'origin/main' into fix/palleteColorImages
wayfarer3130 e882d1b
Merge remote-tracking branch 'origin/main' into fix/palleteColorImages
wayfarer3130 33cb6bb
fix: Convert 16 bit declared as 8 palette color data
wayfarer3130 dda66f3
fix: or condition on setting 16 bit palette data
wayfarer3130 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
Some comments aren't visible on the classic Files Changed page.
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
44 changes: 44 additions & 0 deletions
44
packages/dicomImageLoader/src/imageLoader/colorSpaceConverters/fetchLUTForInstance.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,44 @@ | ||
| import type { Types } from '@cornerstonejs/core'; | ||
| import { metaData } from '@cornerstonejs/core'; | ||
| import { fetchPaletteData } from './fetchPaletteData'; | ||
|
|
||
| /** | ||
| * Fetches all necessary LUT data (palette, modality, VOI) for an image instance if not already loaded. | ||
| * This function only returns a promise if there is actual LUT data to fetch from metadata. | ||
| * TODO : Extend this to modality and VOI LUT fetching as needed. | ||
| * | ||
| * @param imageFrame - The ImageFrame to fetch LUT data for | ||
| * @returns Promise that resolves when all LUT data is fetched, or void if no fetching needed | ||
| */ | ||
| export async function fetchLUTForInstance( | ||
| imageFrame: Types.IImageFrame | ||
| ): Promise<void> | null { | ||
| const fetchPromises = []; | ||
|
|
||
| // Check if palette color LUTs need to be fetched | ||
| const needsPaletteLUT = | ||
| !imageFrame.redPaletteColorLookupTableData || | ||
| !imageFrame.greenPaletteColorLookupTableData || | ||
| !imageFrame.bluePaletteColorLookupTableData; | ||
|
|
||
| if (needsPaletteLUT) { | ||
| // Fetch palette data if not already loaded | ||
| const palettePromises = Promise.all([ | ||
| fetchPaletteData(imageFrame, 'red', null), | ||
| fetchPaletteData(imageFrame, 'green', null), | ||
| fetchPaletteData(imageFrame, 'blue', null), | ||
| ]).then(([redData, greenData, blueData]) => { | ||
| // Attach palette data to imageFrame | ||
| imageFrame.redPaletteColorLookupTableData = redData; | ||
wayfarer3130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| imageFrame.greenPaletteColorLookupTableData = greenData; | ||
| imageFrame.bluePaletteColorLookupTableData = blueData; | ||
| }); | ||
|
|
||
| fetchPromises.push(palettePromises); | ||
| } | ||
|
|
||
| // Only await if there are promises to fetch | ||
| if (fetchPromises.length > 0) { | ||
| await Promise.all(fetchPromises); | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
packages/dicomImageLoader/src/imageLoader/colorSpaceConverters/fetchPaletteData.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,33 @@ | ||
| import type { Types } from '@cornerstonejs/core'; | ||
| import { metaData } from '@cornerstonejs/core'; | ||
|
|
||
| /** | ||
| * Fetches the palette color lookup table data for a given color (red, green, or blue) from the image frame. | ||
| * If the data is not present on the image frame, it attempts to fetch it from the metadata store. | ||
| * @param imageFrame - The image frame containing palette information | ||
| * @param color - The color channel to fetch ('red', 'green', or 'blue') | ||
| * @param fallback - Value to return if palette data is not found | ||
| * @returns Promise resolving to the palette color lookup table data or fallback value | ||
| */ | ||
| export function fetchPaletteData( | ||
| imageFrame: Types.IImageFrame, | ||
| color: 'red' | 'green' | 'blue', | ||
| fallback | ||
| ) { | ||
| const data = imageFrame[`${color}PaletteColorLookupTableData`]; | ||
| if (data) { | ||
| return Promise.resolve(data); | ||
| } | ||
|
|
||
| const result = metaData.get('imagePixelModule', imageFrame.imageId); | ||
|
|
||
| if (result && typeof result.then === 'function') { | ||
| return result.then((module) => | ||
| module ? module[`${color}PaletteColorLookupTableData`] : fallback | ||
| ); | ||
| } else { | ||
| return Promise.resolve( | ||
| result ? result[`${color}PaletteColorLookupTableData`] : fallback | ||
| ); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.