如何使用cv2处理numpy数组(img1)?

时间:2018-05-18 13:42:29

标签: numpy opencv

如何使用cv2处理img1(numpy数组)?我尝试用CreateMat转换它。但是cv2不支持CreateMat。

    # Load dimensions based on the number of rows, columns, and slices (along 
    the Z axis)
    ConstPixelDims = (int(RefDs.Rows), int(RefDs.Columns), len(lstFilesDCM))

    # Load spacing values (in mm)
    ConstPixelSpacing = (float(RefDs.PixelSpacing[0]), 
    float(RefDs.PixelSpacing[1]), float(RefDs.SliceThickness))

    x = np.arange(0.0, (ConstPixelDims[0]+1)*ConstPixelSpacing[0], 
    ConstPixelSpacing[0])
    y = np.arange(0.0, (ConstPixelDims[1]+1)*ConstPixelSpacing[1], 
    ConstPixelSpacing[1])
    z = np.arange(0.0, (ConstPixelDims[2]+1)*ConstPixelSpacing[2], 
    ConstPixelSpacing[2])

    # The array is sized based on 'ConstPixelDims'
    ArrayDicom = np.zeros(ConstPixelDims, 
    dtype=RefDs.pixel_array.dtype,np.float32)

    # loop through all the DICOM files
    for filenameDCM in lstFilesDCM:
    # read the file
    ds = dicom.read_file(filenameDCM)
    # store the raw image data
    ArrayDicom[:, :, lstFilesDCM.index(filenameDCM)] = ds.pixel_array

    #numpy array for the 11th image in the directory
    img1 = ArrayDicom[:, :, 10]

有什么方法可以转换img1吗?

0 个答案:

没有答案