aboutsummaryrefslogtreecommitdiff
path: root/src/conversion
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversion')
-rw-r--r--src/conversion/czi/czi.ts220
1 files changed, 106 insertions, 114 deletions
diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts
index 7e39d68..addf43e 100644
--- a/src/conversion/czi/czi.ts
+++ b/src/conversion/czi/czi.ts
@@ -6,9 +6,10 @@ import * as parsexml from 'xml-parser';
import { SharpInstance } from 'sharp';
const extractionDirectory: string = '/cs/scratch/cjd24/0701-extraction/';
-const outputImageDirectory: string = '/cs/scratch/cjd24/0701-extraction-processed/'
+const outputImageDirectory: string = '/cs/scratch/cjd24/0701-extraction-processed2/'
const tileOverlap: number = 0;
const tileSize: number = 1024;
+const maxZoom: number = 64;
interface Dimension {
Dimension: string;
@@ -40,6 +41,45 @@ class TileBounds {
this.bottom = bottomBound;
}
}
+interface SupportedViews {
+ scalable_image: {
+ width: number;
+ height: number;
+ channels: [
+ {
+ channel_id: string;
+ channel_name: string;
+ metadata?: {};
+ }
+ ];
+ real_width?: {
+ value: number;
+ units: string;
+ };
+ real_height?: {
+ value: number;
+ units: string;
+ };
+ metadata?: {};
+ }
+}
+interface CZITile {
+ x_offset: number;
+ y_offset: number;
+ width: number;
+ height: number;
+ file: string;
+}
+interface CZIHeightMap {
+ zoom_level: number,
+ plane: CZITile[][];
+}
+interface WholeCZIHierarchy {
+ c_values: [{
+ channel_id: string,
+ height_map: CZIHeightMap[];
+ }];
+}
const getOriginalTileBounds: Function = function(originalTile: Segment): (TileBounds | null) {
const bounds: TileBounds = new TileBounds(-1, -1, -1, -1);
@@ -130,7 +170,7 @@ const orderSegments: Function = function(segments: Segment[]): Segment[][] {
const initC: number = getDimension(segments[0], 'C').Start;
for (const seg of segments) {
if (getDimension(seg, 'C').Start !== initC) {
- throw new Error("Segment array contains multiple values of C - this overlay is currently unsupported within this method");
+ throw new Error('Segment array contains multiple values of C - this overlay is currently unsupported within this method');
}
xCoords.push(getDimension(seg, 'X').Start);
yCoords.push(getDimension(seg, 'Y').Start);
@@ -235,7 +275,7 @@ const extractAndStitchChunks: Function = async function(segments: Segment[][], d
{top:0, left:0, bottom:0, right: (tileSize - (bufferBound.right - bufferBound.left))});
}
for (let index = 1; index < segRow.length; index++) {
- imageVerticalSlice = imageVerticalSlice
+ imageVerticalSlice = await imageVerticalSlice
.overlayWith(tileRow[index],
{top: 0, left: (bufferBound.right - bufferBound.left) + ((index -1) * tileSize)});
}
@@ -261,31 +301,21 @@ const extractAndStitchChunks: Function = async function(segments: Segment[][], d
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const dataBlocks: Segment[] = require(`${extractionDirectory}outputjson.json`).czi.filter(
(s: Segment) => s.Id === 'ZISRAWSUBBLOCK' && s.Data.Data !== 'empty');
-const inspect: object = require('util').inspect;
-const metaXML: parsexml.Node[] = parsexml(fs.readFileSync(`${extractionDirectory}FILE-META-1.xml`, 'utf8')).root.children;
+const inspect = require('util').inspect;
+const metaXML: parsexml.Document = parsexml(fs.readFileSync(`${extractionDirectory}FILE-META-1.xml`, 'utf8'));
+
+let supportedViews: SupportedViews = {scalable_image: {width: -1, height: -1, channels: [{channel_id: '-1', channel_name: ''}], metadata: metaXML}};
+supportedViews.scalable_image.channels.pop();
let totalSizeX: number = -1;
let totalSizeY: number = -1;
// THE FOLLOWING FOR LOOP IS DISGUSTING AND I HATE IT, AND I WISH I DIDNT WRITE IT BUT DON'T SEE ANY OTHER WAY TO DO IT LOL :'(
-for (const child of metaXML) {
+for (const child of metaXML.root.children) {
if (child.name === 'Metadata') {
for (const entry of child.children) {
if (entry.name === 'Information') {
@@ -294,8 +324,26 @@ for (const child of metaXML) {
for (const property of properties.children) {
if (property.name === 'SizeX' && property.content) {
totalSizeX = Number.parseInt(property.content, 10);
+ supportedViews.scalable_image.width = totalSizeX;
+ continue;
} else if (property.name === 'SizeY' && property.content) {
totalSizeY = Number.parseInt(property.content, 10);
+ supportedViews.scalable_image.height = totalSizeY;
+ continue;
+ } else if(property.name === 'Dimensions') {
+ for (const chan of property.children) {
+ if (chan.name === 'Channels') {
+ for (const channel of chan.children) {
+ supportedViews.scalable_image.channels.push(
+ {
+ channel_id: channel.attributes.Id.split(":")[1],
+ channel_name: channel.attributes.Name,
+ metadata: channel.children
+ }
+ );
+ }
+ }
+ }
}
}
}
@@ -328,112 +376,56 @@ for (const seg of dataBlocks) {
}
}
-// // TESTS TO SEE WHAT VARIOUS THINGS RETURN
-// // `npm bin`/ts-node czi.ts
-console.log('\n\nUnique Tile Sizes:');
-console.log(uniqueTileSizes);
-console.log('\n\nSizeX : ' + totalSizeX);
-console.log('UNIQUE X VALUES:');
-console.log(uniqueX);
-console.log('\n\n(tentative) SizeY : ' + totalSizeY);
-console.log('UNIQUE Y VALUES:');
-console.log(uniqueY);
-
-let x: number = 1500, y: number = 1500;
-let c_filter: Segment[] = [];
+let filteredDataBlocks: Segment[] = [];
const filterC: Function = function(to: number): void {
- c_filter = dataBlocks.filter((x: Segment) => {
- const y: Dimension | null = getDimension(x, 'C');
- if (y != null && y.Start === to) {
- return y;
- }
- });
-};
-
-let desired = new TileBounds (0, 0, 0, 0);
-function findRelatedTest(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number) {
- desired = new TileBounds (
- x1 - tileoverlap,
- x1 + tilesize + tileoverlap,
- y1 - tileoverlap,
- y1 + tilesize + tileoverlap
+ filteredDataBlocks = dataBlocks.filter(
+ (item: Segment, index: number, array: Segment[]) => getDimension(item, 'C').Start === to
);
- filterC(cval);
- console.log('\n\nC Value: ' + cval + ' TileSize: ' + tilesize + ' TileOverlap(px): ' + tileoverlap + ' Coords: ' + `[X=${x1}, Y=${y1}]\nResults: `);
- console.log(findRelatedTiles(c_filter, desired).map((x: Segment) => x.Data.Data));
-}
-
-findRelatedTest(0, 1024, 5, 1500, 1500);
-
-findRelatedTest(1, 5000, 5, 1500, 1500);
-
-findRelatedTest(0, 1024, 5, 0, 0);
-
-findRelatedTest(0, 1024, 5, 41940, 59240);
-
-findRelatedTest(0, 1024, 5, -tileSize - tileOverlap - 1, 59240);
-
-findRelatedTest(0, 1024, 5, 41945, 59245);
-
-findRelatedTest(3, 1024, 5, 41940, 1500);
-
-filterC(0);
-console.log('\n\n\n\n\n\n\n');
-
-
-
-
-
-
-
-
-
-
-
-
+};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Begin work on getting the new tiles all nice
-const sortSegmentsTest: Function = function(cval: number, tilesize: number, tileoverlap: number, x1: number, y1: number): Segment[][] {
- desired = new TileBounds (
- x1 - tileoverlap,
- x1 + tilesize + tileoverlap,
- y1 - tileoverlap,
- y1 + tilesize + tileoverlap
- );
- filterC(cval);
- console.log('\nC Value: ' + cval + ' TileSize: ' + tilesize + ' TileOverlap(px): ' + tileoverlap + ' Coords: ' + `[X=${x1}, Y=${y1}]`);
- const outputGrid: Segment[][] = orderSegments(findRelatedTiles(c_filter, desired));
-
- for (const row of outputGrid) {
- let rowOutput: string = '[ ';
- for (const col of row) {
- rowOutput += ` '${col.Data.Data}', `;
- }
- rowOutput += ']';
- console.log(rowOutput);
- }
- return outputGrid;
-};
-
// Print out all of the related tiles to every new tile to be created.
let filecoutner: number = 0;
-async function main(): Promise<void> {
- // temper:
- for (let ys: number = 0; ys < totalSizeY; ys += tileSize) {
+async function extrapolateDimension(cVal: number, totalCs: number, maxZoomLevel: number): Promise<CZIHeightMap[]> {
+ console.log(`Stage (${cVal + 1}/${totalCs}): Task(0/${Math.ceil(totalSizeY/tileSize)}): 0% complete.`)
+ for (let ys: number = 0; ys < totalSizeY;) {
+ var timing = process.hrtime();
for (let xs: number = 0; xs < totalSizeX; xs += tileSize) {
- const sortedSegments: Segment[][] = sortSegmentsTest(0, tileSize, tileOverlap, xs, ys);
+ const desired = new TileBounds (
+ xs - tileOverlap,
+ xs + tileSize + tileOverlap,
+ ys - tileOverlap,
+ ys + tileSize + tileOverlap
+ );
+ filterC(cVal);
+
+ // console.log(filteredDataBlocks.map((x: any) => x.Data.DirectoryEntry.DimensionEntries[2]));
+ const sortedSegments: Segment[][] = orderSegments(findRelatedTiles(filteredDataBlocks, desired));
(await extractAndStitchChunks(sortedSegments, desired)).toFile(`${outputImageDirectory}img-${filecoutner++}`);
}
- // break temper;
+ ys += tileSize;
+ timing = process.hrtime(timing);
+ console.log(`Stage (${cVal + 1}/${totalCs}): Task(${ys/tileSize}/${Math.ceil(totalSizeY/tileSize)}): ${Math.ceil(((ys/totalSizeY)*100) *100)/100}% complete. (${timing[0]} sec/iter)`);
}
+ return [];
}
-main().then(v => {
- //Write the json hierarchy map to file
- console.log("complete");
-}, err => {
- console.log(err);
-});
+let finalCZIJson: WholeCZIHierarchy = {} as any;
+async function main(): Promise<void> {
+ for (const cval of supportedViews.scalable_image.channels) {
+ await extrapolateDimension(Number.parseInt(cval.channel_id, 10), supportedViews.scalable_image.channels.length, maxZoom).then(v =>
+ {
+ finalCZIJson.c_values.push({channel_id: cval.channel_id, height_map: v});
+ console.log(`Completed Tier: ${cval.channel_id}`);
+ return;
+ }, err => {
+ console.error(err);
+ }
+ );
+ }
+ fs.writeFile(`${outputImageDirectory}layout.json`, JSON.stringify(finalCZIJson), (err) => console.error(err));
+}
+main();