Skip to content
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

fix: targetbuffer check and scaling fix #522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ouwen
Copy link
Contributor

@Ouwen Ouwen commented Mar 30, 2023

Prescaling can cause Uint16 type underflows which require the logic in scaleArray to account for negative values.

@netlify
Copy link

netlify bot commented Mar 30, 2023

Deploy Preview for cornerstone-wado-image-loader ready!

Name Link
🔨 Latest commit f5388f7
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-wado-image-loader/deploys/64259d19cebbba00083f2a74
😎 Deploy Preview https://deploy-preview-522--cornerstone-wado-image-loader.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

const { rescaleSlope, rescaleIntercept, suvbw } = scalingParameters;
const rescaleSlope = scalingParameters?.rescaleSlope || 1;
const rescaleIntercept = scalingParameters?.rescaleIntercept || 0;
const suvbw = scalingParameters?.suvbw || 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should we go through headache of the scale and intercept for large arrays if they are undefiend? can we return early instead? Also don't think we get to here at all if rescaleSlope and rescaleIntercept are not numbers because of the check in decodeImageFrame.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So reviewing it looks like there is a check to see if slope/intercept exist before scaleArray is called:

if (
typeof rescaleSlope === 'number' &&
typeof rescaleIntercept === 'number'
) {
scaleArray(
imageFrame,
options.preScale,
pixelDataArray,
scalingParameters
);
}

Additionally, if it is a PET modality and suvbw is not defined the other prescaling is ignored entirely (early return so no prescale). I'm not sure if this desirable because other scale params may exist.

This diff would set defaults and it shouldn't be more computationally expensive than current commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I guess we can say that in this function always typeof rescaleSlope === 'number' is true, so no need for scalingParameters?.rescaleSlope || 1; right?
I guess you are right about the PT scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured for readability I just follow the PET case since it doesn’t change the functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m okay either way, I can remove the || defaults too

const value = suvbw * (array[i] * rescaleSlope + rescaleIntercept);

array[i] = value;
if (value < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be faster if we don't check on value < 0 if the isNegative is true too ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check!

Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments

@Ouwen Ouwen force-pushed the gradienthealth/fix_prescaling branch from a4d973e to f5388f7 Compare March 30, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants