-
Notifications
You must be signed in to change notification settings - Fork 162
Add gaussian and poisson noise options to projection applications #860
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
Open
axel-grc
wants to merge
1
commit into
RTKConsortium:main
Choose a base branch
from
axel-grc:Noise
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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,88 @@ | ||
| import itk | ||
|
|
||
| __all__ = [ | ||
| "add_rtknoise_group", | ||
| "SetNoiseFromArgParse", | ||
| ] | ||
|
|
||
|
|
||
| # Mimics rtknoise_section.ggo | ||
| def add_rtknoise_group(parser): | ||
| rtknoise_group = parser.add_argument_group("Noise") | ||
| rtknoise_group.add_argument( | ||
| "--gaussian", | ||
| help="Gaussian noise parameters: <mean> Noise level and <std> Noise standard deviation", | ||
| type=float, | ||
| nargs="+", | ||
| ) | ||
| rtknoise_group.add_argument( | ||
| "--poisson", | ||
| help=( | ||
| "Poisson noise parameters: <I0> Number of impinging photons per pixel " | ||
| "and <muref> reference linear attenuation coefficient" | ||
| ), | ||
| type=float, | ||
| nargs="+", | ||
| ) | ||
|
|
||
|
|
||
| def SetNoiseFromArgParse(projections, args_info): | ||
| OutputImageType = type(projections) | ||
| output = projections | ||
|
|
||
| if args_info.gaussian is not None: | ||
| noisy = itk.AdditiveGaussianNoiseImageFilter[ | ||
| OutputImageType, OutputImageType | ||
| ].New() | ||
| mean, std = args_info.gaussian | ||
| noisy.SetInput(output) | ||
| noisy.SetMean(mean) | ||
| noisy.SetStandardDeviation(std) | ||
| noisy.UpdateOutputInformation() | ||
| output = noisy.GetOutput() | ||
|
|
||
| if args_info.poisson is not None: | ||
| I0, muref = args_info.poisson | ||
|
|
||
| multiply = itk.MultiplyImageFilter[ | ||
| OutputImageType, OutputImageType, OutputImageType | ||
| ].New() | ||
| multiply.SetInput(output) | ||
| multiply.SetConstant(-muref) | ||
|
|
||
| expf = itk.ExpImageFilter[OutputImageType, OutputImageType].New() | ||
| expf.SetInput(multiply.GetOutput()) | ||
|
|
||
| multiply2 = itk.MultiplyImageFilter[ | ||
| OutputImageType, OutputImageType, OutputImageType | ||
| ].New() | ||
| multiply2.SetInput(expf.GetOutput()) | ||
| multiply2.SetConstant(I0) | ||
|
|
||
| poisson = itk.ShotNoiseImageFilter[OutputImageType].New() | ||
| poisson.SetInput(multiply2.GetOutput()) | ||
|
|
||
| threshold = itk.ThresholdImageFilter[OutputImageType].New() | ||
| threshold.SetInput(poisson.GetOutput()) | ||
| threshold.SetLower(1.0) | ||
| threshold.SetOutsideValue(1.0) | ||
|
|
||
| multiply3 = itk.MultiplyImageFilter[ | ||
| OutputImageType, OutputImageType, OutputImageType | ||
| ].New() | ||
| multiply3.SetInput(threshold.GetOutput()) | ||
| multiply3.SetConstant(1.0 / I0) | ||
|
|
||
| logf = itk.LogImageFilter[OutputImageType, OutputImageType].New() | ||
| logf.SetInput(multiply3.GetOutput()) | ||
|
|
||
| multiply4 = itk.MultiplyImageFilter[ | ||
| OutputImageType, OutputImageType, OutputImageType | ||
| ].New() | ||
| multiply4.SetInput(logf.GetOutput()) | ||
| multiply4.SetConstant(-1.0 / muref) | ||
|
|
||
| multiply4.UpdateOutputInformation() | ||
| output = multiply4.GetOutput() | ||
|
|
||
| return output |
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,5 @@ | ||
| section "Gaussian noise" | ||
| option "gaussian" - "Gaussian noise parameters: <mean> Noise level and <std> Noise standard deviation" double multiple no | ||
|
|
||
| section "Poisson noise" | ||
| option "poisson" - "Poisson noise parameters: <I0> Number of impinging photons per pixel and <muref> reference linear attenuation coefficient" double multiple no | ||
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
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
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.
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.
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.
This seems to make the mu_ref parameter mandatory. Why not. Though we could mention something like "e.g. set 0.01879, which is the attenuation coefficient of water at 75 keV".
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.
Same could be said about the mean parameter for gaussian noise. Default=0. would make sense, to me.
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.
The problem is that we can't use different default values for lists with gengetopt, so the same default value will be used for mean and std for example.
We can maybe add theses default values to the implementation part ?
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.
Or have slightly more complex Gaussian and Poisson ggo sections, with 2 parameters each?