Skip to content
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

Example of TableWrapper with ROI #57

Closed
lldelisle opened this issue Mar 17, 2023 · 6 comments
Closed

Example of TableWrapper with ROI #57

lldelisle opened this issue Mar 17, 2023 · 6 comments
Assignees
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@lldelisle
Copy link

Hi,
Sorry, I already have a question.
I would like to create a Table in omero with a column with ROIs.
I have a ResultTable (obtained with Analyze particle) and the corresponding ImageJ ROIs (in the overlay).
I tried to use setProperty on the ImageJ ROIs then add a column in my ResultTable.
But in omero there is no link between my table entries and my ROIs.
I am quite sure something is missing but I don't know what.
Would you mind to give an example?
Thank you.
My attempt was:

// I built previously a Map<String, Roi> map_rois with the rois corresponding to the table where the key is "Slice" in the rt
// Building a list of ROIs to put in omero
List<Roi> rois =  new ArrayList<>(0)
for ( int row = 0;row<rt.size();row++) {
        int t = rt.getValue("Slice", row) as int
        // Get the corresponding ROI
        Roi temp_roi = map_rois.get(t)
        // Set name and property
        temp_roi.setName("Gastruloid_t" + t)
        temp_roi.setProperty("ROI", "Gastruloid_t" + t)
        rois.add(temp_roi)
        // Add a column with the same info
        rt.setValue("ROI", row, "Gastruloid_t" + t)
}
// Save ROIs to omero
image_wpr.saveROIs(user_client, ROIWrapper.fromImageJ(rois as List))	

// Create an omero table:
TableWrapper table_wpr = new TableWrapper(user_client, rt, image_wpr.getId(), rois as List, "ROI")

// upload the table on OMERO
table_wpr.setName(table_name)
image_wpr.addTable(user_client, table_wpr)
@ppouchin
Copy link
Member

The ROIs need a "ROI_ID" property set with their ID on OMERO (which is done automatically when retrieving ROIs).
I think you need to add something like this after saving the ROIs:

updatedRois = ROIWrapper.toImageJ(image_wpr.getROIs(user_client), "ROI")
TableWrapper table_wpr = new TableWrapper(user_client, rt, image_wpr.getId(), updatedRois, "ROI")

However, you'll retrieve all the ROIs, so if you have more than what you want, you may have to filter them. Or use Folders.

@ppouchin ppouchin self-assigned this Mar 18, 2023
@ppouchin ppouchin added question Further information is requested documentation Improvements or additions to documentation labels Mar 18, 2023
@ppouchin
Copy link
Member

I'll try to improve the documentation...

@lldelisle
Copy link
Author

Hi,
Thank you so much for your answer. It worked.
If I understand well this block:

if (results.columnExists(roiIdProperty)) {
Variable[] roiCol = results.getColumnAsVariables(roiIdProperty);
roiColumn = idColumnToROIColumn(roiCol, id2roi);
colToDelete = roiIdProperty;
}
if (roiColumn.length == 0 && results.columnExists(roiProperty)) {
Variable[] roiCol = results.getColumnAsVariables(roiProperty);
roiColumn = propertyColumnToROIColumn(roiCol, id2roi, label2roi, name2roi, shape2roi);
colToDelete = roiProperty;
}
if (roiColumn.length != 0 && !colToDelete.isEmpty()) results.deleteColumn(colToDelete);
String[] headings = results.getHeadings();
if (roiColumn.length == 0 && Arrays.asList(headings).contains(LABEL)) {
Variable[] roiCol = results.getColumnAsVariables(LABEL);
roiColumn = labelColumnToROIColumn(roiCol, shape2roi, (m, s) -> m.keySet()
.stream()
.filter(s::contains)
.findFirst()
.orElse(null));
if (roiColumn.length == 0) {
roiColumn = labelColumnToROIColumn(roiCol, name2roi, (m, s) -> m.keySet()
.stream()
.filter(s::contains)
.findFirst()
.orElse(null));
}
}

Only one of those 2 is sufficient:

  • add the same label as in the result table as name: temp_roi.setName("Gastruloid_t" + t)
  • add the same label as in the result table as property: temp_roi.setProperty("ROI", "Gastruloid_t" + t)

@ppouchin
Copy link
Member

ppouchin commented Mar 20, 2023

Well, it's also about what you want do display on OMERO:

  • setProperty("ROI", index) is used to group 2D shapes into one 3D/4D ROI on OMERO. The value is never stored, and when you retrieve it from OMERO, the default values are integers.
  • setName(name) is used to name the 2D shapes on OMERO (and in ImageJ).
  • You can also use setProperty("ROI_NAME", name) to give a 3D/4D ROI a name on OMERO.

I try to match against any of those properties when ROIs are passed to a TableWrapper (but you can't mix them though).

@lldelisle
Copy link
Author

Thanks for the answer, I am not familiar with 3D/4D ROI on OMERO.
Just for info, when I tried to use setProperty with index of int type I got an error, it seems that it only accepts String...

@ppouchin
Copy link
Member

ppouchin commented Mar 20, 2023

Oh, yes. setProperty only accepts String. I meant that by default, I return integers as strings.

Any string can be used to group 2D shapes, but, by default, I just return a local index (the string has to be parsed).
It seems redundant with "ROI_ID", the property that contains the OMERO ID, but the latter is a Long, which can be troublesome to handle.
The idea is that if you need to retrieve ROIs from OMERO and want to create a label image, you just have to use the "ROI" property, while the "ROI_ID" property would need 32-bit images and would not start at 1, which would be a bit weird.
When creating ROIs though, you can use whatever String you want, but as it is not stored, it does not have to be complex.

At one point, I also merged "ROI" and "ROI_NAME" too, but there was actually no guarantee that ROI names should be unique.

ppouchin added a commit that referenced this issue Mar 28, 2023
* Update pom.xml and maven.yml
* Fix wrong tag namespace being set when retrieved
* Fix #56 (incomplete tables)
* Fix another null exception when retrieving min positions
* Improve documentation for tables & ROIs (#57)
@ppouchin ppouchin closed this as completed Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants