From 5a37c671670a8b164f9fdfc09e34a6cebfdc1561 Mon Sep 17 00:00:00 2001 From: Robert Ohmacht Date: Thu, 14 Nov 2019 16:25:28 +0100 Subject: [PATCH] -fixes transition from optical scan to raman scan -detectionview uses unscaled image --- detectionview.py | 2 +- sampleview.py | 2 +- scenePyramid.py | 120 ++++++++++++++++++++++++----------------------- 3 files changed, 63 insertions(+), 61 deletions(-) diff --git a/detectionview.py b/detectionview.py index e1adde4..8160b15 100644 --- a/detectionview.py +++ b/detectionview.py @@ -274,7 +274,7 @@ class ParticleDetectionView(QtWidgets.QWidget): super().__init__(parent, QtCore.Qt.Window) self.dataset = self.verifySeedpoints(dataset) self.pyramid = pyramid - self.img = pyramid.getFullImage(.5) + self.img = pyramid.getFullImage() self.imgclip = 0, 0, 0, 0 self.seg = Segmentation(self.dataset, self) self.thread = None diff --git a/sampleview.py b/sampleview.py index cfa2b29..1d74c87 100644 --- a/sampleview.py +++ b/sampleview.py @@ -351,7 +351,7 @@ class SampleView(QtWidgets.QGraphicsView): if not self.ramanctrl.connected: return None maxmode = "OpticalScan" - if os.path.exists(self.dataset.getImageName()): + if os.path.exists(self.dataset.getZvalImageName()): maxmode = "ParticleDetection" if self.dataset.particleDetectionDone: maxmode = "RamanScan" diff --git a/scenePyramid.py b/scenePyramid.py index 8ed93df..be6e8f0 100644 --- a/scenePyramid.py +++ b/scenePyramid.py @@ -462,46 +462,6 @@ class ScenePyramid: """ self.microscopeMode = microscopemode - def getFullImage(self, scale): - """ - returns full size image - for this we use numpy to concatenate the tile images - :param: float scale - :return: full size image - :rtype: np.array - """ - first_col = True - img = None - col = None - # for big images use np.concatenate - # for each tile col - for x in range(len(self.tileWorkingSets[0])): - first_tile = True - # for each tile in col - for y in range(len(self.tileWorkingSets[0][x])): - tile = self.readViewTile(0, x, y) - if 1. != scale: - w = math.floor(scale * tile.shape[1]) - h = math.floor(scale * tile.shape[0]) - tile = np.array(Image.fromarray(tile).resize((w, h), resample=Image.BICUBIC)) - - if not first_tile: - col = np.concatenate((col, tile), axis=0) - else: - col = tile - first_tile = False - # self.imageOut(col, f"_col_{x}_{y}.tif") - - # self.imageOut(col, f"_col_{x}.tif") - if not first_col: - img = np.concatenate((img, col), axis=1) - else: - img = col - first_col = False - - # self.imageOut(img, f"_fullimage.tif") - return img - def getBoundingRectDim(self): """ returns bounding rectangle of all currently rendered tiles @@ -513,24 +473,6 @@ class ScenePyramid: self.scene.destroyItemGroup(group) return rect.width(), rect.height() - def getSubImage(self, clip): - """ - :param (int, int, int, int) clip: (y1, y2, x1, x2) - :return: - :rtype: (np.array, QtGui.QPixmap) - """ - y1, y2, x1, x2 = clip - width = x2 - x1 - height = y2 - y1 - subimg = self.getImagePart(y1, y2, x1, x2) - - pix = QtGui.QPixmap() - pix.convertFromImage( - QtGui.QImage(subimg, width, height, 3 * width, QtGui.QImage.Format_RGB888) - ) - - return subimg, pix - def addSrcTileSimple(self, img, pos, p): """ gets called by opticalscan.takePoint() in scan setup process @@ -811,6 +753,24 @@ class ScenePyramid: p['maxSliceNumber'] = slice_nr - 1 dset.setPyramidParams(p) + def getSubImage(self, clip): + """ + :param (int, int, int, int) clip: (y1, y2, x1, x2) + :return: + :rtype: (np.array, QtGui.QPixmap) + """ + y1, y2, x1, x2 = clip + width = x2 - x1 + height = y2 - y1 + subimg = self.getImagePart(y1, y2, x1, x2) + + pix = QtGui.QPixmap() + pix.convertFromImage( + QtGui.QImage(subimg, width, height, 3 * width, QtGui.QImage.Format_RGB888) + ) + + return subimg, pix + def getImagePart(self, p0y, p1y, p0x, p1x): """ returns part of the full img @@ -871,8 +831,50 @@ class ScenePyramid: cv2.warpAffine(tile, m_trans, size, img, flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_TRANSPARENT) # comment in(?) to check result in tile path - self.imageOut(img, f"_image_part.tif") + # self.imageOut(img, f"_image_part.tif") + + return img + + def getFullImage(self, scale=1.): + """ + returns full image scaled to the given value + for this we use numpy to concatenate the tile images + :param: float scale + :return: full size image + :rtype: np.array + """ + assert 0. <= scale <= 1. + + first_col = True + img = None + col = None + # for big images use np.concatenate + # for each tile col + for x in range(len(self.tileWorkingSets[0])): + first_tile = True + # for each tile in col + for y in range(len(self.tileWorkingSets[0][x])): + tile = self.readViewTile(0, x, y) + if 1. != scale: + w = math.floor(scale * tile.shape[1]) + h = math.floor(scale * tile.shape[0]) + tile = np.array(Image.fromarray(tile).resize((w, h), resample=Image.BICUBIC)) + + if not first_tile: + col = np.concatenate((col, tile), axis=0) + else: + col = tile + first_tile = False + # self.imageOut(col, f"_col_{x}_{y}.tif") + + # self.imageOut(col, f"_col_{x}.tif") + if not first_col: + img = np.concatenate((img, col), axis=1) + else: + img = col + first_col = False + # self.imageOut(img, f"_fullimage.tif") return img def imageOut(self, img, name): -- GitLab