コード例 #1
0
ファイル: monteCarloHelper.py プロジェクト: 0r/MITK
def runOneSimulation(wavelength, eHbO2, eHb,
                     infile, simulationOutputFolderName, gpumcmlDirectory, gpumcmlExecutable,
                     BVF=0.1, Vs=0.4, d=500 * 10**-6,
                     r=0.4 * 10**-6, SaO2=0.7, cHb=120,
                     submucosa_BVF=0.1, submucosa_Vs=0.3, submucosa_r = 2*10**-6, submucosa_SaO2=0.7,
                     Fwhm = 20 * 10**-9, nrPhotons = 10**6,
                     ):
    """
    Args:
    _____
    cHb:
        concentration of haemoglobin per unit volume of blood in colon [g/L],
        taken from: "Modelling and validation of spectral reflectance for the colon"
    """
    outputFilename = \
            simulationOutputFolderName + \
            "BVF" + repr(BVF) + \
            "Vs" + repr(Vs) + \
            "d" + repr(d) + \
            "SaO2" + repr(SaO2) + \
            "r" + repr(r) + \
            "photons" + repr(nrPhotons) + \
            "wavelength" + repr(wavelength) + \
            ".mco"

    usg = mieMonteCarlo.mieMonteCarlo_FWHM(wavelength, r, Vs, FWHM = Fwhm)

    ua  = calcUa(BVF, cHb, SaO2, eHbO2, eHb, wavelength)
    # calculate ua, us for submucosa, values taken from
    # "Model based inversion for deriving maps of
    # histological parameters characteristic of cancer
    # from ex-vivo multispectral images of the colon"
    ua_sm  = calcUa(submucosa_BVF, cHb, submucosa_SaO2, eHbO2, eHb, wavelength)
    usg_sm = mieMonteCarlo.mieMonteCarlo_FWHM(wavelength,submucosa_r, submucosa_Vs, FWHM = Fwhm)

    # now create us and ua for muscle layer according to
    # "Modelling and validation of spectral reflectance for the colon"
    us_mus = calcUsMuscle(wavelength)
    A      = 1.7923385088285804 # calculated to retrieve an absorption of 11.2 cm-1
    # at 515nm
    ua_mus = calcUa(A*0.1, 120, 0.7, eHbO2, eHb, wavelength)


    # factors are due to the program expecting [cm] instead of [m]
    replacements = {'muc_c_ua':str(ua / 100), 'muc_c_us':str(usg['us'] / 100),
        'muc_c_g':str(usg['g']), 'muc_c_d':str(d * 100),
        'sm_c_ua':str(ua_sm / 100), 'sm_c_us':str(usg_sm['us'] / 100),
        'sm_c_g':str(usg_sm['g']),
        'mus_c_ua':str(ua_mus / 100), 'mus_c_us':str(us_mus / 100),
        'outputFilename':outputFilename,
        'c_ph': str(nrPhotons)}

    createSimulationFile(infile, replacements,
                         systemPaths.getOutputFolder() + "simulationFile.mci")

    args = ("./" + gpumcmlExecutable, "-A", systemPaths.getOutputFolder() + "simulationFile.mci")

    with cd(gpumcmlDirectory):
        popen = subprocess.Popen(args, stdout=subprocess.PIPE)
        popen.wait()

    # outside the context manager we are back wherever we started.



    # this function is error prone, please refer to documentation to see
    # if problematic for you
    return getReflectanceFromFile(gpumcmlDirectory + outputFilename)
コード例 #2
0
        parameterImage_i = np.reshape(result[:,i], shape)
        im = Image.fromarray(parameterImage_i)
        im.save(dataFolder + imageName + "_parameterImage_" + str(i) + ".tiff")


    with open(dataFolder + "result_" + imageName + '.csv', 'wb') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=';',
                                quotechar='|', quoting=csv.QUOTE_MINIMAL)
        spamwriter.writerow([imageName])
        spamwriter.writerow(['r2Score', str(r2Score)])




# the folder with the reflectance spectra
dataFolder  =  systemPaths.getOutputFolder()



##%% Evaluate CC2 Mitte links data
#imageToLoad = "CC2_links"
#
#
###%% get data
#trainingParameters, trainingReflectances, shape, image, trainsegmentation, testsegmentation = \
#    data.realImage(dataFolder, imageToLoad)
#
####%% do evaluation with out domain adaptation
#resName = imageToLoad + "_NODA"
#resultCC2linksNODA, r2ScoreCC2linksNODA, backProjectedReflectancesCC2linksNODA, realReflectanceCC2linksNODA = estimateParametersRealImage(trainingParameters, trainingReflectances, shape, image, trainsegmentation, testsegmentation,  False)
#saveResults(resultCC2linksNODA, shape, r2ScoreCC2linksNODA, dataFolder, resName)
コード例 #3
0
def runOneSimulation(
    wavelength,
    eHbO2,
    eHb,
    infile,
    simulationOutputFolderName,
    gpumcmlDirectory,
    gpumcmlExecutable,
    BVF=0.1,
    Vs=0.4,
    d=500 * 10**-6,
    r=0.4 * 10**-6,
    SaO2=0.7,
    cHb=120,
    submucosa_BVF=0.1,
    submucosa_Vs=0.3,
    submucosa_r=2 * 10**-6,
    submucosa_SaO2=0.7,
    Fwhm=20 * 10**-9,
    nrPhotons=10**6,
):
    """
    Args:
    _____
    cHb:
        concentration of haemoglobin per unit volume of blood in colon [g/L],
        taken from: "Modelling and validation of spectral reflectance for the colon"
    """
    outputFilename = \
            simulationOutputFolderName + \
            "BVF" + repr(BVF) + \
            "Vs" + repr(Vs) + \
            "d" + repr(d) + \
            "SaO2" + repr(SaO2) + \
            "r" + repr(r) + \
            "photons" + repr(nrPhotons) + \
            "wavelength" + repr(wavelength) + \
            ".mco"

    usg = mieMonteCarlo.mieMonteCarlo_FWHM(wavelength, r, Vs, FWHM=Fwhm)

    ua = calcUa(BVF, cHb, SaO2, eHbO2, eHb, wavelength)
    # calculate ua, us for submucosa, values taken from
    # "Model based inversion for deriving maps of
    # histological parameters characteristic of cancer
    # from ex-vivo multispectral images of the colon"
    ua_sm = calcUa(submucosa_BVF, cHb, submucosa_SaO2, eHbO2, eHb, wavelength)
    usg_sm = mieMonteCarlo.mieMonteCarlo_FWHM(wavelength,
                                              submucosa_r,
                                              submucosa_Vs,
                                              FWHM=Fwhm)

    # now create us and ua for muscle layer according to
    # "Modelling and validation of spectral reflectance for the colon"
    us_mus = calcUsMuscle(wavelength)
    A = 1.7923385088285804  # calculated to retrieve an absorption of 11.2 cm-1
    # at 515nm
    ua_mus = calcUa(A * 0.1, 120, 0.7, eHbO2, eHb, wavelength)

    # factors are due to the program expecting [cm] instead of [m]
    replacements = {
        'muc_c_ua': str(ua / 100),
        'muc_c_us': str(usg['us'] / 100),
        'muc_c_g': str(usg['g']),
        'muc_c_d': str(d * 100),
        'sm_c_ua': str(ua_sm / 100),
        'sm_c_us': str(usg_sm['us'] / 100),
        'sm_c_g': str(usg_sm['g']),
        'mus_c_ua': str(ua_mus / 100),
        'mus_c_us': str(us_mus / 100),
        'outputFilename': outputFilename,
        'c_ph': str(nrPhotons)
    }

    createSimulationFile(infile, replacements,
                         systemPaths.getOutputFolder() + "simulationFile.mci")

    args = ("./" + gpumcmlExecutable, "-A",
            systemPaths.getOutputFolder() + "simulationFile.mci")

    with cd(gpumcmlDirectory):
        popen = subprocess.Popen(args, stdout=subprocess.PIPE)
        popen.wait()

    # outside the context manager we are back wherever we started.

    # this function is error prone, please refer to documentation to see
    # if problematic for you
    return getReflectanceFromFile(gpumcmlDirectory + outputFilename)