コード例 #1
0
    def get_keyPoints(self):
        local_threshold = float(self.params['local_threshold'])
        _device = int(self.params['device'])
        symmetry = float(self.params['symmetry'])
        targetDir = str(self.params['targetDir'])
        cellsize = int(self.params['cellsize'])
        ccl = str(self.params['ccl'])

        print("[get_keyPoints] device: {}, verbose: {}".format(
            _device, self.verbose))
        for file in self.files:
            img = imreadTif(file)
            binary = threshold_loader(img,
                                      stride=32,
                                      grid_size=32,
                                      color_channel=4095,
                                      thres=local_threshold,
                                      device=_device,
                                      FLAG="matrix")

            cells = ccl_map(binary, ccl, cellsize, device=_device)

            binary, cells = symmetry_mapping(cells, thres=symmetry)

            pos = center_cell(cells)

            img_out = imreadTif(file)

            if (self.verbose == True):

                img = img_out.astype('uint16')
                img = gray2rgb(img)
                img = rescale_intensity(img)
                for point in pos:
                    img = drawMarker(img, point)
                _path = targetDir + "/" + file.replace("tif", "png")

                imwrite(img, _path)
                imwrite(binary, _path.replace(".png", "_mapping.jpeg"))
                yield file, cells, pos, img_out
            else:
                yield file, cells, pos, img_out
コード例 #2
0
ファイル: inference.py プロジェクト: overshiki/NNWrapper
def analyze(img, checkPath, targetPath, device):
    stride = 5
    pos_x = np.arange(0, 2048, stride)
    pos_y = np.arange(0, 2048, stride)
    vx, vy = np.meshgrid(pos_x, pos_y)
    pos = np.stack([vx, vy]).reshape((2, -1)).transpose([1, 0])

    PRED, pos = inference(img, pos, checkPath, device, size=31)

    op = operation(device=device)

    INDEX = op.where(PRED > 0)
    print("finished where")
    pos = pos[INDEX]
    pos = pos.ndarray().get()

    img = rescale_intensity(img.astype('uint8'))

    img = drawRedPoints(img, pos, half_size=2)

    imwrite(img, targetPath)
コード例 #3
0
ファイル: inference.py プロジェクト: overshiki/NNWrapper
    img = imreadTif(path)
    pos = doubleLayer_analyze(img)

    pos = pos.cpu()
    _pos = []

    half_size = 15

    for x in range(-1 * half_size, half_size, 5):
        for y in range(-1 * half_size, half_size, 5):
            _pos.append(pos + np.array([x, y]))

    pos = np.concatenate(_pos, axis=0)
    print(pos.shape)

    img = rescale_intensity(img.astype('uint8'))

    img = drawRedPoints(img, pos, half_size=2)

    imwrite(img, "./log/result.png")

# if __name__ == '__main__':
# 	from CV.ImageIO import center_cell, imreadTif, imshow_plt, plt, gray2rgb, drawMarker, drawRedPoints, imwrite, rescale_intensity
# 	import os, re
# 	from timeit import default_timer as timer
# 	path = "../../../../DATA/CELL/10.tif"
# 	# path = "/media/processed/Dec_2017/CST-20171211-01/changhai12.11/DATA/"
# 	# path = path+list(filter(lambda x: re.search("tif", x), os.listdir(path)))[0]
# 	print(path)

# 	# checkPath = "./log/params/size_61/25.pkl"
コード例 #4
0
    def get_points(self, half_size=80, extra=0):
        local_threshold = float(self.params['local_threshold'])
        _device = int(self.params['device'])
        symmetry = float(self.params['symmetry'])
        # targetDir = str(self.params['targetDir'])
        cellsize = int(self.params['cellsize'])
        ccl = str(self.params['ccl'])

        print("[get_insider] device: {}, verbose: {}".format(
            _device, self.verbose))
        for file in self.files:
            img = imreadTif(file)
            binary = threshold_loader(img,
                                      stride=32,
                                      grid_size=32,
                                      color_channel=4095,
                                      thres=local_threshold,
                                      device=_device,
                                      FLAG="matrix")

            cells = ccl_map(binary, ccl, cellsize, device=_device)

            binary, cells = symmetry_mapping(cells, thres=symmetry)

            pos = center_cell(cells)

            img_bound = [0, 2048]

            mapping = np.zeros((2048, 2048))
            num = len(cells) + extra
            img_out = imreadTif(file)

            for cell in cells:
                _bound, _ = boundary(cell=cell, _range=None)
                if (_bound[0] - half_size >= img_bound[0]):
                    _bound[0] = _bound[0] - half_size
                else:
                    _bound[0] = img_bound[0]
                if (_bound[2] - half_size >= img_bound[0]):
                    _bound[2] = _bound[2] - half_size
                else:
                    _bound[2] = img_bound[0]

                if (_bound[1] + half_size <= img_bound[1]):
                    _bound[1] = _bound[1] + half_size
                else:
                    _bound[1] = img_bound[1]
                if (_bound[3] - half_size <= img_bound[1]):
                    _bound[3] = _bound[3] + half_size
                else:
                    _bound[3] = img_bound[1]

                mapping[_bound[0]:_bound[1], _bound[2]:_bound[3]] = 1

            mapping[0:half_size, :] = 1
            mapping[img_bound[1] - half_size:img_bound[1], :] = 1

            mapping[:, 0:half_size] = 1
            mapping[:, img_bound[1] - half_size:img_bound[1]] = 1

            pts = np.array(np.where(mapping == 0)).transpose()
            if (pts.shape[0] >= num):
                index = np.random.choice(pts.shape[0], num)
                choice = pts[index]
            else:
                choice = np.zeros((0, 2))

            if (len(pos) > 0):
                if (self.verbose == True):
                    img = img_out.copy()
                    img = rescale_intensity(img.astype('uint8'))

                    mask_true = drawMarkers(np.array(pos), 10, 2)
                    mask_false = drawMarkers(choice, 10, 2)

                    img = np.stack([img, img, img], axis=2)

                    index = list(np.where(mask_true == 1))
                    index.append(
                        (np.ones(index[0].shape[0]) * 2).astype('int32'))
                    # img[index] = 55535
                    img[index] = 255

                    index = list(np.where(mask_false == 1))
                    index.append(
                        (np.ones(index[0].shape[0]) * 1).astype('int32'))
                    # img[index] = 55535
                    img[index] = 255

                    _path = self.targetDir + "/" + os.path.basename(
                        file).replace("tif", "png")
                    print("[verbose]: ", _path)
                    imwrite(img, _path)

                    yield file, cells, pos, choice, img_out
                else:
                    yield file, cells, pos, choice, img_out