[scikit-image] Viewing 3D images/stacks of images
Kesavan Subburam
pskeshu at gmail.com
Fri May 19 12:45:21 EDT 2017
from matplotlib.widgets import Slider
import matplotlib.pyplot as plt
import numpy as np
def ddd(images):
def _update_image(num):
num = int(num)
image = np.squeeze(images[num:num+1])
img_ax.set_data(image)
fig.canvas.draw_idle()
if images.ndim is not 3:
raise ValueError("Not a 3D image.")
Z, _, _ = images.shape
fig, ax = plt.subplots()
img_ax = ax.imshow(np.squeeze(images[0]), cmap="gray")
ax.axis("off")
sliderax = plt.axes([0.19, 0.05, 0.65, 0.03],
facecolor="lightgoldenrodyellow")
img_slider = Slider(sliderax, "Z", 0, Z-1,
valfmt='%d', valinit=0)
img_slider.on_changed(_update_image)
plt.show()
I'd forgotten to include the import statements. Just in case you'd like to
test the code. Input image of shape (Z, N, M).
On 19 May 2017 at 22:10, Kesavan Subburam <pskeshu at gmail.com> wrote:
> Hi all,
>
> I'd used CollectionViewer from skimage.viewer before for viewing
> microscopy Z stacks. However, I personally felt it was a bit of a pain to
> use. For instance, before passing in an array of images, the image has to
> be stretched, otherwise, most of the time, one would end up with a "black"
> series of images.
>
> So, I wrote a simple function using matplotlib to view image collections,
> which works quite well, and I think it can be extended to display nD images
> with multiple sliders.
>
> def ddd(images):
> def _update_image(num):
> num = int(num)
> image = np.squeeze(images[num:num+1])
> img_ax.set_data(image)
> fig.canvas.draw_idle()
>
> if images.ndim is not 3:
> raise ValueError("Not a 3D image.")
>
> Z, _, _ = images.shape
>
> fig, ax = plt.subplots()
> img_ax = ax.imshow(np.squeeze(images[0]), cmap="gray")
> ax.axis("off")
>
> sliderax = plt.axes([0.19, 0.05, 0.65, 0.03],
> facecolor="lightgoldenrodyellow")
> img_slider = Slider(sliderax, "Z", 0, Z-1,
> valfmt='%d', valinit=0)
> img_slider.on_changed(_update_image)
> plt.show()
>
>
> This might be a bit redundant, but I would like your thoughts on whether
> this might be useful for scikit-image. Some of the plugins of
> CollectionViewer can be rewritten for this matplotlib based approach in a
> much more readable fashion -- for instance, the line profile plugin.
>
> Best,
>
> --
> Kesavan Subburam
>
--
Kesavan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20170519/978060cb/attachment.html>
More information about the scikit-image
mailing list