-
Notifications
You must be signed in to change notification settings - Fork 7
Handle image overlaps, to fix metadata round-off errors #107
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
Comments
To set the stage, I'm parsing the metadata files and building a simplified dataframe: import sys
from fractal_tasks_core.metadata_parsing import parse_yokogawa_metadata
import pandas as pd
folder = sys.argv[1]
if not folder.endswith("/"):
folder += "/"
mlf_path = folder + "MeasurementData.mlf"
mrf_path = folder + "MeasurementDetail.mrf"
df, total_files = parse_yokogawa_metadata(mrf_path, mlf_path)
new_df = pd.DataFrame()
new_df["xmin"] = df["x_micrometer"]
new_df["ymin"] = df["y_micrometer"]
new_df["xmax"] = df["x_micrometer"] + df["pixel_size_x"] * df["x_pixel"]
new_df["ymax"] = df["y_micrometer"] + df["pixel_size_y"] * df["y_pixel"]
new_df.to_csv(folder + "metadata.csv") (this is not meant to be part of fractal workflows, but it's just to simplify tests) |
Using this script I identified the FOVs that have some overlap (the ones with thick boundaries): The original csv (see last comment) is
|
For the record, in this example the "error" always seems to take place when the X or Y coordinate passes from negative to positive. |
It's also useful to look at the (x position of the) first few FOVs:
Contrary to my expectations, it's not enough to shift a single FOV (e.g. FOV 4 in this list) to get the "correct" positions, but this will indeed trigger a series of other shifts (as @jluethi had anticipated at some point), to make space for the new FOV 4. |
Given the last comment, a minimal working example for removing overlaps is in this (python) script: It's still quite dirty (and it needs to be translated back to the original dataframe form), but the logic is the one we would expect:
In principle this function could scale quadratically with the number of FOVs, but that quadratic scaling is only achieved when there are few/no overlaps - and then the prefactor is a small number (close to 1) and we can live with it. In practice, this version of the function solves overlap for the 23 wells in less than a second, so I am not that worried. |
Hmm, kinda looks like there is some weird rounding happening depending on whether a value is positive or negative 🙈 In any case, for the more general implementation for #10 and #15, I'd anyway expect that moving one FOV always forces us to also move the others. Maybe a good general heuristic would be to loop through them in order of FOV IDs (1, 2, 3, 4 etc.) [not FOV001, FOV010, etc or random order]. In that way, for most grids, we shouldn't have to move FOVs more than once. |
Addendum to my last comment: |
haha, overlap here in comment time.
Sounds reasonable. Which one do you move? And looking at this grid, it starts bottom left again, while I think our FOV ordering starts top left (FOV 1 is where FOV 65 would be). Let's make sure we don't flip the Y axis again :) |
Regarding tolerance: As long as |
I noticed it, but I am not sure it is relevant at the moment. The dataframe is shown in #107 (comment), and it has the correct signs (e.g.
Given an overlap between FOVs 4 and 5 (I'm now using the labels as shown in the figure above), I shift FOVs For the current example, removing two overlaps is sufficient to remove all of them. In a more complex search-first dataset, we may have to go through a larger number of overlaps. |
Sounds good. I think the assumption that we should move the later FOV to larger x & y values will mostly hold, at least for datasets I'm aware of. But it's not a general rule we'll be able to rely on. If we implement it like this for the moment, let's make a backlog issue to be aware of this limitation. It would come up when someone has a different imaging pattern, e.g. FOVs are imaged in vertical patterns or zig-zag horizontal, instead of straight horizontal lines like we usually get |
Let's check the metadata file here |
And here are the FOV left boundaries:
with the usual issue when crossing the The "wrong" ones |
tl;dr |
Uh oh!
There was an error while loading. Please reload this page.
This is a fresh issue to keep track of work towards fixing #91 (the off-by-one-pixel shape errors due to
0.1 um
-rounding in metadata files). In principle it should prepare the ground for then addressing #10 and #15 (the more general handling of overlapping images).For testing purposes, I'm using the metadata file of a single 9x8 well, which has some overlapping FOVs - see #91. The file is in
/data/active/fractal/3D/PelkmansLab/CardiacMultiplexing/Cycle1_9x8_singleWell/
.The text was updated successfully, but these errors were encountered: