Skip to content

fix: index shift correction for blob detection in 2d tiles#2076

Closed
shachafl wants to merge 1 commit intomasterfrom
2075-blobdetector-incorrect-results
Closed

fix: index shift correction for blob detection in 2d tiles#2076
shachafl wants to merge 1 commit intomasterfrom
2075-blobdetector-incorrect-results

Conversation

@shachafl
Copy link
Copy Markdown
Collaborator

This closes #2075 & #1870

There might be another solution to this as I couldn't figure why when running blob detection with is_volume=False and with a reference image gives a 4d result (z, y, x, sigma) vs. without a reference image which gives a 3d output (y, x, sigma).

@shachafl shachafl requested a review from berl May 16, 2025 03:06
@berl
Copy link
Copy Markdown
Collaborator

berl commented May 18, 2025

so the reference_image handles things a bit differently, first runningskimage spotfinding function on the whole stack, or at least that's my read of this after a squeeze which may be leading to the weird behavior here.

somewhat orthogonally, the is_volume parameter is supposed to change the behavior of the spotfinding from per z plane (is_volume=False) to finding 3D blobs (is_volume=True). This was intended to be used for different kinds of data (sparse sampling in z vs dense sampling) but should be able to work both ways on a given input stack. the underlying skimage functions don't know anything about this (they just return 3d information on a 3d image stack or 2d on a 2d stack).
not sure if this helps clarify anything @shachafl, but getting rid of the is_volume condition should be done carefully to maintain this functionality

@shachafl shachafl requested a review from Copilot October 21, 2025 08:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an index shift issue in blob detection for 2D tiles by correcting how array dimensions are interpreted and indexed. The change addresses a discrepancy where blob detection results have different dimensionality (3D vs 4D) depending on whether a reference image is used.

  • Replaces is_volume flag check with dynamic shape inspection of fitted_blobs_array
  • Corrects 2D indexing to use (y_inds, x_inds) instead of incorrectly including z_inds for 2D data

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +140 to +146
if fitted_blobs_array.shape[1] == 4:
z_inds = fitted_blobs_array[:, 0].astype(int)
y_inds = fitted_blobs_array[:, 1].astype(int)
x_inds = fitted_blobs_array[:, 2].astype(int)
radius = np.round(fitted_blobs_array[:, 3] * np.sqrt(3))
intensities = data_image[tuple([z_inds, y_inds, x_inds])]
else:
elif fitted_blobs_array.shape[1] == 3:
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition checks only for shapes with 3 or 4 columns, but doesn't handle other potential array shapes. If fitted_blobs_array.shape[1] is neither 3 nor 4, the code will silently skip both branches, leaving intensities, z_inds, y_inds, x_inds, and radius undefined, which will cause errors in subsequent code. Add an else clause to raise an informative error for unexpected array shapes.

Copilot uses AI. Check for mistakes.
@shachafl shachafl added this to the Release 0.3.4 milestone Oct 22, 2025
@shachafl shachafl marked this pull request as draft October 24, 2025 12:06
@shachafl shachafl self-assigned this Nov 5, 2025
@shachafl
Copy link
Copy Markdown
Collaborator Author

closing this here, as a more comprehensive fix is done in #2154.
The new fix maintains the ability to process a 3d image as a set of 2d tiles instead.

@shachafl shachafl closed this Nov 22, 2025
@shachafl shachafl deleted the 2075-blobdetector-incorrect-results branch November 26, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blobdetector yields incorrect results

3 participants