예제 #1
0
def test_coreFunction_small():
    """
    Testing FarsighOPConv.app.coreFunction with a short runtime case
    """

    testLabelFile = os.path.join(
        "tests", "files", "Act5C_no5_med1_C428_dec1_label_20LabelSubset.tif")
    testSeedsFile = os.path.join(
        "tests", "files",
        "Act5C_no5_med1_C428_dec1_seedPoints_20LabelSubset.txt")

    expOutLabelFile = os.path.join(
        "tests", "files",
        "Act5C_no5_med1_C428_dec1_label_20LabelSubset_corrected32Bit_exp.tiff")
    expOutXLFile = os.path.join(
        "tests", "files",
        "Act5C_no5_med1_C428_dec1_label_20LabelSubset_corrected32Bit_exp.xlsx")

    print(f"Running tests using\n{testLabelFile} and\n{testSeedsFile}")
    startTime = time.time()
    outLabelFile, outXLFile = farsightOPConvAndMetrics(testLabelFile,
                                                       testSeedsFile)
    endTime = time.time()

    duration = endTime - startTime

    print(f"Execution time of core Function: {duration/60}min")

    assert np.allclose(tifffile.imread(outLabelFile),
                       tifffile.imread(expOutLabelFile))

    assert pd.read_excel(outXLFile).equals(pd.read_excel(expOutXLFile))
예제 #2
0
def test_labelConv32bitTo16bit():
    """
    Testing the function FarsightOPConv.img32bit16bitIO.labelConv32bitTo16bit
    """

    test32BitFile = os.path.join(
        "tests", "files",
        "Act5C_no5_med1_C428_dec1_label_corrected32Bit_13LabelSubset.tif")

    img32bit = tifffile.imread(test32BitFile)

    imgs16Bit, labelMap = labelConv32bitTo16bit(img32bit)

    assert len(imgs16Bit) == 3

    opImgBase = os.path.join("tests", "files", "funcs",
                             "labelConv32bitTo16bit", "outputImg")

    expOPImageFiles = [f"{opImgBase}_{ind:d}_exp.tif" for ind in range(3)]
    expLabelMapXL = os.path.join("tests", "files", "funcs",
                                 "labelConv32bitTo16bit",
                                 "outputLabelMap_exp.xlsx")
    expLabelMapDF = pd.read_excel(expLabelMapXL)

    assert expLabelMapDF.equals(labelMap.astype(np.int64))

    for expOPImageFile, opImg in zip(expOPImageFiles, imgs16Bit):

        expOPImage = tifffile.imread(expOPImageFile)
        assert np.allclose(expOPImage, opImg)
예제 #3
0
def test_getLabelShapeStats():
    """
    Testing the function FarsightOPConv.sitkFuncs.getLabelShapeStatistics
    """

    testFile = os.path.join(
        "tests", "files",
        "Act5C_no5_med1_C428_dec1_label_20LabelSubset_corrected32Bit_exp.tiff")
    outFile = os.path.join("tests", "files", "funcs", "getLabelShapeStats",
                           "output.xlsx")
    expected_outFile = os.path.join("tests", "files", "funcs",
                                    "getLabelShapeStats",
                                    "expectedOutput.xlsx")

    testImageNP = tifffile.imread(testFile)
    testImageNPUInt16 = testImageNP.astype(np.uint16)

    measureNames, measureValues = getLabelShapeStatistics(testImageNPUInt16)

    outDF = pd.DataFrame(columns=measureNames, data=measureValues)
    outDF.to_excel(outFile)

    expected_outDF = pd.read_excel(expected_outFile)

    arrayCols = ["Centroid", "Principal Moments"]

    expected_outDF[arrayCols] = expected_outDF[arrayCols].applymap(make_tuple)

    assert outDF.equals(expected_outDF)
예제 #4
0
    def __init__(self, outputlabelImageFile:str, outputSeedsTXT: str):
        """
        Initializes the object by reading in output label image and seeds
        :param outputLabelImageFile: string, path of the output label image file generated by farsight
        :param outputSeedsTXT: string, path of the output seed text file generated by farsight
        """

        self.outputlabelImageFile = outputlabelImageFile
        self.outputSeedsTXT = outputSeedsTXT

        self.seeds = np.loadtxt(self.outputSeedsTXT, dtype=int)
        self.labelImage = tifffile.imread(self.outputlabelImageFile)