Exemple #1
0
def checkAnotatedLabels(argv):
    # Number of input arguments
    #    1: Folder containing label images
    #    2: Folder to save corrected label images
    #    3: Number of expected classes (including background)
    #    4: Image type
    #             0: nifti format
    #             1: matlab format  
    # Do some sanity checks
    
    if len(argv) < 4:
        printUsage(1)
        sys.exit()
    
    imagesFolder = argv[0]
    imagesFolderdst  = argv[1]
    numClasses = int(argv[2])
    imageType = int(argv[3])
    print imagesFolder
    imageNames = getImageImageList(imagesFolder)
    print imageNames
    printFileNames = False
    
    for i_d in xrange(0, len(imageNames)) :
        if imageType == 0:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            [imageData,img_proxy] = load_nii(imageFileName, printFileNames)
        else:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            imageData = load_matlab(imageFileName, printFileNames)

        labelsOrig = np.unique(imageData)

        if (len(labelsOrig) != numClasses):
            print(" WARNING!!!!! Number of expected clases ({}) is different to found labels ({}) ".format(numClasses,len(labelsOrig)))

        # Correct labels
        labelCorrectedImage = np.zeros(imageData.shape,dtype=np.int8)
        for i_l in xrange(0,len(labelsOrig)):
            idx = np.where(imageData == labelsOrig[i_l])
            labelCorrectedImage[idx] = i_l

        
        print(" ... Saving labels...")
        nameToSave =  imagesFolderdst + '/' + imageNames[i_d]
        if imageType == 0: # nifti
            imageTypeToSave = np.dtype(np.int8)
            saveImageAsNifti(labelCorrectedImage,
                             nameToSave,
                             imageFileName,
                             imageTypeToSave)
        else: # Matlab
            # Cast to int8 for saving purposes
            saveImageAsMatlab(labelCorrectedImage.astype('int8'),nameToSave)

            
    print " ******************************************  PROCESSING LABELS DONE  ******************************************"
def checkAnotatedLabels(argv):
    # Number of input arguments
    #    1: Folder containing label images
    #    2: Folder to save corrected label images
    #    3: Number of expected classes (including background)
    #    4: Image type
    #             0: nifti format
    #             1: matlab format  
    # Do some sanity checks
    
    if len(argv) < 4:
        printUsage(1)
        sys.exit()
    
    imagesFolder = argv[0]
    imagesFolderdst  = argv[1]
    numClasses = int(argv[2])
    imageType = int(argv[3])
    
    imageNames = getImageImageList(imagesFolder)
    printFileNames = False
    
    for i_d in xrange(0, len(imageNames)) :
        if imageType == 0:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            [imageData,img_proxy] = load_nii(imageFileName, printFileNames)
        else:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            imageData = load_matlab(imageFileName, printFileNames)

        labelsOrig = np.unique(imageData)

        if (len(labelsOrig) != numClasses):
            print(" WARNING!!!!! Number of expected clases ({}) is different to found labels ({}) ".format(numClasses,len(labelsOrig)))

        # Correct labels
        labelCorrectedImage = np.zeros(imageData.shape,dtype=np.int8)
        for i_l in xrange(0,len(labelsOrig)):
            idx = np.where(imageData == labelsOrig[i_l])
            labelCorrectedImage[idx] = i_l

        
        print(" ... Saving labels...")
        nameToSave =  imagesFolderdst + '/' + imageNames[i_d]
        if imageType == 0: # nifti
            imageTypeToSave = np.dtype(np.int8)
            saveImageAsNifti(labelCorrectedImage,
                             nameToSave,
                             imageFileName,
                             imageTypeToSave)
        else: # Matlab
            # Cast to int8 for saving purposes
            saveImageAsMatlab(labelCorrectedImage.astype('int8'),nameToSave)

            
    print " ******************************************  PROCESSING LABELS DONE  ******************************************"
def checkAnotatedLabels(argv):
    # Number of input arguments
    #    1: Folder containing label images
    #    2: Folder to save corrected label images
    #    3: Image type
    #             0: nifti format
    #             1: matlab format  
    # Do some sanity checks
    
    if len(argv) < 3:
        printUsage(1)
        sys.exit()
    
    imagesFolder = argv[0]
    imagesFolderdst  = argv[1]
    imageType = int(argv[2])
    
    imageNames = getImageImageList(imagesFolder)
    printFileNames = False
    
    for i_d in xrange(len(imageNames)) :
        if imageType == 0:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            [imageData,img_proxy] = load_nii(imageFileName, printFileNames)
        else:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            imageData = load_matlab(imageFileName, printFileNames)

        # Find voxels different to 0
        # NOTE: I assume voxels equal to 0 are outside my ROI (like in the skull stripped datasets)
        idx = np.where(imageData > 0 )

        # Create ROI and assign those indexes to 1
        roiImage = np.zeros(imageData.shape,dtype=np.int8)
        roiImage[idx] = 1
        
        print(" ... Saving roi...")
        nameToSave =  imagesFolderdst + '/ROI_' + imageNames[i_d]
        if imageType == 0: # nifti
            imageTypeToSave = np.dtype(np.int8)
            saveImageAsNifti(roiImage,
                             nameToSave,
                             imageFileName,
                             imageTypeToSave)
        else: # Matlab
            # Cast to int8 for saving purposes
            saveImageAsMatlab(labelCorrectedImage.astype('int8'),nameToSave)

            
    print " ******************************************  PROCESSING LABELS DONE  ******************************************"
def checkAnotatedLabels(argv):
    # Number of input arguments
    #    1: Folder containing label images
    #    2: Folder to save corrected label images
    #    3: Image type
    #             0: nifti format
    #             1: matlab format
    # Do some sanity checks

    if len(argv) < 3:
        printUsage(1)
        sys.exit()

    imagesFolder = argv[0]
    imagesFolderdst = argv[1]
    imageType = int(argv[2])

    imageNames = getImageImageList(imagesFolder)
    printFileNames = False

    for i_d in xrange(len(imageNames)):
        if imageType == 0:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            [imageData, img_proxy] = load_nii(imageFileName, printFileNames)
        else:
            imageFileName = imagesFolder + '/' + imageNames[i_d]
            print imageFileName
            imageData = load_matlab(imageFileName, printFileNames)

        # Find voxels different to 0
        # NOTE: I assume voxels equal to 0 are outside my ROI (like in the skull stripped datasets)
        idx = np.where(imageData > 0)

        # Create ROI and assign those indexes to 1
        roiImage = np.zeros(imageData.shape, dtype=np.int8)
        roiImage[idx] = 1

        print(" ... Saving roi...")
        nameToSave = imagesFolderdst + '/ROI_' + imageNames[i_d]
        if imageType == 0:  # nifti
            imageTypeToSave = np.dtype(np.int8)
            saveImageAsNifti(roiImage, nameToSave, imageFileName,
                             imageTypeToSave)
        else:  # Matlab
            # Cast to int8 for saving purposes
            saveImageAsMatlab(roiImage.astype('int8'), nameToSave)

    print " ******************************************  PROCESSING LABELS DONE  ******************************************"