Repository navigation
Center image pixels on their Sigima coordinates - #73
Merged
Merged
Conversation
Sigima and DataLab desktop define x0/y0 as the center of the first pixel, but the image viewers drew it from x0/y0 as its upper-left corner, so everything shown in physical coordinates (ROIs, analysis results, crosshair, stats rectangle) was half a pixel off the pixels used by the computations. - shared axis helpers (pixelCenters.ts) mirroring Sigima's axis_to_float_indices / axis_to_physical, with pixel edges, image extent and center, pixel lookup and covered pixel ranges, for uniform and non-uniform images; - the LOD raster geometry follows the pixel-center convention; the bitmap placement is named after Plotly's layout-image x/y and shared by the single-image, spatial and processing preview plots; - image viewer: extent, hover value, cross-sections and stats use the helpers (cross-sections and stats now also work on non-uniform images; stats keep the covered-pixel rule of DataLab desktop); - spatial and thumbnail views: extent and hover read-out likewise; - default ROIs, erase area and ROI panel bounds use the image extent and the center of its pixel grid; - decimated image payloads keep the exact physical extent of the image. Refs #69 Assisted-by: Claude Opus 5.5
The live preview of "Create ROI grid..." replicated the former generate_image_grid_roi, laid out from x0 (the first pixel center) and not snapped to pixels, so it no longer matched the regions of interest created by Sigima 1.4. The replica now lays the grid over the outer edges of the pixels (bin edges for non-uniform images), makes each cell of the pixels whose centers lie in it and draws each rectangle to the outer edges of its pixels; empty cells are kept, as in Sigima, and a zero translation is no longer read as the default. The new test checks the preview against reference values computed with Sigima. Refs #69 Assisted-by: Claude Opus 5.5
Refs #69 Assisted-by: Claude Opus 5.5
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #69
Summary
Sigima and DataLab desktop define
x0/y0as the center of the first pixel (axis_to_physical(i) = x0 + i·dx), but the image viewers drew the first pixel fromx0/y0as its upper-left corner. Everything shown in physical coordinates (ROIs, analysis results, crosshair, stats rectangle, hover read-out) was therefore half a pixel off the pixels used by the computations. Example of the issue: a 4×4 image withx0 = y0 = 0now spans [-0.5, 3.5] with pixel centers at 0…3.src/utils/pixelCenters.ts):axisToFloatIndex/axisToPhysicalmirror Sigima'saxis_to_float_indices/axis_to_physical(extrapolation included), pluspixelEdges,imageExtent,imageCenter(Sigimaxc/yc),pixelIndexAtandpixelRangeOverlapping, for uniform and non-uniform images. No other code converts between pixels and physical coordinates on its own anymore.imageLod.ts,imageRaster.ts):ImageGeometry.x0/y0are pixel centers; the bitmap starts atx0 + (i0 − ½)·dx. The placement fields are renamedx/y(Plotly layout-image names) to avoid the center/corner confusion, and a singlerasterLayoutImagehelper replaces three copies.x0, no pixel snapping). It now matchesgenerate_image_grid_roi(grid over the outer pixel edges, whole-pixel cells, empty cells kept), and a zero translation is no longer read as the default.x0' = x0 + (dx' − dx)/2keeps the exact physical extent, so previews overlay the full-resolution image exactly.binSearchCellis removed (replaced bypixelIndexAt), along with its tests, which were ported to the new helpers.Out of scope: Distribute on grid / Reset positions keep the desktop behavior (they align first-pixel centers). The profile dialog already followed the convention (#70).
Validation
develop.npm run buildwithin the bundle budget.3af8228):image-lod,multi-image-spatial,image-roi-drag,image-pan(9 passed).[-0.5, 1.5]lands on pixel edges, and hovering (0.6, 0.4) reads pixel (1, 0).Note: small images are drawn smoothed by the browser when zoomed in (no
image-rendering: pixelatedon the main viewer's layout image, unlike the thumbnails). This existed before this PR and is not changed here.