当前位置: 首页>>代码示例>>Python>>正文


Python Image.data[:,:,:]方法代码示例

本文整理汇总了Python中msct_image.Image.data[:,:,:]方法的典型用法代码示例。如果您正苦于以下问题:Python Image.data[:,:,:]方法的具体用法?Python Image.data[:,:,:]怎么用?Python Image.data[:,:,:]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在msct_image.Image的用法示例。


在下文中一共展示了Image.data[:,:,:]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: vertebral_detection

# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import data[:,:,:] [as 别名]

#.........这里部分代码省略.........
    #     if i_peak>0:
    #         if (Mcorr[i_peak+1]-Mcorr[i_peak])<0.4*np.mean(Mcorr[1:i_peak+2]-Mcorr[0:i_peak+1]):
    #             test = i_peak
    #             template_resize_peak = np.concatenate((template_truncated,np.zeros(round(mean_distance[i_peak])-xmax_pattern-pixend),pattern))
    #             good_scale_peak = np.round(mean_distance[i_peak]) - xmax_pattern - pixend
    #             flag = 1
    #     if i_peak==0:
    #         if (Mcorr[i_peak+1] - Mcorr[i_peak])<0.4*Mcorr[0]:
    #             template_resize_peak = np.concatenate((template_truncated,np.zeros(round(mean_distance[i_peak])-xmax_pattern-pixend),pattern))
    #             good_scale_peak = round(mean_distance[i_peak]) - xmax_pattern - pixend
    #             flag = 1
    #     if flag==0:
    #         template_resize_peak=np.concatenate((template_truncated,np.zeros(good_scale_peak),pattern))
    #
    #     #update mean-distance by a adjustement ratio
    #     mean_distance_new[i_peak] = good_scale_peak + xmax_pattern + pixend
    #     mean_ratio[i_peak] = np.mean(mean_distance_new[:,0:i_peak]/mean_distance[:,0:i_peak])
    #
    #     template_truncated = template_resize_peak
    #
    #     if verbose:
    #         plt.plot(I_detrend[:,0])
    #         plt.plot(template_truncated)
    #         plt.xlim(0,(len(I_detrend[:,0])-1))
    #         plt.show()
    #
    # #finding the maxima of the adjusted template
    # minpeakvalue = 0.5
    # loc_disk = np.arange(len(template_truncated))
    # index_disk = []
    # for i in range(len(template_truncated)):
    #     if template_truncated[i]>=minpeakvalue:
    #         if i==0:
    #             if template_truncated[i]<template_truncated[i+1]:
    #                 index_disk.append(i)
    #         elif i==(len(template_truncated)-1):
    #             if template_truncated[i]<template_truncated[i-1]:
    #                 index_disk.append(i)
    #         else:
    #             if template_truncated[i]<template_truncated[i+1]:
    #                 index_disk.append(i)
    #             elif template_truncated[i]<template_truncated[i-1]:
    #                 index_disk.append(i)
    #     else:
    #         index_disk.append(i)
    #
    # mask_disk = np.ones(len(template_truncated), dtype=bool)
    # mask_disk[index_disk] = False
    # loc_disk = loc_disk[mask_disk]
    # X1 = np.where(loc_disk > I_detrend.shape[0])
    # mask_disk1 = np.ones(len(loc_disk), dtype=bool)
    # mask_disk1[X1] = False
    # loc_disk = loc_disk[mask_disk1]
    # loc_disk = loc_disk + start_centerline_y - 1


    #=====================================================================
    # Step 3: Building of the labeled centerline and surface
    #=====================================================================

    # Project vertebral levels back to the centerline
    centerline = Image(fname_centerline)
    raw_orientation = centerline.change_orientation()
    centerline.data[:,:,:] = 0
    for iz in range(locs[0]):
            centerline.data[np.round(x[iz]),np.round(y[iz]),iz]=1
    for i in range(len(locs)-1):
        for iz in range(locs[i],min(locs[i+1],len(z))):
            centerline.data[np.round(x[iz]),np.round(y[iz]),iz]=i+2
    for iz in range(locs[-1],len(z)):
            centerline.data[np.round(x[iz]),np.round(y[iz]),iz]=i+3

    #centerline.change_orientation(raw_orientation)
    centerline.file_name+='_labeled'
    centerline.save()


    # color the segmentation with vertebral number
    if fname_segmentation:
        seg=Image(fname_segmentation)
        seg_raw_orientation = seg.change_orientation()
        x_seg,y_seg,z_seg=np.where(seg.data)
        for ivox in range(len(x_seg)):
            vox_coord = np.array([x_seg[ivox], y_seg[ivox], z_seg[ivox]])
            for iplane in range(len(locs)):
                ind=np.where(z==locs[iplane])
                vox_vector = vox_coord - np.hstack((x[ind],y[ind],z[ind]))
                normal2plane_vector = np.hstack((Tx[ind], Ty[ind], Tz[ind]))

                # if voxel is above the plane --> give the number of the plane
                if np.dot(vox_vector, normal2plane_vector) > 0:
                    seg.data[vox_coord[0], vox_coord[1], vox_coord[2]] = iplane+2

                else: # if the voxel gets below the plane --> next voxel
                    break
        seg.change_orientation(seg_raw_orientation)
        seg.file_name+='_labeled'
        seg.save()

    return locs
开发者ID:,项目名称:,代码行数:104,代码来源:

示例2: create_label_z

# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import data[:,:,:] [as 别名]
def create_label_z(fname_seg, z, value):
    """
    Create a label at coordinates x_center, y_center, z
    :param fname_seg: segmentation
    :param z: int
    :return: fname_label
    """
    fname_label = 'labelz.nii.gz'
    nii = Image(fname_seg)
    orientation_origin = nii.change_orientation('RPI')  # change orientation to RPI
    nx, ny, nz, nt, px, py, pz, pt = nii.dim  # Get dimensions
    # find x and y coordinates of the centerline at z using center of mass
    from scipy.ndimage.measurements import center_of_mass
    x, y = center_of_mass(nii.data[:, :, z])
    x, y = int(round(x)), int(round(y))
    nii.data[:, :, :] = 0
    nii.data[x, y, z] = value
    # dilate label to prevent it from disappearing due to nearestneighbor interpolation
    from sct_maths import dilate
    nii.data = dilate(nii.data, [3])
    nii.setFileName(fname_label)
    nii.change_orientation(orientation_origin)  # put back in original orientation
    nii.save()
    return fname_label
开发者ID:,项目名称:,代码行数:26,代码来源:


注:本文中的msct_image.Image.data[:,:,:]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。