Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def show_image(self, img, annot=None):
"""Display the requested slices of an image on the existing axes."""
for ax_index, (dim_index, slice_index) in enumerate(self.slices):
self.h_images[ax_index].set(data=get_axis(img, dim_index, slice_index),
cmap=self.current_cmap)
if annot is not None:
self._identify_foreground(annot)
else:
self.fg_annot_h.set_visible(False)
ax = ax.flatten()
# display surfaces
for sf_counter, ((hemi, view), spath) in enumerate(surf_vis.items()):
plt.sca(ax[sf_counter])
img = mpimg.imread(spath)
# img = crop_image(img)
plt.imshow(img)
ax[sf_counter].text(0, 0, '{} {}'.format(hemi, view))
plt.axis('off')
# display slices
for ax_counter, (dim_index, slice_num) in enumerate(slices):
plt.sca(ax[ax_counter + num_surf_vis])
slice_mri = get_axis(mri, dim_index, slice_num)
slice_seg = get_axis(seg, dim_index, slice_num)
# display MRI
mri_rgb = mri_mapper.to_rgba(slice_mri)
h_mri = plt.imshow(mri_rgb, **display_params_mri)
if 'volumetric' in qcw.vis_type:
seg_rgb = seg_mapper.to_rgba(slice_seg)
h_seg = plt.imshow(seg_rgb, **display_params_seg)
elif 'contour' in qcw.vis_type:
h_seg = plot_contours_in_slice(slice_seg, unique_labels, color4label)
plt.axis('off')
# # encoding the souce of the object (image/line) being displayed
# handle_seg.set_label('seg {} {}'.format(dim_index, slice_num))
def show_image(self, img, annot=None):
"""Display the requested slices of an image on the existing axes."""
for ax_index, (dim_index, slice_index) in enumerate(self.slices):
self.h_images[ax_index].set(data=get_axis(img, dim_index, slice_index),
cmap=self.current_cmap)
if annot is not None:
self._identify_foreground(annot)
else:
self.fg_annot_h.set_visible(False)
def overlay_dwi_edges(self):
# not cropping to help checking align in full FOV
overlaid = scale_0to1(self.b0_volume)
base_img = scale_0to1(self.dw_volumes[..., self.current_grad_index].squeeze())
slices = pick_slices(base_img, self.views, self.num_slices_per_view)
for ax_index, (dim_index, slice_index) in enumerate(slices):
mixed = dwi_overlay_edges(get_axis(base_img, dim_index, slice_index),
get_axis(overlaid, dim_index, slice_index))
self.images_fg[ax_index].set(data=mixed)
self.images_fg_label[ax_index].set_text(str(slice_index))
# the following needs to be done outside show_image3d, as we need custom mixing
self._set_backgrounds_visibility(False)
self._set_foregrounds_visibility(True)
self._identify_foreground('Alignment check to b=0, '
'grad index {}'.format(self.current_grad_index))
def mix_and_display(self):
"""Static mix and display."""
# TODO maintain a dict mixed[vis_type] to do computation only once
for ax_index, (dim_index, slice_index) in enumerate(self.slices):
slice_one = get_axis(self.image_one, dim_index, slice_index)
slice_two = get_axis(self.image_two, dim_index, slice_index)
mixed_slice = self.mixer(slice_one, slice_two)
# mixed_slice is already in RGB mode m x p x 3, so
# prev. cmap (gray) has no effect on color_mixed data
self.h_images[ax_index].set(data=mixed_slice, cmap=self.current_cmap)
ax = ax.flatten()
# display surfaces
for sf_counter, ((hemi, view), spath) in enumerate(surf_vis.items()):
plt.sca(ax[sf_counter])
img = mpimg.imread(spath)
# img = crop_image(img)
plt.imshow(img)
ax[sf_counter].text(0, 0, '{} {}'.format(hemi, view))
plt.axis('off')
# display slices
for ax_counter, (dim_index, slice_num) in enumerate(slices):
plt.sca(ax[ax_counter + num_surf_vis])
slice_mri = get_axis(mri, dim_index, slice_num)
slice_seg = get_axis(seg, dim_index, slice_num)
# display MRI
mri_rgb = mri_mapper.to_rgba(slice_mri)
h_mri = plt.imshow(mri_rgb, **display_params_mri)
if 'volumetric' in qcw.vis_type:
seg_rgb = seg_mapper.to_rgba(slice_seg)
h_seg = plt.imshow(seg_rgb, **display_params_seg)
elif 'contour' in qcw.vis_type:
h_seg = plot_contours_in_slice(slice_seg, unique_labels, color4label)
plt.axis('off')
# # encoding the souce of the object (image/line) being displayed
# handle_seg.set_label('seg {} {}'.format(dim_index, slice_num))
# handle_mri.set_label('mri {} {}'.format(dim_index, slice_num))
def attach_image_to_foreground_axes(self, image3d, cmap='gray'):
"""Attaches a given image to the foreground axes and bring it forth"""
image3d = crop_image(image3d, self.padding)
image3d = scale_0to1(image3d)
slices = pick_slices(image3d, self.views, self.num_slices_per_view)
for ax_index, (dim_index, slice_index) in enumerate(slices):
slice_data = get_axis(image3d, dim_index, slice_index)
self.images_fg[ax_index].set(data=slice_data, cmap=cmap)
for ax in self.fg_axes:
ax.set(visible=True, zorder=self.layer_order_zoomedin)