-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Allow polynomial function to dummy_segmentation function #2835
Conversation
y = y.reshape(nz) # reshape to vector (1,R) -> (R,) | ||
z = np.arange(0, nz) | ||
p = np.poly1d(np.polyfit(z, y, deg=nz)) | ||
# create regularized curve, within Y-Z plane (A-P), located at x=nx/2, passing through the following points: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it counterintuitive to have the polynomial shape only under interleaved. A clearer approach, would be to allow polynomial shape regardless what interleaved is, and in order to keep the same default behaviour, polynomial order could be set to one by default.
also note that i am starting to see a lot of similarity with dummy_centerline()
. At the end, a segmentation is just a centerline with a shape around it (ellipse or rectangle). Would it make sense to merge the two functions? Maybe this is a bad idea…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A clearer approach, would be to allow polynomial shape regardless what interleaved is, and in order to keep the same default behavior, polynomial order could be set to one by default.
Of course, it sounds better. Do we want to move to solely polynomial function (i.e., delete current code and let only code for polynomial) or let both options (polynomial and "non-polynomial")? So far, I modified code to choose either from original non-polynomial behavior or polynomial one in this commit: 6f13992
UPDATE:
(current non-polynomial segmentations are used in this unit testing, so probably the second option would be better)
also note that i am starting to see a lot of similarity with
dummy_centerline()
. At the end, a segmentation is just a centerline with a shape around it (ellipse or rectangle). Would it make sense to merge the two functions? Maybe this is a bad idea…
Yeah, there are a lot of similarities between dummy_centerline()
and dummy_segmentation()
, so we could probably merge these two functions. But I am not sure, if to start with this merging within this PR, because purpose of this PR should be to create interleaved 4D data to test sct_dmri_moco -interleaved
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to move to solely polynomial function (i.e., delete current code and let only code for polynomial) or let both options (polynomial and "non-polynomial")
simplest approach is always the best. if we can achieve the same functionality (and more) with less code, we should always go with less code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(current non-polynomial segmentations are used in this unit testing, so probably the second option would be better)
as mentioned above ^ if we can reach the same functionality with more general code, then the unit tests should pass (if they don't pass, it means there was a change in behaviour, which we should avoid-- expect if it affects input arguments, which is manageable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I am not sure, if to start with this merging within this PR, because purpose of this PR should be to create interleaved 4D data to test sct_dmri_moco -interleaved .
right-- let's do this merge in another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned above ^ if we can reach the same functionality with more general code, then the unit tests should pass (if they don't pass, it means there was a change in behavior, which we should avoid-- expect if it affects input arguments, which is manageable)
Okay, I tried to reduce and simplify code to let only polynomial function. Unfortunately, unit tests fail (see comment below).
d561807
to
57d2a77
Compare
…yfit to bspline, code simplification
After switch to purely polynomial curve in 1st fail is for segmentation with following parameters: This fail is probably caused by slightly different segmentation when using polynomial function (red-yellow) compared to segmentation created without polynomial function (white): 2nd fail is for: (again, polynomially created segmentation is slightly different compared to original one) |
@valosekj no worries, you can edit the "expected" values of the unit tests-- it is justified because the produced image is slightly different. |
Hm, I found out why segmentations were sometimes slightly different (and why unit tests failed). Problem was with conversion of fitted bspline curve from float to int. I added rounding before float -> int conversion in last commit 00af6f5 and now unit tests finished successfully. (I use bspline instead of polynomial fit based on recommendation from |
Now, after allowing regularized curve for
But, bspline which I am using now does return B-spline coefficients instead of polynomial terms which are returned by polynomial fitting. How to deal with it? When I try to choose random scalar for individual B-spline coefficients, it returns to me completely different segmentation. |
👍 I tried this in the last commit b1b5201 and it looks fine (all unit tests passed successfully). Now, if I want to choose random scalar for each term of the polynomial function, it is probably necessary to do this directly in by for example code like this:
Because |
well in that case you can simply bypass |
I tried to implement remaining steps from this comment in the last commit b7cef13. Example output: |
Fantastic work @valosekj ! I let you rebase the branch with master and switch off Draft mode if ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great contribution!
…oolbox#2835) * allow polynomial function to dummy_segmentation function * allow polynomial shape generally to whole dummy_segmentation function * keeping only polynomial curve for dummy_segmentation, switch from polyfit to bspline, code simplification * dummy_segmentation docstring fix * switch to straight segmentation (same location of AP points across SI direction) * add rounding before float->int conversion for fitted curve * switch from bspline to polyfit in dummy_segmentation() * add interleaved option to dummy_segmentation * comments clarification
This PR addresses creation of synthetic 4D interleaved data discusses here - #2664 (comment).
So far, I focused on this comment (#2664 (comment)) and allowed polynomial function to
dummy_segmentation
function in this commit - d561807. I took inspiration fromdummy_centerline
function.Is this implementation correct? I can produce following data with this implementation
(code used for creation of this data:)