From a02e7709bc7179db02a3109864f2cca13eb23dc5 Mon Sep 17 00:00:00 2001 From: Simon Warchol Date: Tue, 14 Sep 2021 09:47:02 -0400 Subject: [PATCH] Attempting to fix issue with seg tiles being redrawn --- .../client/src/js/views/imageViewer.js | 72 +++++++++++-------- minerva_analysis/server/models/data_model.py | 30 +++++--- minerva_analysis/test.py | 0 3 files changed, 60 insertions(+), 42 deletions(-) create mode 100644 minerva_analysis/test.py diff --git a/minerva_analysis/client/src/js/views/imageViewer.js b/minerva_analysis/client/src/js/views/imageViewer.js index 52a7da563..071333947 100644 --- a/minerva_analysis/client/src/js/views/imageViewer.js +++ b/minerva_analysis/client/src/js/views/imageViewer.js @@ -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("/"); @@ -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(); + } } } }); @@ -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'); // @@ -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)) { diff --git a/minerva_analysis/server/models/data_model.py b/minerva_analysis/server/models/data_model.py index 4dbcc2d7d..7b5c612f4 100644 --- a/minerva_analysis/server/models/data_model.py +++ b/minerva_analysis/server/models/data_model.py @@ -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} diff --git a/minerva_analysis/test.py b/minerva_analysis/test.py new file mode 100644 index 000000000..e69de29bb