mobie / mobie-viewer-fiji

BSD 2-Clause "Simplified" License
30 stars 12 forks source link

Load Columns doesn't work for non-MoBIE table formats #1044

Closed imagejan closed 11 months ago

imagejan commented 1 year ago

We have default.tsv tables (for multiple sources in a merged grid view) in scikit-image format (i.e., containing label, centroid-0 etc.).

When trying to load additional columns using Table > Load Columns..., we get this log message:

There are duplicate columns: [label]

(likely from here:) https://github.com/mobie/mobie-viewer-fiji/blob/8191c9109adeee3effac4e9c312400008f2cb378/src/main/java/org/embl/mobie/lib/table/saw/TableSawAnnotationTableModel.java#L168-L179

... and the label column in the table view shows all 0s.


It seems that annotation( 0 ).idColumns() here: https://github.com/mobie/mobie-viewer-fiji/blob/8191c9109adeee3effac4e9c312400008f2cb378/src/main/java/org/embl/mobie/lib/table/saw/TableSawAnnotationTableModel.java#L161

... always returns label_id (i.e. the MoBIE format), irrespective of the actual format of the displayed table, so that mergeByColumnNames is empty in our case.

tischi commented 1 year ago

@imagejan yes, you are right this is a bug.

I had a look and probably entirely removing the idColumns from the Annotation and instead fetching them from the TableSawAnnotationCreator makes more sense, because that class is present in the TableSawAnnotationTableModel and it already knows the correct column names for the different use-cases.

For testing, it would be great if you could provide me with:

I should not need a MoBIE project because one can now open such data directly: https://github.com/mobie/mobie-viewer-fiji/blob/main/src/main/java/org/embl/mobie/command/open/OpenImageAndLabelsCommand.java

imagejan commented 1 year ago

Here's some python code to generate minimal test data:

import pandas as pd

from skimage.data import coins
from skimage.filters import gaussian
from skimage.io import imsave
from skimage.measure import regionprops_table
from skimage.morphology import label
from skimage.util import img_as_uint

image = coins()
labels = label(gaussian(image, sigma=5) > 0.46)

imsave("image.tif", image, imagej=True)
imsave("labels.tif", img_as_uint(labels), check_contrast=False)

df = pd.DataFrame(regionprops_table(labels, properties=["label", "centroid", "area"]))
df.to_csv("default.tsv", sep="\t", index=False)
df_int = pd.DataFrame(regionprops_table(labels, intensity_image=image, properties=["label", "mean_intensity"]))
df_int.to_csv("additional.tsv", sep="\t", index=False)

The resulting files (intensity image, label image and two tables) are in this zip file: issue1044.zip

When I try loading columns (with the current state of the MoBIE-beta update site), I do see the labels and the mean_intensity values from additional.tsv, but the values for the default columns (i.e. centroid-0, centroid-1 and area) are the same for all rows after loading.

tischi commented 1 year ago

Working on it: https://github.com/mobie/mobie-viewer-fiji/pull/1046

imagejan commented 11 months ago

Closing this, as #1046 has long been merged.