From 4a2d35719abd68537a7fd1479aa26023a1647f84 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Mon, 10 Apr 2023 15:14:34 -0400 Subject: [PATCH] Bug fixes (#646) * "sklearn" import name * Fix render flickering issues * Fix resetting slices on frame change * Lint fix --- miqa/learning/correlator.py | 2 +- miqa/learning/nn_inference.py | 7 +---- miqa/learning/nn_training.py | 2 +- web_client/src/components/VtkViewer.vue | 38 ++++++++++++++----------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/miqa/learning/correlator.py b/miqa/learning/correlator.py index ad3e9af9..1cede05c 100644 --- a/miqa/learning/correlator.py +++ b/miqa/learning/correlator.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import pandas as pd -from scikit_learn.metrics import confusion_matrix +from sklearn.metrics import confusion_matrix df = pd.read_csv('M:/MIQA/data.csv') # manually converted TRUE/FALSE into 1/0 print(f'count NaN: {df.isnull().sum().sum()}') diff --git a/miqa/learning/nn_inference.py b/miqa/learning/nn_inference.py index faa723c2..771908e6 100644 --- a/miqa/learning/nn_inference.py +++ b/miqa/learning/nn_inference.py @@ -4,12 +4,7 @@ import itk import monai import numpy as np -from scikit_learn.metrics import ( - classification_report, - confusion_matrix, - mean_squared_error, - r2_score, -) +from sklearn.metrics import classification_report, confusion_matrix, mean_squared_error, r2_score import torch from torch.utils.data import DataLoader import torchio diff --git a/miqa/learning/nn_training.py b/miqa/learning/nn_training.py index d1ccc6d3..a7995271 100755 --- a/miqa/learning/nn_training.py +++ b/miqa/learning/nn_training.py @@ -21,7 +21,7 @@ ) import numpy as np import pandas as pd -from scikit_learn.metrics import confusion_matrix +from sklearn.metrics import confusion_matrix import torch from torch.utils.data import DataLoader from torch.utils.tensorboard import SummaryWriter diff --git a/web_client/src/components/VtkViewer.vue b/web_client/src/components/VtkViewer.vue index 63416a34..ca03fb44 100644 --- a/web_client/src/components/VtkViewer.vue +++ b/web_client/src/components/VtkViewer.vue @@ -104,13 +104,17 @@ export default { this.initializeSlice(); this.initializeView(); }, - currentFrame() { - this.prepareViewer(); + currentFrame(oldFrame, newFrame) { this.representation.setSlice(this.slice); - }, - currentScan() { - this.initializeSlice(); - this.initializeCamera(); + this.applyCurrentWindowLevel(); + this.updateCrosshairs(); + // use this instead of currentScan watcher + // currentScan is computed from currentFrame and technically + // will change every time currentFrame has changed + if (oldFrame.scan !== newFrame.scan) { + this.initializeSlice(); + this.initializeCamera(); + } }, showCrosshairs() { this.updateCrosshairs(); @@ -150,9 +154,7 @@ export default { } }); this.resizeObserver.observe(this.$refs.viewer); - const representationProperty = this.representation.getActors()[0].getProperty(); - representationProperty.setColorWindow(this.currentWindowWidth); - representationProperty.setColorLevel(this.currentWindowLevel); + this.applyCurrentWindowLevel(); }, initializeSlice() { if (this.name !== 'default') { @@ -162,13 +164,12 @@ export default { initializeView() { this.view.setContainer(this.$refs.viewer); fill2DView(this.view); - if (this.name !== 'default') { - this.modifiedSubscription = this.representation.onModified(() => { - if (!this.loadingFrame) { - this.slice = this.representation.getSlice(); - } - }); - } + // add scroll interaction to change slice + this.view.getInteractor().onMouseWheel(() => { + if (!this.loadingFrame) { + this.slice = this.representation.getSlice(); + } + }); // add click interaction to place crosshairs this.view.getInteractor().onLeftButtonPress((event) => this.placeCrosshairs(event)); // remove drag interaction to change window @@ -206,6 +207,11 @@ export default { this.view.resetCamera(); fill2DView(this.view); }, + applyCurrentWindowLevel() { + const representationProperty = this.representation.getActors()[0].getProperty(); + representationProperty.setColorWindow(this.currentWindowWidth); + representationProperty.setColorLevel(this.currentWindowLevel); + }, findClosestColumnToVector(inputVector, matrix) { let currClosest = null; let currMax = 0;