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

Resolve integer overflow when running on a large 3D image #249

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions stardist/lib/stardist2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ static PyObject* c_non_max_suppression_inds(PyObject *self, PyObject *args) {
results, params);
else{
results.resize(n_polys-i);
for (int n = 0; n < results.size(); ++n)
for (size_t n = 0; n < results.size(); ++n)
results[n].first = i+n;
}

Expand All @@ -563,7 +563,7 @@ static PyObject* c_non_max_suppression_inds(PyObject *self, PyObject *args) {
#pragma omp parallel for schedule(dynamic) reduction(+:count_suppressed) shared(suppressed)
#endif

for (int neigh=0; neigh<results.size(); neigh++) {
for (size_t neigh=0; neigh<results.size(); neigh++) {
// for (int j=i+1; j<n_polys; j++) {

long j = results[neigh].first;
Expand Down
13 changes: 6 additions & 7 deletions stardist/lib/stardist3d_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ void _COMMON_non_maximum_suppression_sparse(
results, params);
else{
results.resize(n_polys-i);
for (int n = 0; n < results.size(); ++n)
for (size_t n = 0; n < results.size(); ++n)
results[n].first = i+n;
}
// inner loop
Expand All @@ -1192,7 +1192,7 @@ void _COMMON_non_maximum_suppression_sparse(
// if (suppressed[j])
// continue;

for (int neigh=0; neigh<results.size(); neigh++) {
for (size_t neigh=0; neigh<results.size(); neigh++) {

long j = results[neigh].first;

Expand Down Expand Up @@ -1458,13 +1458,12 @@ void _COMMON_polyhedron_to_label(const float* dist, const float* points,

// loop over bounding box and label pixel if inside of the polyhedron
#pragma omp parallel for schedule(dynamic)
for (int z = std::max(0,bbox[0]); z <= std::min(nz-1,bbox[1]); ++z) {
for (int y = std::max(0,bbox[2]); y <= std::min(ny-1,bbox[3]); ++y) {
for (int x = std::max(0,bbox[4]); x <= std::min(nx-1,bbox[5]); ++x) {
for (uint64_t z = std::max(0,bbox[0]); z <= (uint64_t) std::min(nz-1,bbox[1]); ++z) {
for (uint64_t y = std::max(0,bbox[2]); y <= (uint64_t) std::min(ny-1,bbox[3]); ++y) {
for (uint64_t x = std::max(0,bbox[4]); x <= (uint64_t) std::min(nx-1,bbox[5]); ++x) {


bool inside = false;
long offset = x+y*nx+z*(nx*ny);
uint64_t offset = x+y*nx+z*(nx*ny);

switch(render_mode){
case 0:
Expand Down