Skip to content

Commit e4527ba

Browse files
find_spots: Exclude masked pixels from erosion check (dials#2790)
In order to prevent erroneous spot erasure, as seen in dials#2785. Set masked pixels to 'true' in the dispersion threshold mask so that they do not affect erosion and erode from masked regions as if they were background. Closes dials#2785.
1 parent b59bf96 commit e4527ba

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Daniel Paley
1010
Daniel Tchon
1111
David Waterman
1212
Derek Mendez
13+
Dimitrios Vlachos
1314
Graeme Winter
1415
Huw Jenkins
1516
Hans-Christian Stadler

newsfragments/2790.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``dials.find_spots``: Prevent masked pixels from causing a "halo" of excluded pixels around them when using ``threashold.algorithm=extended_dispersion`` (the default). This previously caused strong pixels to be excluded from module edges and incorrectly classed strong pixels as background if close to masked pixels.

src/dials/algorithms/image/threshold/local.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,13 @@ namespace dials { namespace algorithms {
901901
final_mask_ = af::versa<bool, af::c_grid<2> >(image.accessor(), false);
902902
global_mask_ = af::versa<bool, af::c_grid<2> >(image.accessor(), false);
903903
for (std::size_t i = 0; i < image.size(); ++i) {
904-
if (temp[i]) {
904+
if (!temp[i]) {
905+
/*
906+
* Masked pixels are set as non-background in order to
907+
* prevent them from affecting the erosion calculation.
908+
*/
909+
cv_mask_[i] = true;
910+
} else {
905911
double bnd_b = gain[i] + nsig_b * gain[i] * std::sqrt(2.0 / (count[i] - 1));
906912
cv_mask_[i] = cv_[i] > bnd_b;
907913
global_mask_[i] = image[i] > threshold;
@@ -1094,7 +1100,13 @@ namespace dials { namespace algorithms {
10941100

10951101
// Compute the thresholds
10961102
dst[k] = false;
1097-
if (mask[k] && m >= min_count_ && x >= 0) {
1103+
if (!mask[k]) {
1104+
/*
1105+
* Masked pixels are set as non-background in order to
1106+
* prevent them from affecting the erosion calculation.
1107+
*/
1108+
dst[k] = true;
1109+
} else if (m >= min_count_ && x >= 0) {
10981110
double a = m * y - x * x - x * (m - 1);
10991111
double c = x * nsig_b_ * std::sqrt(2 * (m - 1));
11001112
dst[k] = (a > c);
@@ -1165,7 +1177,13 @@ namespace dials { namespace algorithms {
11651177

11661178
// Compute the thresholds
11671179
dst[k] = false;
1168-
if (mask[k] && m >= min_count_ && x >= 0) {
1180+
if (!mask[k]) {
1181+
/*
1182+
* Masked pixels are set as non-background in order to
1183+
* prevent them from affecting the erosion calculation.
1184+
*/
1185+
dst[k] = true;
1186+
} else if (m >= min_count_ && x >= 0) {
11691187
double a = m * y - x * x;
11701188
double c = gain[k] * x * (m - 1 + nsig_b_ * std::sqrt(2 * (m - 1)));
11711189
dst[k] = (a > c);

0 commit comments

Comments
 (0)