コード例 #1
0
    def __segment_nifti(self, source_file, filepath_only=False):
        # assert __is_nifti(source_file)

        payload         = {'source_file': source_file}

        print("filepath only ", filepath_only)

        response_dict = self.container_requester.send_request_to_worker(payload,
                                                                        self.worker_hostname,
                                                                        self.worker_port,
                                                                        self.segment_muscle_request_name)

        rel_seg_path = response_dict["segmentation"]
        data_share = os.environ["DATA_SHARE_PATH"]

        segmentation_path = os.path.join(data_share, rel_seg_path)
        abs_source_file   = os.path.join(data_share, source_file)

        if filepath_only:
            return segmentation_path, abs_source_file

        print("reading muscle segmentation from", segmentation_path)
        segmentation = nifti_reader.read_nifti_image(segmentation_path)
        original     = nifti_reader.read_nifti_image(abs_source_file)

        return segmentation, original
コード例 #2
0
def read_image(source_dir, filepath_only=False):
    data_share = os.environ["DATA_SHARE_PATH"]
    full_source = os.path.join(data_share, source_dir)

    if filepath_only:
        return full_source

    image = read_nifti_image(full_source)
    return image
コード例 #3
0
def convert(source_dir, filepath_only=False):
    data_share = os.environ["DATA_SHARE_PATH"]

    converter = Converter(ContainerRequester())
    nifti_filename = converter.convert_dcm_to_nifti(source_dir)
    nifti_filename = os.path.join(data_share, nifti_filename)

    if filepath_only:
        return nifti_filename

    return read_nifti_image(nifti_filename)
コード例 #4
0
    def __generate_maps(self, source_file, filepath_only):
        payload = {"source_file": source_file}

        response_dict = self.container_requester.send_request_to_worker(
            payload, self.worker_hostname, self.worker_port, self.request_name)

        rel_mask_volume_path = response_dict["auxiliary_volume"]
        rel_detection_volume_path = response_dict["detection_volume"]

        data_share = os.environ["DATA_SHARE_PATH"]

        mask_volume_path = os.path.join(data_share, rel_mask_volume_path)
        detection_volume_path = os.path.join(data_share,
                                             rel_detection_volume_path)

        if filepath_only:
            return mask_volume_path, detection_volume_path

        mask_volume = nifti_reader.read_nifti_image(mask_volume_path)
        detection_volume = nifti_reader.read_nifti_image(detection_volume_path)

        return mask_volume, detection_volume
コード例 #5
0
    def __docker_segment(self, source_dir, model_name, filepath_only):

        payload = {'source_dir': source_dir, 'model_name': model_name}

        response_dict = self.container_requester.send_request_to_worker(
            payload, self.worker_hostname, self.worker_port,
            self.segment_request_name)

        rel_seg_path = response_dict["segmentation"]

        data_share = os.environ["DATA_SHARE_PATH"]

        segmentation_path = os.path.join(data_share, rel_seg_path)
        if filepath_only:
            return segmentation_path

        segmentation = read_nifti_image(segmentation_path)
        return segmentation
コード例 #6
0
    def display_volume_and_slice_information(self,
                                             input_nifti_path,
                                             lung_seg_path=None,
                                             muscle_seg=None,
                                             lesion_detection=None,
                                             lesion_attention=None,
                                             lesion_detection_seg=None,
                                             lesion_mask_seg=None,
                                             fat_report=None,
                                             fat_interval=None):

        original_array = self.__get_array_from_image_path(input_nifti_path)

        # lung_seg_path may be None, in which case fat_report_displayer doesn't display anything
        lungmask_displayer \
            = LungmaskSegmentationDisplayer(input_nifti_path, lung_seg_path, streamlit_wrapper=self.st,
                                            download_displayer=self.download_class(streamlit_wrapper=self.st))

        # lung_seg is None if lung_seg_path is None
        lung_seg = lungmask_displayer.get_seg_array()

        # fat_report may be None, in which case fat_report_displayer doesn't display anything
        fat_report_displayer = FatReportDisplayer(
            original_array,
            fat_report,
            fat_interval=fat_interval,
            streamlit_wrapper=self.st,
            download_displayer=self.download_class(streamlit_wrapper=self.st))

        lungmask_displayer.download_button()
        fat_report_displayer.download_button()

        # may be None
        fat_report_cm3 = fat_report_displayer.get_converted_report()

        input_download_displayer = self.download_class(
            streamlit_wrapper=self.st)
        input_download_displayer.display(
            os.path.split(input_nifti_path)[1], "Input Image")

        detection_array = None
        attention_array = None
        muscle_seg_array = None
        detection_seg_array = None
        mask_seg_array = None

        if lesion_detection is not None:
            detection_array = read_nifti_image(lesion_detection)
            detection_array = sitk.GetArrayFromImage(detection_array)

            detection_download_displayer = self.download_class(
                streamlit_wrapper=self.st)
            detection_download_displayer.display(
                os.path.split(lesion_detection)[1], "Lesion Detection Volume")

        if lesion_attention is not None:
            attention_array = read_nifti_image(lesion_attention)
            attention_array = sitk.GetArrayFromImage(attention_array)

            attention_download_displayer = self.download_class(
                streamlit_wrapper=self.st)
            attention_download_displayer.display(
                os.path.split(lesion_attention)[1], "Attention Volume")

        if muscle_seg is not None:
            muscle_seg_array = read_nifti_image(muscle_seg)
            muscle_seg_array = sitk.GetArrayFromImage(muscle_seg_array)

            muscle_download_displayer = self.download_class(
                streamlit_wrapper=self.st)
            muscle_download_displayer.display(
                os.path.split(muscle_seg)[1], "Muscle Segmentation")

        if lesion_detection_seg is not None:
            detection_seg_array = read_nifti_image(lesion_detection_seg)
            detection_seg_array = sitk.GetArrayFromImage(detection_seg_array)

            detection_seg_download_displayer = self.download_class(
                streamlit_wrapper=self.st)
            detection_seg_download_displayer.display(
                os.path.split(lesion_detection_seg)[1],
                "Lesion Detection Segmentation")

        if lesion_mask_seg is not None:
            mask_seg_array = read_nifti_image(lesion_mask_seg)
            mask_seg_array = sitk.GetArrayFromImage(mask_seg_array)

            mask_seg_download_displayer = self.download_class(
                streamlit_wrapper=self.st)
            mask_seg_download_displayer.display(
                os.path.split(lesion_mask_seg)[1], "Lesion Detection Mask")

        lungmask_displayer.display()
        fat_report_displayer.display()

        self.__display_information_rows(original_array, lung_seg,
                                        muscle_seg_array, detection_array,
                                        attention_array, detection_seg_array,
                                        mask_seg_array, fat_report_cm3)
コード例 #7
0
 def __get_array_from_image_path(self, path):
     image = read_nifti_image(path)
     return sitk.GetArrayFromImage(image)