plt.imshow顯示CT/MRI圖像

先看一下plt.imshow

help(plt.imshow)

下面只是顯示此博客關注的關鍵部分,完整的可以自己運行命令查看。

imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, *, data=None, **kwargs)
    Display an image, i.e. data on a 2D regular raster
    Parameters
    ----------
    X : array-like or PIL image
        The image data. Supported array shapes are:
    
        - (M, N): an image with scalar data. The data is visualized
          using a colormap.
        - (M, N, 3): an image with RGB values (float or uint8).
        - (M, N, 4): an image with RGBA values (float or uint8), i.e.
          including transparency.
        The RGB(A) values should be in the range [0 .. 1] for floats or
        [0 .. 255] for integers.  Out-of-range values will be clipped to
        these bounds.
    
    cmap : str or `~matplotlib.colors.Colormap`, optional
        A Colormap instance or registered colormap name. The colormap
        maps scalar data to colors. It is ignored for RGB(A) data.
        Defaults to :rc:`image.cmap`.
    ...
    ...
    ...
    
    Returns
    -------
    image : `~matplotlib.image.AxesImage`

注意,一般顯示醫療影像的時候,我們讀取的是其中的一個切片,所以使用的是M,N(M,N),而千萬不要自作聰明,將M,N(M,N)擴展成M,N,3(4)(M,N,3(4))這種形式。具體原因:

The RGB(A) values should be in the range [0 … 1] for floats or
[0 … 255] for integers. Out-of-range values will be clipped to
these bounds.

會對像素值進行自動裁剪的!!

dicom

plt.imshow(filedata,cmap=plt.cm.bone)

在這裏插入圖片描述
有關cmap=plt.cm.bone,
參考https://matplotlib.org/3.1.0/gallery/color/colormap_reference.html?highlight=bone
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章