コード例 #1
0
def read(read_string):
    ext = os.path.splitext(read_string)[1]
    m_string = read_string
    if (ext == ".nii" or ext == ".nrrd"):

        Inner_volume = sitk.ReadImage(m_string)
    else:
        Inner_volume = RIM.dicom_series_reader(m_string)

    return Inner_volume
コード例 #2
0
    # input_matrix[np.where((input_matrix == [255.0]))] = [1.0]
    img = (img - min(img)) / (max(img) - min(img))
    img = img * 65535
    return img


##########################################################################################################################

# read the original volume
ext = os.path.splitext(args.args0)[1]
m_string = args.args0
if (ext == ".nii" or ext == ".nrrd"):

    input_volume = sitk.ReadImage(m_string)
else:
    input_volume = RIM.dicom_series_reader(m_string)

# spacing=input_volume.GetSpacing()
spacing = [0.12, 0.12, 0.12]
origin = input_volume.GetOrigin()
try:
    myvolume = sitk.GetArrayFromImage(input_volume)
except:
    myvolume = itk.GetArrayFromImage(input_volume)
w1 = myvolume.shape[2]
h1 = myvolume.shape[1]
d1 = myvolume.shape[0]
# The_Normal,p1,p2,p3=call_normal_computation.main_normal(myvolume,spacing)
# The_Normal=[round(The_Normal[0]),round(The_Normal[1]),round(The_Normal[2])]
# print(The_Normal)
# The_Normal=[0,0,-1]
コード例 #3
0
#
#     original_volume=sitk.ReadImage(m_string3)
#     original_array=sitk.GetArrayFromImage(original_volume)
# else:
#     original_volume=RIM.dicom_series_reader(m_string3)
#     original_array=itk.GetArrayFromImage(original_volume)
# # intact_volume=RIM.dicom_series_reader(str(unicode('\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Calgary\TBone-2015\TBoneCBCT-2015-10\L2963L','utf-8')))
########################################################################################
ext = os.path.splitext(str((args.args0)))[1]
m_string3 = str((args.args0))
if (ext == ".nii" or ext == ".nrrd" or ext == ".nhdr"):

    intact_volume = sitk.ReadImage(m_string3)
    intact_array = sitk.GetArrayFromImage(intact_volume)
else:
    intact_volume = RIM.dicom_series_reader(m_string3)
    intact_array = itk.GetArrayFromImage(intact_volume)
# intact_volume=RIM.dicom_series_reader(str(unicode('\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Calgary\TBone-2015\TBoneCBCT-2015-10\L2963L','utf-8')))

intact_array_original = intact_array
##########################################################################
data = intact_array
# xmin2,xmax2,ymin2,ymax2,zmin2,zmax2=bbox2_3D(original_array)
xmin, xmax, ymin, ymax, zmin, zmax = bbox2_3D(data)
aa = xmax - xmin
bb = ymax - ymin
cc = zmax - zmin

# aa2=xmax2-xmin2
# bb2=ymax2-ymin2
# cc2=zmax2-zmin2
コード例 #4
0
    input('Press Enter to quit: ')
###############################################################################################################################



##########################################################################################################################


# read the original volume
ext=os.path.splitext(args.args0)[1]
m_string=args.args0
if (ext==".nii" or ext==".nrrd"):

    input_volume=sitk.ReadImage(m_string)
else:
    input_volume=RIM.dicom_series_reader(m_string)

spacing=input_volume.GetSpacing()
origin=input_volume.GetOrigin()
try:
    myvolume=sitk.GetArrayFromImage(input_volume)
except:
    myvolume=itk.GetArrayFromImage(input_volume)

w1 = myvolume.shape[2]
h1 = myvolume.shape[1]
d1 = myvolume.shape[0]
The_Normal,p1,p2,p3=main_normal(myvolume,spacing,verts2,faces2)
del(myvolume)
#############################################################
コード例 #5
0
def execute(txt_Wedge,txt_Wline,txt_Wterm,txt_alpha,txt_beta,txt_sigma,txt_gamma,txt_start,txt_end,txt_url,txt_start2,txt_end2,flagg,txt_flagDown,txt_Wurl):
    m_string=txt_url
    # m_string='U:\Documents\medical_imaging\Hip'
    input_volume=RIM.dicom_series_reader(m_string)

    # input_volume=im
    #
    PixelType = itk.ctype('signed short')
    Dimension = 3
    ImageType_threshold = itk.Image[PixelType, Dimension]
    # thresholdFilter= itk.BinaryThresholdImageFilter[ImageType_threshold,ImageType_threshold].New()
    thresholdFilter= itk.IntensityWindowingImageFilter[ImageType_threshold,ImageType_threshold].New()
    # thresholdFilter= itk.InvertIntensityImageFilter[ImageType_threshold,ImageType_threshold].New()
    thresholdFilter.SetInput(input_volume)

    # thresholdFilter.SetLowerThreshold(-400)
    # thresholdFilter.SetUpperThreshold(40)
    # thresholdFilter.SetOutsideValue(0)
    # thresholdFilter.SetInsideValue(255)
    ##################################
    thresholdFilter.SetInput(input_volume)
    thresholdFilter.SetWindowMinimum(-500)
    thresholdFilter.SetWindowMaximum(1)
    thresholdFilter.SetOutputMinimum(0)
    thresholdFilter.SetOutputMaximum(255)
    ######################################
    # thresholdFilter.SetMaximum(10)
    #################################
    thresholdFilter.Update()
    threshold_input=thresholdFilter.GetOutput()

    sigma_smooth = float(txt_sigma)
    smooth_volume=SFM.smooth_3d(input_volume,sigma_smooth)
    w = input_volume.GetLargestPossibleRegion().GetSize()[0]
    h = input_volume.GetLargestPossibleRegion().GetSize()[1]
    d = input_volume.GetLargestPossibleRegion().GetSize()[2]




    input_matrix=np.zeros((w,h,d))
    input_matrix_smoothed=np.zeros((w,h,d))


    index=np.zeros((3))

    input_matrix_smoothed=itk.GetArrayFromImage(smooth_volume)
    # input_matrix_smoothed=np.transpose(input_matrix_smoothed,axes=(2,1,0))
    # input_matrix = itk.GetArrayFromImage(SFM.smooth_3d(thresholdFilter.GetOutput(),sigma_smooth))
    input_matrix = itk.GetArrayFromImage(input_volume)
    # input_matrix = itk.GetArrayFromImage(thresholdFilter.GetOutput())
    # input_matrix=np.transpose(input_matrix,axes=(2,1,0))

    input_matrix2=input_matrix
    input_matrix_smoothed2=input_matrix_smoothed
    # P=RPM.read_points()
    #P,zslice=MIM.mouse_input()
    zslice=txt_start
    zslice2=txt_start2
    d1=txt_end
    d2=txt_end2
    # zslice=498
    # d=829
    # X=[]
    # Y=[]
    # P=[]
    if (flagg==0):
        P=ICP.main((input_matrix[:][:][zslice]))

        P2=ICP.main((input_matrix2[:][:][zslice2]))
        npoints=P[0].__len__()

        ############################
        # output_volume = input_matrix
        output_volume=np.zeros((d,h,w))
        output_volume1=np.zeros((d,h,w))
        output_volume2=np.zeros((d,h,w))
        ##############################
        tck,u= interpolate.splprep( [P[0],P[1]] ,s = 0 )

        xnew,ynew = interpolate.splev( np.linspace( 0, 1, P[0].__len__() ), tck,der = 0)

        P=[xnew[:],ynew[:]]

        ##################################################
        tck2,u2= interpolate.splprep( [P2[0],P2[1]] ,s = 0 )

        xnew2,ynew2 = interpolate.splev( np.linspace( 0, 1, P2[0].__len__() ), tck2,der = 0)

        P2=[xnew2[:],ynew2[:]]

        #############################
        output_volume1=func.function_abstract(P,input_matrix,input_matrix_smoothed,zslice,d1,output_volume1,1,txt_Wedge,txt_Wline,txt_Wterm,txt_alpha,txt_beta,txt_gamma,txt_flagDown)
        output_volume2=func.function_abstract(P2,input_matrix2,input_matrix_smoothed2,zslice2,d2,output_volume2,1,txt_Wedge,txt_Wline,txt_Wterm,txt_alpha,txt_beta,txt_gamma,txt_flagDown)
        output_volume=output_volume1+output_volume2
        # output_volume=output_volume1
        ####################################################################
        output_volume=sitk.GetImageFromArray(output_volume)
        output_volume=sitk.Cast(output_volume,sitk.sitkFloat64)

        # #output_volume = sitk.Cast(output_volume, sitk.sitkInt64)
        sitk.WriteImage(output_volume,txt_Wurl)

    if(flagg==1):
        P=ICP.main((input_matrix[:][:][zslice]))

        # P2=ICP.main((input_matrix2[:][:][zslice2]))
        npoints=P[0].__len__()

        ############################
        # output_volume = input_matrix
        output_volume=np.zeros((d,h,w))
        output_volume1=np.zeros((d,h,w))
        output_volume2=np.zeros((d,h,w))
        ##############################
        tck,u= interpolate.splprep( [P[0],P[1]] ,s = 0 )

        xnew,ynew = interpolate.splev( np.linspace( 0, 1, P[0].__len__() ), tck,der = 0)

        P=[xnew[:],ynew[:]]

        ##################################################
        # tck2,u2= interpolate.splprep( [P2[0],P2[1]] ,s = 0 )
        #
        # xnew2,ynew2 = interpolate.splev( np.linspace( 0, 1, P2[0].__len__() ), tck2,der = 0)
        #
        # P2=[xnew2[:],ynew2[:]]

        #############################
        output_volume1=func.function_abstract(P,input_matrix,input_matrix_smoothed,zslice,d1,output_volume1,1,txt_Wedge,txt_Wline,txt_Wterm,txt_alpha,txt_beta,txt_gamma,txt_flagDown)
        # output_volume2=func.function_abstract(P2,input_matrix2,input_matrix_smoothed2,zslice2,d2,output_volume2,1)
        # output_volume=output_volume1+output_volume2
        output_volume=output_volume1
        ####################################################################
        output_volume=sitk.GetImageFromArray(output_volume)
        output_volume=sitk.Cast(output_volume,sitk.sitkFloat64)

        # #output_volume = sitk.Cast(output_volume, sitk.sitkInt64)
        sitk.WriteImage(output_volume,txt_Wurl)
コード例 #6
0
################################################Reading Dissected Volume##########################################################################

########################################################################################################################################
def finish():
    print('\n', "bye", '\n')
    input('Press Enter to quit: ')
################################################Reading Dissected Volume##########################################################################

# read the original volume
ext=os.path.splitext(args.args2)[1]
m_string=args.args2
if (ext==".nii" or ext==".nrrd"):

    input_volume=sitk.ReadImage(m_string)
else:
    input_volume=RIM.dicom_series_reader(m_string)



spacing=input_volume.GetSpacing()
origin=input_volume.GetOrigin()
try:
    dissected_matrix=sitk.GetArrayFromImage(input_volume)
except:
    dissected_matrix=itk.GetArrayFromImage(input_volume)
w1 = dissected_matrix.shape[2]
h1 = dissected_matrix.shape[1]
d1 = dissected_matrix.shape[0]


#############################Reading Intact Volume################################
コード例 #7
0
def main(args0, args1, args2, args3):
    parser = argparse.ArgumentParser(
        description=
        """This program uses ray casting method to detect overhang problem""")
    parser.add_argument(
        "-args0",
        type=str,
        default=
        (("\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Kowther\Specimen2501L\Specimen2501L\Segmentations\FacialNerve.nrrd"
          )),
        help="facial nerve")
    # parser.add_argument("-args0", type = str, default = "U:\Documents\Data_Sets\Calgary\TBone-2015\TBoneCBCT-2015-10\L3016_modified_19_nov", help = "dicome image address")
    parser.add_argument(
        "-args1",
        type=str,
        default=
        ("\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Kowther\Specimen2501L\Specimen2501L\Segmentations\SigmoidSinus.nrrd"
         ),
        help="address of sigmoid sinus mask")
    parser.add_argument(
        "-args2",
        type=str,
        default=
        (('\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Kowther\Specimen2501L\dissected_27_feb_2019'
          )),
        help="dissected image address")
    parser.add_argument(
        "-args3",
        type=str,
        default=
        ('\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Kowther\Specimen2501L\Specimen2501L\\2501L_reduced'
         ),
        help="intact image address")
    parser.add_argument("-args4", type=int, default=1000, help="low")
    parser.add_argument("-args5", type=int, default=4000, help="high")

    # Get your arguments
    args = parser.parse_args()
    args.args0 = args0
    args.args1 = args1
    args.args2 = args2
    args.args3 = args3
    low = args.args4
    high = args.args5

    ################################################Reading Dissected Volume##########################################################################

    # read the original volume
    ext = os.path.splitext(args.args2)[1]
    m_string = args.args2
    if (ext == ".nii" or ext == ".nrrd"):

        input_volume = sitk.ReadImage(m_string)
    else:
        input_volume = RIM.dicom_series_reader(m_string)

    spacing = input_volume.GetSpacing()
    origin = input_volume.GetOrigin()
    try:
        dissected_matrix = sitk.GetArrayFromImage(input_volume)
    except:
        dissected_matrix = itk.GetArrayFromImage(input_volume)
    w1 = dissected_matrix.shape[2]
    h1 = dissected_matrix.shape[1]
    d1 = dissected_matrix.shape[0]

    #############################Reading Intact Volume################################

    ext = os.path.splitext(str((args.args3)))[1]
    m_string3 = str((args.args3))
    if (ext == ".nii" or ext == ".nrrd" or ext == ".nhdr"):

        intact_volume = sitk.ReadImage(m_string3)
        intact_array = sitk.GetArrayFromImage(intact_volume)
    else:
        intact_volume = RIM.dicom_series_reader(m_string3)
        intact_array = itk.GetArrayFromImage(intact_volume)
    # intact_volume=RIM.dicom_series_reader(str(unicode('\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Calgary\TBone-2015\TBoneCBCT-2015-10\L2963L','utf-8')))

    #######################################################################################################
    #

    #do binary threshoulding on the original image

    PixelType = itk.ctype('signed short')
    Dimension = 3
    try:
        thresholdFilter = sitk.BinaryThresholdImageFilter()
        input_volume_thr = thresholdFilter.Execute(input_volume, low, high,
                                                   255, 0)
    except:
        print(0)
    try:
        ImageType_threshold = itk.Image[PixelType, Dimension]
        thresholdFilter = itk.BinaryThresholdImageFilter[
            ImageType_threshold, ImageType_threshold].New()
        # input_volume=thresholdFilter.Execute(input_volume,low,high,0,255)
        thresholdFilter.SetInput((input_volume))

        thresholdFilter.SetLowerThreshold(low)
        thresholdFilter.SetUpperThreshold(high)
        thresholdFilter.SetOutsideValue(0)
        thresholdFilter.SetInsideValue(255)
        thresholdFilter.Update()
        input_volume_thr = thresholdFilter.GetOutput()

    except:
        print(0)

    #####################################################

    #do binary threshoulding on the intact image
    try:
        thresholdFilter = sitk.BinaryThresholdImageFilter()
        intact_volume2_thr = thresholdFilter.Execute(intact_volume, low, high,
                                                     255, 0)
    except:
        print(0)
    #
    try:
        PixelType = itk.ctype('signed short')
        Dimension = 3
        ImageType_threshold = itk.Image[PixelType, Dimension]
        thresholdFilter = itk.BinaryThresholdImageFilter[
            ImageType_threshold, ImageType_threshold].New()
        thresholdFilter.SetInput(intact_volume)

        thresholdFilter.SetLowerThreshold(low)
        thresholdFilter.SetUpperThreshold(high)
        thresholdFilter.SetOutsideValue(0)
        thresholdFilter.SetInsideValue(255)
        thresholdFilter.Update()
        intact_volume2_thr = thresholdFilter.GetOutput()
    #
    except:
        print(0)
    #intact_array=itk.GetArrayFromImage(intact_volume2)
    try:
        intact_array_thr = sitk.GetArrayFromImage(intact_volume2_thr)
    except:
        print(0)
    try:
        intact_array_thr = itk.GetArrayFromImage(intact_volume2_thr)
    except:
        print(0)

    #####################################################
    try:
        dissected_array_thr = sitk.GetArrayFromImage(input_volume_thr)
    except:
        print(0)
    try:
        dissected_array_thr = itk.GetArrayFromImage(input_volume_thr)
    except:
        print(0)

    #######################################################################################################

    # read nrrd or segmented volume of sigmoid sinus to be used as mask
    ext = os.path.splitext(args.args1)[1]
    m_string2 = args.args1
    if (ext == ".nii" or ext == ".nrrd"):

        sigmoid_volume = sitk.ReadImage(m_string2)
    else:
        sigmoid_volume = RIM.dicom_series_reader(m_string2)
    # nrrd_volume=sitk.ReadImage(m_string2)

    spacing = sigmoid_volume.GetSpacing()
    sigmoid_volume = sitk.GetArrayFromImage(sigmoid_volume)
    sigmoid_volume = np.ndarray.transpose(np.ndarray.transpose(sigmoid_volume))

    # read facialnerve
    ext = os.path.splitext(args.args0)[1]
    m_string = args.args0
    if (ext == ".nii" or ext == ".nrrd"):

        facial_volume = sitk.ReadImage(m_string)
    else:
        facial_volume = RIM.dicom_series_reader(m_string)

    facial_volume = sitk.GetArrayFromImage(facial_volume)
    facial_volume = np.ndarray.transpose(np.ndarray.transpose(facial_volume))

    ##########################chebyshev distance###########################
    # allDist = squareform( pdist2( set1, set2 ) );
    # [minDist nni] = min( allDist, [], 2 );
    ###########python version#################

    #
    # X = sigmoid_volume
    # Y = facial_volume
    #
    # allDist=cdist(X, Y)
    # distancee=min(allDist)
    mesh = sigmoid_volume
    pts = facial_volume
    # squared_distances,face_indices,closest_point=pymesh.distance_to_mesh(mesh, pts, engine='auto')
    # print(squared_distances)
    # print(face_indices)
    # print(closest_point)
    #######################################################################

    # quality=computeQualityMeasures(facial_volume,sigmoid_volume)
    # print(quality)
    a = np.ones((3, 3, 3))
    for i in range(10, 50):
        b = morph.binary_dilation(sigmoid_volume, a, i)
        c = morph.binary_dilation(facial_volume, a, i)
        d = np.logical_and(b, c)
        d[np.where((d == [True]))] = [1.0]
        if np.sum(d) > 10000:
            print(np.sum(d))

            print(i)
            break
    print(np.where((d == [1.0])))

    sum_image = b + c
    #############visualizing the extended sigmoid sinus and facial nerve
    verts, faces, normals, values = marching_cubes_lewiner(
        sum_image, 0, spacing)
    # mesh=mlab.triangular_mesh([vert[0] for vert in verts],
    #                              [vert[1] for vert in verts],
    #                              [vert[2] for vert in verts],
    #                              faces)
    # fig = mlab.figure(1)
    # mlab.show()
    #################calculate the bounding box of the intersection point
    d[np.where((d == [True]))] = [1.0]
    rmin3, rmax3, cmin3, cmax3, zmin3, zmax3 = bbox2_3D(d)
    original_sum = sigmoid_volume + facial_volume
    original_sum[np.where((original_sum == [True]))] = [1.0]
    ##################extracting region of interest
    segmented_area = dissected_array_thr[rmin3:rmax3, cmin3:cmax3, zmin3:zmax3]
    print(segmented_area.shape)
    verts, faces, normals, values = marching_cubes_lewiner(
        segmented_area, 0, spacing)
    # mesh=mlab.triangular_mesh([vert[0] for vert in verts],
    #                              [vert[1] for vert in verts],
    #                              [vert[2] for vert in verts],
    #                              faces)
    # mlab.title("part of dissected")
    # fig = mlab.figure("part of dissected")

    segmented_area = intact_array_thr[rmin3:rmax3, cmin3:cmax3, zmin3:zmax3]
    print(segmented_area.shape)
    verts, faces, normals, values = marching_cubes_lewiner(
        segmented_area, 0, spacing)
    # mesh=mlab.triangular_mesh([vert[0] for vert in verts],
    #                              [vert[1] for vert in verts],
    #                              [vert[2] for vert in verts],
    #                             faces)
    # mlab.title("part of intact")
    # fig = mlab.figure("part of intact")

    segmented_area = dissected_array_thr[rmin3:rmax3, cmin3:cmax3, zmin3:zmax3]
    print(segmented_area.shape)
    verts, faces, normals, values = marching_cubes_lewiner(
        dissected_array_thr, 0, spacing)
    # mesh=mlab.triangular_mesh([vert[0] for vert in verts],
    #                              [vert[1] for vert in verts],
    #                              [vert[2] for vert in verts],
    #                             faces)
    # mlab.title('complete image')
    # fig=mlab.figure('complete image')
    # mlab.show()

    ##############################results####################################
    subtracted_array = intact_array_thr - dissected_array_thr

    subtracted_region = subtracted_array[rmin3:rmax3, cmin3:cmax3, zmin3:zmax3]
    num1 = np.sum(subtracted_region)
    print(num1)
    if (num1 > 0):
        print("digastric ridge is identified")
    else:
        print("digastric ridge is not identified")

    print("rmin")
    print(rmin3)
    print("rmax")
    print(rmax3)
    print("cmin")
    print(cmin3)
    print("cmax")
    print(cmax3)
    print("zmin")
    print(zmin3)
    print("zmax")
    print(zmax3)

    return rmin3, rmax3, cmin3, cmax3, zmin3, zmax3
コード例 #8
0
def main(read_string):
    ext = os.path.splitext(str((read_string)))[1]
    m_string3 = str((read_string))
    if (ext == ".nii" or ext == ".nrrd" or ext == ".nhdr"):

        intact_volume = sitk.ReadImage(m_string3)
        intact_array = sitk.GetArrayFromImage(intact_volume)
    else:
        intact_volume = RIM.dicom_series_reader(m_string3)
        intact_array = itk.GetArrayFromImage(intact_volume)
    # intact_volume=RIM.dicom_series_reader(str(unicode('\\\\samba.cs.ucalgary.ca\\fatemeh.yazdanbakhsh\Documents\Data_Sets\Calgary\TBone-2015\TBoneCBCT-2015-10\L2963L','utf-8')))

    intact_array_original = intact_array
    ##########################################################################
    data = intact_array
    # xmin2,xmax2,ymin2,ymax2,zmin2,zmax2=bbox2_3D(original_array)
    xmin, xmax, ymin, ymax, zmin, zmax = bbox2_3D(data)
    aa = xmax - xmin
    bb = ymax - ymin
    cc = zmax - zmin

    # aa2=xmax2-xmin2
    # bb2=ymax2-ymin2
    # cc2=zmax2-zmin2
    # scale=(aa2*bb2*cc2)/(aa*bb*cc)
    scale = int(
        (intact_array.shape[0] * intact_array.shape[1] * intact_array.shape[2])
        / (aa * bb * cc))
    data[np.where(data == 255)] = 1

    data = np.where(data == 1.0)
    #
    from sklearn.cluster import KMeans

    if data[0].__len__() > 20:
        # if data[0].__len__()/scale<1:
        #     nn=np.ceil(data[0].__len__()/scale)*2
        # else:
        nn = np.ceil(data[0].__len__() / 30)

        if nn < 1:
            nn = 1
        if scale > 400:
            nn = np.ceil(data[0].__len__() / 40)
        if scale <= 15:
            # nn=300

            nn = np.ceil(data[0].__len__() / scale)
            # nn=np.ceil(data[0].__len__()/30)*2.3
            if nn > 300:
                nn = 300

        # if scale<=10:
        #     nn=np.ceil(data[0].__len__()/scale)*0.2
        #     if nn>300:
        #         nn=300

        if scale <= 8:
            # nn=500/scale
            # nn=np.ceil(data[0].__len__()/30)*3
            nn = np.ceil(
                math.ceil((data[0].__len__() / math.floor(scale))) / 2)
            if nn > 350:
                nn = 350
        if scale <= 2:
            nn = np.ceil(data[0].__len__() / 30) * 4
            # nn=500
            if nn > 500:
                nn = 500
            # nn=data[0].__len__()/20
        print("number of clusters")
        print(nn)
        # nn=math.ceil(data[0].__len__())/20
        cluster = KMeans(n_clusters=int(nn), algorithm='full',
                         max_iter=500).fit(np.asarray(data).transpose())
        c2 = 0
        for i in (np.unique(cluster.labels_)):
            jjj.append((np.where(cluster.labels_ == i))[0].size)
            print(jjj)
        print("number of clusters")
        print(nn)
        print("max")
        print(np.asarray(jjj).max())
        for i in range(jjj.__len__()):
            k = jjj.pop()
            if k > 48:
                print(k)
                print("overhang has happend in label")
                print(i)
                c2 = c2 + 1

        cluster = KMeans(n_clusters=int(nn), algorithm='full',
                         max_iter=500).fit(np.asarray(data).transpose())
        c1 = 0
        for i in (np.unique(cluster.labels_)):
            jjj.append((np.where(cluster.labels_ == i))[0].size)
            print(jjj)

        print("number of clusters")
        print(nn)
        print("max")
        print(np.asarray(jjj).max())
        for i in range(jjj.__len__()):
            k = jjj.pop()
            if k > 48:
                print(k)
                print("overhang has happend in label")
                print(i)
                c1 = c1 + 1

        if c1 > 0 and c2 > 0:
            print("overhang has happend")
            res = 0
            np.max
            percent = 1 - (np.max((c1, c2)) / nn)
        else:
            print("No Overhang")
            res = 1
            percent = 0

    else:
        print("over hang has not happend")
        percent = 1
        res = 1
    print('scale')
    print(scale)
    print('percent')
    print(percent)
    return res
コード例 #9
0
# Get your arguments
args = parser.parse_args()

low = args.args4
high = args.args5

################################################Reading Dissected Volume##########################################################################

# read the original volume
ext = os.path.splitext(args.args2)[1]
m_string = args.args2
if (ext == ".nii" or ext == ".nrrd"):

    input_volume = sitk.ReadImage(m_string)
else:
    input_volume = RIM.dicom_series_reader(m_string)

spacing = input_volume.GetSpacing()
origin = input_volume.GetOrigin()
try:
    dissected_matrix = sitk.GetArrayFromImage(input_volume)
except:
    dissected_matrix = itk.GetArrayFromImage(input_volume)
w1 = dissected_matrix.shape[2]
h1 = dissected_matrix.shape[1]
d1 = dissected_matrix.shape[0]

#############################Reading Intact Volume################################

ext = os.path.splitext(str((args.args3)))[1]
m_string3 = str((args.args3))