Skip to content

Commit

Permalink
Add tile compositing
Browse files Browse the repository at this point in the history
Read position metadata of tiles from nd2 file

Closes #244
  • Loading branch information
bruyeret committed Dec 6, 2022
1 parent db34c4d commit e2c7afb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/store/GirderAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ export default class GirderAPI {
return this.client.get(`item/${toId(item)}/tiles`).then(r => r.data);
}

getTilesInternalMetadata(item: string | IGirderItem): Promise<ITileMeta> {
return this.client
.get(`item/${toId(item)}/tiles/internal_metadata`)
.then(r => r.data);
}

private getHistogram(
item: string | IGirderItem,
options: Partial<IHistogramOptions> = {}
Expand Down
48 changes: 44 additions & 4 deletions src/views/dataset/MultiSourceConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import store from "@/store";
import { collectFilenameMetadata2 } from "@/utils/parsing";
import { IGirderItem } from "@/girder";
import { ITileMeta } from "@/store/GirderAPI";
import { IGeoJSPoint } from "@/store/model";
enum Sources {
File = "file",
Expand All @@ -84,6 +86,9 @@ interface IAssignment {
export default class NewDataset extends Vue {
readonly store = store;
tilesInternalMetadata: { [key: string]: any }[] | undefined;
tilesMetadata: ITileMeta[] | undefined;
get datasetId() {
return this.$route.params.id;
}
Expand Down Expand Up @@ -309,16 +314,20 @@ export default class NewDataset extends Vue {
this.addSizeToDimension("XY", metadata.xy.length, Sources.Filename);
// Get info from file
const tiles = await Promise.all(
this.tilesMetadata = await Promise.all(
items.map(item => this.store.api.getTiles(item))
);
this.numberOfFrames = tiles[0]?.frames?.length || tiles.length;
this.tilesInternalMetadata = await Promise.all(
items.map(item => this.store.api.getTilesInternalMetadata(item))
);
this.numberOfFrames =
this.tilesMetadata[0]?.frames?.length || this.tilesMetadata.length;
const channels: string[] = [];
this.maxFramesPerItem = 1;
this.areStridesSetFromFile = false;
tiles.forEach(tile => {
this.tilesMetadata.forEach(tile => {
const frames: number = tile.frames?.length || 1;
this.maxFramesPerItem = Math.max(this.maxFramesPerItem, frames);
if (tile.IndexStride) {
Expand Down Expand Up @@ -434,7 +443,38 @@ export default class NewDataset extends Vue {
})
};
const newItemId = await this.store.addMultiSourceMetadata({
if (
this.tilesInternalMetadata &&
this.tilesInternalMetadata.length === 0 &&
this.tilesInternalMetadata[0].nd2_frame_metadata &&
this.tilesMetadata &&
this.tilesMetadata.length === 1
) {
const { mm_x, mm_y } = this.tilesMetadata[0];
const framesMetadata = this.tilesInternalMetadata[0].nd2_frame_metadata;
const coordinates: IGeoJSPoint[] = framesMetadata.map((f: any) => {
const framePos = f.position.stagePositionUm;
return {
x: (1000 * framePos[0]) / mm_x,
y: (1000 * framePos[1]) / mm_y
};
});
const minCoordinate = {
x: Math.min(...coordinates.map(coordinate => coordinate.x)),
y: Math.min(...coordinates.map(coordinate => coordinate.y))
};
const intCoordinates = coordinates.map(coordinate => ({
x: Math.round(coordinate.x - minCoordinate.x),
y: Math.round(coordinate.y - minCoordinate.y)
}));
description.sources.forEach((source, itemIdx) => {
source.xySet = 0;
source.position = intCoordinates[itemIdx];
});
}
await this.store.addMultiSourceMetadata({
parentId: this.datasetId,
metadata: JSON.stringify(description)
});
Expand Down

0 comments on commit e2c7afb

Please sign in to comment.