Skip to content

Commit

Permalink
Attempting to fix issue with seg tiles being redrawn
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwarchol committed Sep 14, 2021
1 parent c6319be commit a02e770
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 42 deletions.
72 changes: 41 additions & 31 deletions minerva_analysis/client/src/js/views/imageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class ImageViewer {
//
seaGL.addHandler('tile-drawing', async function (callback, e) {


// Read parameters from each tile
const tile = e.tile;
const group = e.tile.url.split("/");
Expand Down Expand Up @@ -140,10 +139,19 @@ class ImageViewer {
// await that.drawLabels(e);
} else {
if (e.tile._redrawLabel) {
if (!e.tile._array || !e.tile._tileImageData) {
console.log('Missing Array', e.tile.url);
// this.refreshSegmentationMask();
}
that.drawLabelTile(e.tile, e.tile._tileImageData.width, e.tile._tileImageData.height);
}
if (e.tile.containsLabel) {
e.rendered.putImageData(e.tile._tileImageData, 0, 0);
try {
e.rendered.putImageData(e.tile._tileImageData, 0, 0);
} catch (err) {
console.log('Another issue', err, e.tile.url);
// this.refreshSegmentationMask();
}
}
}
});
Expand Down Expand Up @@ -172,47 +180,52 @@ class ImageViewer {


seaGL.addHandler('tile-loaded', (callback, e) => {
try {
const group = e.tile.url.split("/");
let isLabel = group[group.length - 3] == that.labelChannel.sub_url;
e.tile._blobUrl = e.image.src;
// Label Tiles We'll view as 32 bits to get the ID values and save that on the tile object so it's cached
if (isLabel) {
e.tile._array = new Int32Array(PNG.sync.read(new Buffer(e.tileRequest.response), {colortype: 0}).data.buffer);

that.drawLabelTile(e.tile, e.image.width, e.image.height);

// We're hence skipping that OpenseadragonGL callback since we only care about the vales
return e.getCompletionCallback()();
} else {
// This goes to OpenseadragonGL which does the necessary bit stuff.
return callback(e);
}
} catch (e) {
console.log('Load Error, Refreshing');
that.forceRepaint();
var decoder = new Promise(function (resolve, reject) {
try {
const group = e.tile.url.split("/");
let isLabel = group[group.length - 3] == that.labelChannel.sub_url;
e.tile._blobUrl = e.image?.src;
if (isLabel) {
e.tile._isLabel = true;
if (!e.tile._array) {
e.tile._array = new Int32Array(PNG.sync.read(new Buffer(e.tileRequest?.response ||
e.image._array), {colortype: 0}).data.buffer);
}
that.drawLabelTile(e.tile, e.image?.width || e.tile?._tileImageData?.width, e.image?.height
|| e.tile?._tileImageData?.height);

// We're hence skipping that OpenseadragonGL callback since we only care about the vales
return resolve();
} else {
return callback(e)
// This goes to OpenseadragonGL which does the necessary bit stuff.
}
} catch (err) {
console.log('Load Error, Refreshing', err, e.tile.url);
that.forceRepaint();

// return callback(e);
}
// return callback(e);
}
// Notify openseadragon when decoded
decoder.then(e.getCompletionCallback())
});
});



this.viewer.addHandler('tile-drawn', (e) => {
let count = _.size(e.tiledImage._tileCache._tilesLoaded);
e.tiledImage._tileCache._imagesLoadedCount = count;

})

this.viewer.addHandler('tile-unloaded', (e) => {
(window.URL || window.webkitURL).revokeObjectURL(e.tile._blobUrl);
if (e.tile._blobUrl) {
(window.URL || window.webkitURL).revokeObjectURL(e.tile._blobUrl);
}
delete e.tile._array;
delete e.tile._tileImageData;
})




// Instantiate viewer managers
that.viewerManagerVMain = new ViewerManager(that, seaGL.openSD, 'main');
//
Expand Down Expand Up @@ -595,9 +608,6 @@ ImageViewer

async function addTile(path) {
const addJob = new Promise((resolve, reject) => {
if (seaDragonViewer.tileCache[path]) {
resolve();
}

// If we're currently waiting for a tile to load, just use it's callback
if (seaDragonViewer.pendingTiles.has(path)) {
Expand Down
30 changes: 19 additions & 11 deletions minerva_analysis/server/models/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,17 +664,25 @@ def convertOmeTiff(filePath, channelFilePath=None, dataDirectory=None, isLabelIm
channel_io = tf.TiffFile(str(channelFilePath), is_ome=False)
channels = zarr.open(channel_io.series[0].aszarr())
write_path = None
directory = Path(dataDirectory + "/" + filePath.name)
segmentation_mask = tf.TiffFile(str(filePath), is_ome=False)
if segmentation_mask.series[0].aszarr().is_multiscales is False:
args = {}
args['in_paths'] = [Path(filePath)]
args['out_path'] = directory
args['is_mask'] = True
pyramid_assemble.main(py_args=args)
write_path = str(directory)
else:
write_path = str(filePath)
# removing '.ome' from the name
directory = Path(dataDirectory + "/" + str(filePath.name).replace('.ome', '_pyramided'))
args = {}
args['in_paths'] = [Path(filePath)]
args['out_path'] = directory
args['is_mask'] = True
pyramid_assemble.main(py_args=args)
write_path = str(directory)
# TODO: Reintroduce when MCMICRO pipeline produces better masks
# segmentation_mask = tf.TiffFile(str(filePath), is_ome=False)
# if segmentation_mask.series[0].aszarr().is_multiscales is False:
# args = {}
# args['in_paths'] = [Path(filePath)]
# args['out_path'] = directory
# args['is_mask'] = True
# pyramid_assemble.main(py_args=args)
# write_path = str(directory)
# else:
# write_path = str(filePath)
return {'segmentation': write_path}


Expand Down
Empty file added minerva_analysis/test.py
Empty file.

0 comments on commit a02e770

Please sign in to comment.