-
Notifications
You must be signed in to change notification settings - Fork 5
Read noise #39
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
dlagattuta
wants to merge
28
commits into
main
Choose a base branch
from
readNoise
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
Read noise #39
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
5b8ed68
updating readNoise class
dlagattuta 49c1f37
Merge pull request #38 from dlagattuta/readNoise
dlagattuta fd5c2da
Update read_noise.py
dlagattuta c3a4e24
Update .gitignore
dlagattuta 96778e7
Update read_noise.py
dlagattuta ca592fd
Update read_noise.py
dlagattuta f366443
Update read_noise.py
dlagattuta a300a68
updated readme
rjmassey 169cedd
Update read_noise.py
dlagattuta c04513e
Merge branch 'readNoise' of https://github.com/jkeger/arctic into rea…
dlagattuta 6a42b8b
Update read_noise.py
dlagattuta e447034
comments added
rjmassey f9c3ec6
update read_noise.py
dlagattuta a8ce2dd
Update read_noise.py
dlagattuta 38cee6d
Update read_noise.py
dlagattuta feb4572
Update read_noise.py
dlagattuta 92d8aaf
Update read_noise.py
dlagattuta 38d0aa8
Update read_noise.py
dlagattuta d867f99
updated read_noise.py and test_arcticpy.py
dlagattuta dc67000
Update test_arcticpy.py
dlagattuta 2948bae
Update test_arcticpy.py
dlagattuta 588c0ba
Update read_noise.py
dlagattuta a410659
speed ups for noise treatment
bea2521
some type hints; further fixes
f1aa23b
fixed typo
f41fabf
added new c implementation; updated setup.py
0db1946
fix to setup.py (g++ does not work for read_noise extension)
e8e2c09
Merge pull request #43 from jkeger/fix/readNoise
dlagattuta 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <math.h> | ||
|
|
||
| #define SQUARE(x) ((x) * (x)) | ||
|
|
||
| void determine_noise_model(const double* imageIn, const double* imageOut, const int rows, const int cols, const double readNoiseAmp, const double readNoiseAmpFraction, const int smoothCol, double* output) { | ||
|
|
||
| double* dval0 = output; // using already allocated output buffer to temporarily store the results to avoid allocating more memory (safe as long as we do not modify output before storing dval0 there and not use dval0 after modifying output for the first time) | ||
| double* dval9 = (double*)malloc(rows * cols * sizeof(double)); | ||
|
|
||
| double mod_clip = readNoiseAmp * readNoiseAmpFraction; | ||
| double readNoiseAmp2 = SQUARE(readNoiseAmp); | ||
|
|
||
| int idx; | ||
|
|
||
| for (int i = 0; i < rows * cols; i++) { | ||
| dval0[i] = imageIn[i] - imageOut[i]; | ||
| dval9[i] = dval0[i]; | ||
| } | ||
|
|
||
| // get the dval9 average | ||
| // inner part | ||
| for (int i = 1; i < rows - 1; i++) { | ||
| #pragma omp parallel for private(idx) | ||
| for (int j = 1; j < cols - 1; j++) { | ||
| idx = i * cols + j; | ||
| dval9[idx] += dval0[idx + cols + 1]; // comparison with bottom-left neighbour | ||
| dval9[idx] += dval0[idx + cols]; // comparison with bottom-central neighbour | ||
| dval9[idx] += dval0[idx + cols - 1]; // comparison with bottom-right neighbour | ||
| dval9[idx] += dval0[idx + 1]; // comparison with middle-left neighbour | ||
| dval9[idx] += dval0[idx - 1]; // comparison with middle-right neighbour | ||
| dval9[idx] += dval0[idx - cols + 1]; // comparison with top-left neighbour | ||
| dval9[idx] += dval0[idx - cols]; // comparison with top-central neighbour | ||
| dval9[idx] += dval0[idx - cols - 1]; // comparison with top-right neighbour | ||
| dval9[idx] /= 9; | ||
| } | ||
| } | ||
| // edges (excl. corners) | ||
| #pragma omp parallel for private(idx) | ||
| for (int i = 1; i < rows - 1; i++) { | ||
| // left edge (j=0) | ||
| idx = i * cols; | ||
| dval9[idx] += dval0[idx + cols + 1]; // comparison with bottom-left neighbour | ||
| dval9[idx] += dval0[idx + cols]; // comparison with bottom-central neighbour | ||
| dval9[idx] += dval0[idx + 1]; // comparison with middle-left neighbour | ||
| dval9[idx] += dval0[idx - cols + 1]; // comparison with top-left neighbour | ||
| dval9[idx] += dval0[idx - cols]; // comparison with top-central neighbour | ||
| dval9[idx] /= 6.0; | ||
| // right edge (j=cols-1) | ||
| idx = (i + 1) * cols - 1; | ||
| dval9[idx] += dval0[idx + cols]; // comparison with bottom-central neighbour | ||
| dval9[idx] += dval0[idx + cols - 1]; // comparison with bottom-right neighbour | ||
| dval9[idx] += dval0[idx - 1]; // comparison with middle-right neighbour | ||
| dval9[idx] += dval0[idx - cols]; // comparison with top-central neighbour | ||
| dval9[idx] += dval0[idx - cols - 1]; // comparison with top-right neighbour | ||
| dval9[idx] /= 6.0; | ||
| } | ||
|
|
||
| #pragma omp parallel for private(idx), shared(dval0, dval9) | ||
| for (int j = 1; j < cols - 1; j++) { | ||
| // top edge (i=0) | ||
| idx = j; | ||
| dval9[idx] += dval0[idx + cols + 1]; // comparison with bottom-left neighbour | ||
| dval9[idx] += dval0[idx + cols]; // comparison with bottom-central neighbour | ||
| dval9[idx] += dval0[idx + cols - 1]; // comparison with bottom-right neighbour | ||
| dval9[idx] += dval0[idx + 1]; // comparison with middle-left neighbour | ||
| dval9[idx] += dval0[idx - 1]; // comparison with middle-right neighbour | ||
| dval9[idx] /= 6.0; | ||
| // bottom edge (i=rows-1) | ||
| idx = (rows - 1) * cols + j; | ||
| dval9[idx] += dval0[idx + 1]; // comparison with middle-left neighbour | ||
| dval9[idx] += dval0[idx - 1]; // comparison with middle-right neighbour | ||
| dval9[idx] += dval0[idx - cols + 1]; // comparison with top-left neighbour | ||
| dval9[idx] += dval0[idx - cols]; // comparison with top-central neighbour | ||
| dval9[idx] += dval0[idx - cols - 1]; // comparison with top-right neighbour | ||
| dval9[(rows - 1) * cols + j] /= 6.0; | ||
| } | ||
| // corners | ||
| dval9[0] += dval0[cols + 1]; // comparison with bottom-left neighbour | ||
| dval9[0] += dval0[cols]; // comparison with bottom-central neighbour | ||
| dval9[0] += dval0[1]; // comparison with middle-left neighbour | ||
| dval9[0] /= 4.0; | ||
|
|
||
| idx = cols - 1; | ||
| dval9[idx] += dval0[idx + cols]; // comparison with bottom-central neighbour | ||
| dval9[idx] += dval0[idx + cols - 1]; // comparison with bottom-right neighbour | ||
| dval9[idx] += dval0[idx - 1]; // comparison with middle-right neighbour | ||
| dval9[idx] /= 4.0; | ||
|
|
||
| idx = (rows - 1) * cols; | ||
| dval9[idx] += dval0[idx + 1]; // comparison with middle-left neighbour | ||
| dval9[idx] += dval0[idx - cols + 1]; // comparison with top-left neighbour | ||
| dval9[idx] += dval0[idx - cols]; // comparison with top-central neighbour | ||
| dval9[idx] /= 4.0; | ||
|
|
||
| idx = rows * cols - 1; | ||
| dval9[idx] += dval0[idx - 1]; // comparison with middle-right neighbour | ||
| dval9[idx] += dval0[idx - cols]; // comparison with top-central neighbour | ||
| dval9[idx] += dval0[idx - cols - 1]; // comparison with top-right neighbour | ||
| dval9[idx] /= 4.0; | ||
|
|
||
| #pragma omp parallel for shared(output, dval0, dval9) | ||
| for (int i = 0; i < cols * rows; i++) { | ||
|
|
||
| // setting dval0u to output | ||
| output[i] = fmin(1.0, fmax(-1.0, dval0[i])) * SQUARE(dval0[i]) / (SQUARE(dval0[i]) + 4.0 * readNoiseAmp2); | ||
| // adding dval9u to output | ||
| output[i] += fmax(fmin(dval9[i], mod_clip), -mod_clip) * SQUARE(dval9[i]) / (SQUARE(dval9[i]) + 18.0 * readNoiseAmp2); | ||
|
|
||
| int rcol = i % cols; | ||
| double dmod1, dmod2; | ||
| if (i < cols) { // first row | ||
| dmod1 = 0.0; | ||
| } else { | ||
| dmod1 = imageOut[i - cols] - imageOut[i]; | ||
| } | ||
| output[i] += fmax(fmin(dmod1, mod_clip), -mod_clip) * 4 * readNoiseAmp2 / (SQUARE(dmod1) + 4.0 * readNoiseAmp2); | ||
|
|
||
| if (i >= (rows - 1) * cols) { // last row | ||
| dmod2 = 0.0; | ||
| } else { | ||
| dmod2 = imageOut[i + cols] - imageOut[i]; | ||
| } | ||
| output[i] += fmax(fmin(dmod2, mod_clip), -mod_clip) * 4 * readNoiseAmp2 / (SQUARE(dmod2) + 4.0 * readNoiseAmp2); | ||
|
|
||
| if (smoothCol) { | ||
| double cmod1, cmod2; | ||
| if (rcol == 0) { // first column | ||
| cmod1 = 0.0; | ||
| } else { | ||
| cmod1 = imageOut[i - 1] - imageOut[i]; | ||
| } | ||
| output[i] += fmax(fmin(cmod1, mod_clip), -mod_clip) * 4 * readNoiseAmp2 / (SQUARE(cmod1) + 4.0 * readNoiseAmp2); | ||
| if (rcol == cols - 1) { // last column | ||
| cmod2 = 0.0; | ||
| } else { | ||
| cmod2 = imageOut[i + 1] - imageOut[i]; | ||
| } | ||
| output[i] += fmax(fmin(cmod2, mod_clip), -mod_clip) * 4 * readNoiseAmp2 / (SQUARE(cmod2) + 4.0 * readNoiseAmp2); | ||
|
|
||
| output[i] /= 6.0; | ||
| } else { | ||
| output[i] /= 4.0; | ||
| } | ||
| } | ||
|
|
||
| free(dval9); | ||
| } |
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.
We need to stop swapping these out depending on whether the last PR was someone using Mac or Linux lol