Example #1
0
    def render_mouse_brain(self, view_matrix: np.ndarray,
                           annotation_volume: Volume, energy_volumes: dict,
                           image_size: int, image: np.ndarray):
        """
        fucntion that implements the visualization of the mouse brain.
        select below the function that you want in order to visualize the data.
        """
        # create volumes for the gradient magnitude and mask
        magnitude_volume = np.zeros(annotation_volume.data.shape)
        for x in range(0, annotation_volume.dim_x):
            for y in range(0, annotation_volume.dim_y):
                for z in range(0, annotation_volume.dim_z):
                    magnitude_volume[
                        x, y,
                        z] = self.annotation_gradient_volume.get_gradient(
                            x, y, z).magnitude
        magnitude_volume = Volume(magnitude_volume)
        mask_volume = np.copy(self.annotation_gradient_volume.mask).astype(int)
        mask_volume = Volume(mask_volume)

        #################################################
        # set of different functions
        # self.visualize_annotations_only(view_matrix, mask_volume, annotation_volume, magnitude_volume, image_size, image, csv_colors = False, precision = 1)
        self.visualize_energies_only(view_matrix,
                                     mask_volume,
                                     energy_volumes,
                                     image_size,
                                     image,
                                     annotation_aware=True,
                                     precision=1)
Example #2
0
    def handle_click(self, event):
        """Show the load file dialog"""
        if self.load_dialog.ShowModal() == wx.ID_CANCEL:
            return

        pathname = self.load_dialog.GetPath()
        try:
            volume_io = VolumeIO(pathname)
            volume_data = volume_io.data
            volume = Volume(volume_data)

            TFUNC.init(volume.get_minimum(), volume.get_maximum())
            self.file_name_label.SetLabel(f"File name: {basename(pathname)}")
            self.dimensions_label.SetLabel(
                f"Dimensions: {volume_io.dim_x}x{volume_io.dim_y}x{volume_io.dim_z}"
            )
            self.value_range_label.SetLabel(
                f"Voxel value range: {volume.get_minimum():.3g}-{volume.get_maximum():.3g}"
            )

            self.visualization.set_volume(volume)
            self.on_data_loaded(volume)
        except Exception:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_exception(exc_type,
                                      exc_value,
                                      exc_traceback,
                                      limit=2,
                                      file=sys.stdout)
            dialog = wx.MessageDialog(
                None,
                message="An error occurred while reading the file",
                style=wx.ICON_ERROR | wx.OK)
            dialog.ShowModal()
            dialog.Destroy()
Example #3
0
    def render_mouse_brain(self, view_matrix: np.ndarray,
                           annotation_volume: Volume, energy_volumes: dict,
                           image_size: int, image: np.ndarray):

        self.tfunc.init(
            0,
            math.ceil(
                self.annotation_gradient_volume.get_max_gradient_magnitude()))
        magnitudeVolume = Volume(
            self.annotation_gradient_volume.magnitudeVolume)

        # Chose the visulization mode
        option = 1

        if option == 0:
            # Compositing rendering of the region specified in volume file
            self.render_compositing(view_matrix, magnitudeVolume, image_size,
                                    image)
        elif option == 1:
            # Compositing rendering of multiple energy in the whole brain
            self.render_energy_compositing(
                view_matrix, self.annotation_gradient_volume.volume,
                image_size, image, energy_volumes)
        elif option == 2:
            # Compositing rendering of multiple energy in the region specified in volume file
            self.render_energy_region_compositing(
                view_matrix, self.annotation_gradient_volume.volume,
                image_size, image, energy_volumes, magnitudeVolume)
        pass
Example #4
0
    def handle_energy_selected(self, evt: wx.CommandEvent):
        selection = evt.GetSelection()
        file_name = self.available_energy_items[selection]
        energy_number = int(file_name[:-11])
        if energy_number in self.energy_selected:
            self.energy_selected.remove(energy_number)
            self.visualization.remove_energy_volume(energy_number)
        else:
            self.energy_selected.add(energy_number)
            volumeio = VolumeIO(os.path.join(self.energies_path, file_name))
            volume = Volume(volumeio.data, compute_histogram=False)
            self.visualization.add_energy_volume(energy_number, volume)

        self.on_challenge_data_changed(len(self.energy_selected) > 0)
Example #5
0
def test_interpolate():
    data = np.fromfile('tests/default_volume', dtype=np.int).reshape((256, 256, 163))
    volume = Volume(data)
    view_matrix = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    inverse_view_matrix = np.linalg.inv(view_matrix)
    points_raw = np.fromfile('tests/default_points', dtype=np.float).reshape(4,3)

    interpolated_values = interpolate(volume, points_raw, inverse_view_matrix)

    # assert (np.abs(interpolated_values - np.array([ 47.44855585,  71.62875015, 133.71909277,  59.86651823]))).all(), \
    #                         "works with just raw points in input"
    assert np.isclose(interpolated_values, np.array([ 47.44855585,  71.62875015, 133.71909277,  59.86651823])).all(), \
                            "works with just raw points in input"

    inverse_view_matrix = [[0.1, -0.5, -0.8], [-0.3, 0.8, -0.5], [0.9, 0.3, 0]]
    interpolated_values = interpolate(volume, points_raw, inverse_view_matrix)

    # assert (np.abs(interpolated_values - np.array([ 47.44855585,  71.62875015, 133.71909277,  59.86651823]))).all(), \
    #                         "works with just raw points in input"
    assert np.isclose(interpolated_values, np.array([ 47.44855585,  71.62875015, 133.71909277,  59.86651823])).all(), \
                            "should work with wierd view_matrix"
Example #6
0
    def handle_annotation_selected(self, evt: wx.CommandEvent):
        selection = evt.GetSelection()  # type: int
        if self.selection != selection:
            self.selection = selection
            item = self.annotations_items[selection]
            mhd_energies = ANNOTATION_2_ENERGY[item][:10]
            intersection = set(self.energy_items) & set(mhd_energies)
            self.available_energy_items = [
                file for file in mhd_energies if file in intersection
            ]
            self.energy_list.Clear()
            self.energy_list.AppendItems(self.available_energy_items)
            self.energy_selected.clear()
            self.visualization.clear_energy_volumes()
            volumeio = VolumeIO(
                os.path.join(self.annotations_path,
                             self.annotations_items[selection]))
            self.visualization.set_annotation_volume(
                Volume(volumeio.data, compute_histogram=False))

            self.on_challenge_data_changed(False)