天天看點

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) (M,N)擴充成 ( M , N , 3 ( 4 ) ) (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)
           
plt.imshow顯示CT/MRI圖像

有關cmap=plt.cm.bone,

參考https://matplotlib.org/3.1.0/gallery/color/colormap_reference.html?highlight=bone

plt.imshow顯示CT/MRI圖像

繼續閱讀