def manual_segmentation(self, idx):
        """

        :param idx: {int} -- the index of the .broct file
        :return: None
        """
        for data in scans("../../data/oct_volume_calibration/" +
                          self.serial_num + "/config" + str(idx) + ".broct"):
            volume = data['volume']
            # volume = volume[:, :, 85:]
            volume = volume[:, :, :]
            volume_raw = np.array(volume, copy=True)
            for i in tqdm(range(volume.shape[0])):
                volume_raw[i] = volume_raw[i][::-1, :]
            pcd_s = self.pointcloud_process(volume_raw)
            pcd_s.paint_uniform_color([1, 0.706, 0])
            draw_geometries_with_editing([pcd_s])
    def intensity_projection(self, index, brightest_pix):
        """
        :param index: {int} -- the index of the .broct file
        :param brightest_pix: {int} -- the brightest pixel value
        :return: thres_map: {numpy.array} -- the intensity projection threshold map
        :return: volume: {numpy.array} -- the OCT volume
        :return: brightest_pix: {int} -- the brightest pixel value
        """
        for data in scans("../../data/oct_volume_calibration/" +
                          self.serial_num + "/config" + str(index) + ".broct"):
            volume = data['volume']
            for i in tqdm(range(volume.shape[0])):
                volume[i] = volume[i][::-1, :]
            volume_copy = np.copy(volume)
            volume = pcd_y_clip(volume, self.clip_threshold_y[index - 1])
            volume_sum = np.max(volume, axis=1)
            volume_sum -= volume_sum.min()
            if index == 1:
                brightest_pix = volume_sum.max()
            volume_sum = np.array(volume_sum *
                                  (100 / (brightest_pix - volume_sum.min())),
                                  dtype=np.uint8)

            # ### DEBUG ###
            cv.namedWindow('component', cv.WINDOW_NORMAL)
            cv.imshow('component', volume_sum)
            cv.waitKey(10)

            thres_map = cv.threshold(volume_sum, self.map_thres, 255,
                                     cv.THRESH_BINARY)[1]
            if index == 6:
                thres_map = cv.morphologyEx(thres_map, cv.MORPH_CLOSE,
                                            np.ones((3, 3)))
            else:
                thres_map = cv.morphologyEx(thres_map, cv.MORPH_CLOSE,
                                            np.ones((5, 5)))

            if self.clip_threshold_xz[index - 1][1] == -1:
                thres_map[:, :self.clip_threshold_xz[index - 1][0]] = 0
            else:
                thres_map[:, self.clip_threshold_xz[index - 1][0]:] = 0
            if self.clip_threshold_xz[index - 1][2] != 0:
                thres_map[self.clip_threshold_xz[index - 1][2]:, :] = 0

            volume_copy[:, :self.clip_threshold_y[index - 1][0] + 1, :] = 0
            return thres_map, volume_copy, brightest_pix
Esempio n. 3
0
def save_ideal_png(ideal_cscan, serial_num):
    """
    :param ideal_cscan: {int} -- the index of the ideal C-scan
    :param serial_num: {string} -- the serial number of needle insertion
    :return: None
    """
    for data in scans(
            "../../data/suture_experiment/suture_result_broct_files/AMAL_wound/"
            + serial_num + "_wound.broct"):
        volume = data['volume']
        bscan = volume[ideal_cscan - 1]
        bscan = bscan[::-1, :]
        bscan = (bscan - 54) / (100 - 54)
        bscan = np.clip(bscan, 0, 1)
        bscan = (255 * bscan).astype(np.uint8)
        os.makedirs(
            "../../data/suture_experiment/suture_result_broct_files/AMAL_png/"
            + serial_num + "/",
            exist_ok=True)
        imageio.imwrite(
            '../../data/suture_experiment/suture_result_broct_files/AMAL_png/'
            + serial_num + '/bscan.png',
            bscan,
            format='png')
import numpy
import cv2

import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import pyplot

from PyBROCT.io.reader import scans
from PyBROCT.render.cuda import CudaRenderer
from PyBROCT.render.cpu import CpuRenderer

from PyBROCT.matrix_util import perspective, lookat, rotx, roty, rotz, translate, scale, ortho

path = r"C:\Users\Mark\Downloads\eye.broct"

data = next(scans(path))[1]
vol = data['volume']
# vol = numpy.swapaxes(vol, 0, 2).copy()
print(vol.shape)
vol[:, 1000:, :] = 0
vol[:, :50, :] = 0
# vol = vol[:, ::10, :]
# vol = numpy.flip(vol, axis=1)

# vol[50:150, :, :] = 0
# vol[:, :, 300:500] = 0

# pyplot.imshow(vol[0, :400, :], aspect='auto')
# pyplot.show()
# raise SystemExit
    group.add_argument('--xscan',
                       nargs='?',
                       type=int,
                       help='cross B-scan index to dump')
    group.add_argument('--scan-all',
                       action='store_true',
                       help='dump all B-scans')
    group.add_argument('--mip', action='store_true', help='dump a MIP')

    args = parser.parse_args()

    chunks = max(1, args.average)

    for path in args.path:
        for path in glob(path):
            for (vidx, vol) in scans(path, skip=args.volume, count=args.count):
                data = vol['volume']

                if args.svp:
                    print(path, vidx, 'SVP', end=' ')

                    svp = numpy.mean(data, axis=1)
                    svp = _postprocess(args, svp)

                    out = '{}_{:03d}_svp.png'.format(
                        os.path.splitext(path)[0], vidx)
                    dpi = (1e3 * vol['xlength'] / svp.shape[0],
                           1e3 * vol['zlength'] / svp.shape[1])
                    imwrite(out, svp, dpi=dpi)
                    print('->', out)
                elif args.mip:
Esempio n. 6
0
import numpy
import imageio

import os

from PyBROCT.io.reader import scans

if __name__ == '__main__':
    serial_num = '200305O'
    for data in scans(
            "../../data/suture_experiment/suture_result_broct_files/suture/" +
            serial_num + "_suture.broct"):
        volume = data['volume']
        idx = 222
        for bscan in volume[222:256]:
            bscan = bscan[::-1, :]
            # white and black levels
            bscan = (bscan - 54) / (100 - 54)
            bscan = numpy.clip(bscan, 0, 1)
            bscan = (255 * bscan).astype(numpy.uint8)
            os.makedirs("../../data/suture_experiment/png_data/" + serial_num +
                        "/",
                        exist_ok=True)
            imageio.imwrite('../../data/suture_experiment/png_data/' +
                            serial_num + '/' + str(idx) + '_bscan.png',
                            bscan,
                            format='png')
            idx += 1