Search in sources :

Example 1 with HDF5CompoundDataMap

use of ch.systemsx.cisd.hdf5.HDF5CompoundDataMap in project bioformats by openmicroscopy.

the class CellH5Reader method getChannelIndexOfCellObjectName.

private int getChannelIndexOfCellObjectName(String cellObjectName) {
    HDF5CompoundDataMap[] allImageRegions = jhdf.readCompoundArrayDataMap(CellH5Constants.DEFINITION + CellH5Constants.SEGMENTATION_PATH);
    for (int regionIdx = 0; regionIdx < allImageRegions.length; regionIdx++) {
        String regionName = (String) allImageRegions[regionIdx].get("region_name");
        Integer channelIdx = (Integer) allImageRegions[regionIdx].get("channel_idx");
        if (regionName.endsWith(cellObjectName)) {
            return channelIdx.intValue();
        }
    }
    return -1;
}
Also used : NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) HDF5CompoundDataMap(ch.systemsx.cisd.hdf5.HDF5CompoundDataMap)

Example 2 with HDF5CompoundDataMap

use of ch.systemsx.cisd.hdf5.HDF5CompoundDataMap in project bioformats by openmicroscopy.

the class CellH5Reader method parseROIs.

private void parseROIs(int s) {
    int objectIdx = 0;
    List<Color> classColors = new ArrayList<Color>();
    int roiIndexOffset = 0;
    CellH5Coordinate coord = CellH5PositionList.get(0);
    for (String cellObjectName : cellObjectNames) {
        LOGGER.info("Parse segmentation ROIs for cell object {} : {}", cellObjectName, objectIdx);
        String featureName = CellH5Constants.FEATURE + cellObjectName + "/";
        String pathToBoundingBox = coord.pathToPosition + featureName + CellH5Constants.BBOX;
        String pathToClassDefinition = CellH5Constants.DEFINITION + featureName + CellH5Constants.CLASS_LABELS;
        boolean hasClassification = false;
        if (jhdf.exists(pathToClassDefinition)) {
            String classColorHexString;
            HDF5CompoundDataMap[] classDef = jhdf.readCompoundArrayDataMap(pathToClassDefinition);
            for (int cls = 0; cls < classDef.length; cls++) {
                classColorHexString = (String) classDef[cls].get("color");
                classColors.add(hex2Rgb(classColorHexString));
            }
            if (classDef.length > 0) {
                hasClassification = true;
                classes = jhdf.readCompoundArrayDataMap(coord.pathToPosition + featureName + CellH5Constants.PREDICTED_CLASS_LABELS);
            }
        }
        if (jhdf.exists(pathToBoundingBox)) {
            bbox = jhdf.readCompoundArrayDataMap(pathToBoundingBox);
            times = jhdf.readCompoundArrayDataMap(coord.pathToPosition + CellH5Constants.OBJECT + cellObjectName);
            int roiChannel = getChannelIndexOfCellObjectName(cellObjectName);
            int roiZSlice = 0;
            for (int roiIndex = 0; roiIndex < bbox.length; roiIndex++) {
                int roiManagerRoiIndex = roiIndex + roiIndexOffset;
                int roiTime = (Integer) times[roiIndex].get("time_idx");
                int objectLabelId = (Integer) times[roiIndex].get("obj_label_id");
                int left = (Integer) bbox[roiIndex].get("left");
                int right = (Integer) bbox[roiIndex].get("right");
                int top = (Integer) bbox[roiIndex].get("top");
                int bottom = (Integer) bbox[roiIndex].get("bottom");
                int width = right - left;
                int height = bottom - top;
                String roiID = MetadataTools.createLSID("ROI", roiManagerRoiIndex);
                store.setROIID(roiID, roiManagerRoiIndex);
                store.setImageROIRef(roiID, s, roiManagerRoiIndex);
                store.setROIName(cellObjectName + " " + objectLabelId, roiManagerRoiIndex);
                String shapeID = MetadataTools.createLSID("Shape", roiManagerRoiIndex, 0);
                store.setRectangleID(shapeID, roiManagerRoiIndex, 0);
                store.setRectangleX((double) left, roiManagerRoiIndex, 0);
                store.setRectangleY((double) top, roiManagerRoiIndex, 0);
                store.setRectangleWidth((double) width, roiManagerRoiIndex, 0);
                store.setRectangleHeight((double) height, roiManagerRoiIndex, 0);
                store.setRectangleText(cellObjectName, roiManagerRoiIndex, 0);
                store.setRectangleTheT(new NonNegativeInteger(roiTime), roiManagerRoiIndex, 0);
                store.setRectangleTheC(new NonNegativeInteger(roiChannel), roiManagerRoiIndex, 0);
                store.setRectangleTheZ(new NonNegativeInteger(roiZSlice), roiManagerRoiIndex, 0);
                Color strokeColor;
                if (hasClassification) {
                    int classLabelIDx = (Integer) classes[roiIndex].get("label_idx");
                    strokeColor = classColors.get(classLabelIDx);
                } else {
                    strokeColor = new Color(COLORS[objectIdx][0], COLORS[objectIdx][1], COLORS[objectIdx][2], 0xff);
                }
                store.setRectangleStrokeColor(strokeColor, roiManagerRoiIndex, 0);
            }
            objectIdx++;
            roiIndexOffset += bbox.length;
        } else {
            LOGGER.info("No Segmentation data found...");
            break;
        }
    }
}
Also used : NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) HDF5CompoundDataMap(ch.systemsx.cisd.hdf5.HDF5CompoundDataMap) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Color(ome.xml.model.primitives.Color) ArrayList(java.util.ArrayList)

Aggregations

HDF5CompoundDataMap (ch.systemsx.cisd.hdf5.HDF5CompoundDataMap)2 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)2 ArrayList (java.util.ArrayList)1 Color (ome.xml.model.primitives.Color)1