-
Notifications
You must be signed in to change notification settings - Fork 47
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
Offset when rasterizing data #165
Comments
Another important point, the rasterization functions could be used for computing aggregation functions. Until this offset problem is addressed, the aggregation would be imprecise. |
The function
|
The bug is not just of rasterize, but multiple factors are involved. First, napari considers the coordinates as the center of pixels. Here is for instance the effect of rotating an image by -45 degrees, and showing also the (0, 0) coordinate before and after rotation. Note that the rotation doesn't preserve the location of the (0, 0)-pixel top-left corner. I need to check, but I suspect that |
I confirm that one of the reasons for the bug is the fact that (0, 0) is not the top-left corner but the center of the top-left pixel, as shown in the image above. I am fixing this in #453. Nevertheless, there is also another problem, apparently due to |
After digging deeper into this I found out the causes of the bug, some of which can be fixed (as I did partially did in #453), but one of them requires a design choice to be made. I will explain this here. The bugs are the following (they all lead to an error to up to 1 pixel, which is noticeable when the pixel sizes are large):
The design choice to be made is due to the following: @timtreis @Sonja-Stockhaus I kindly ask for feedback, how does matplotlib operates? With the approach (a) or (b)? Some example implications of the case (a) are the following:
Some implications of the case (b) are the following:
|
The approach (a) is motivated by http://alvyray.com/Memos/CG/Microsoft/6_pixel.pdf. After reading this (just done) I am more inclined for this approach. We should carefully what this implies for the result of the |
Using
|
|
|
|
When the issue is addressed, we should double check against this example from @t-a-m-i that all is working correctly: https://scverse.zulipchat.com/#narrow/channel/315824-spatial/topic/SpatialData/near/479568220 |
When rasterizing images or labels (basically resampling), there is an offset (see picture) that I think is due to the fact that somewhere in the code for rasterization the coordinates of the pixels are considered to be associated with the top left corner, and in other parts of the code for rasterization the coordinates refer to the center of the pixels.
This half pixel difference is not negligible since when we align together images of different resolutions, one pixel for one image can be many pixels for another.
The screenshot is from this example:
spatialdata/examples/dev-examples/spatial_query_and_rasterization.py
Line 15 in eb99aeb
The text was updated successfully, but these errors were encountered: