-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(color): Fix RGB inconsistencies (#829)
* Fix RGB inconsistencies * Add color space conversion check * refactor(comments) : refactor comments in code * refactor(code): change requirements YBR_FULL_422 * fix(color): fix bug in color example * fix bug in image loader example * Refactoring function * fix: correct typo in color space conversion function * refactor: Refactor color space conversion functions --------- Co-authored-by: Alireza <[email protected]>
- Loading branch information
1 parent
76cc2c2
commit 2fc22bc
Showing
9 changed files
with
136 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
33 changes: 33 additions & 0 deletions
33
packages/dicomImageLoader/src/imageLoader/isColorConversionRequired.ts
This file contains 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 @@ | ||
/** | ||
* This function checks color space conversion data requirements before | ||
* applying them. This function was created to solve problems like the one | ||
* discussed in here https://discourse.orthanc-server.org/t/orthanc-convert-ybr-to-rgb-but-does-not-change-metadata/3533/17 | ||
* In this case, Orthanc server converts the pixel data from YBR to RGB, but maintain | ||
* the photometricInterpretation dicom tag in YBR | ||
* @param imageFrame | ||
* @param RGBA | ||
* @returns | ||
*/ | ||
export default function isColorConversionRequired(imageFrame, RGBA) { | ||
if (imageFrame === undefined) { | ||
return false; | ||
} | ||
const { rows, columns, photometricInterpretation, pixelDataLength } = | ||
imageFrame; | ||
|
||
if (photometricInterpretation.endsWith('420')) { | ||
return ( | ||
pixelDataLength !== | ||
(3 * Math.ceil(columns / 2) + Math.floor(columns / 2)) * rows | ||
); | ||
} else if (photometricInterpretation.endsWith('422')) { | ||
return ( | ||
pixelDataLength !== | ||
(3 * Math.ceil(columns / 2) + Math.floor(columns / 2)) * | ||
Math.ceil(rows / 2) + | ||
Math.floor(rows / 2) * columns | ||
); | ||
} else { | ||
return photometricInterpretation !== 'RGB'; | ||
} | ||
} |