Exemple #1
0
def generateBorderMask(data_img, out_mask, RAMPerProcess=4000):
    """
    """

    threshold = 0.0011
    mask = OtbAppBank.CreateBandMathApplication({
        "il":
        data_img,
        "exp":
        "im1b1<{}?1:0".format(threshold),
        "ram":
        str(RAMPerProcess),
        "pixType":
        'uint8'
    })
    mask.Execute()
    borderMask = OtbAppBank.CreateBinaryMorphologicalOperation({
        "in":
        mask,
        "out":
        out_mask,
        "ram":
        str(RAMPerProcess),
        "pixType":
        "uint8",
        "filter":
        "opening",
        "ballxradius":
        5,
        "ballyradius":
        5
    })
    dep = mask
    return borderMask, dep
Exemple #2
0
    def generateBorderMask(self, AllOrtho):
        print("Generate Mask ...")
        masks = []
        for currentOrtho, _ in AllOrtho:
            outputParameter = OtbAppBank.getInputParameterOutput(currentOrtho)
            if "vv" not in currentOrtho.GetParameterValue(outputParameter):
                continue
            workingDirectory = os.path.split(
                currentOrtho.GetParameterValue(outputParameter))[0]
            nameBorderMask = os.path.split(
                currentOrtho.GetParameterValue(outputParameter))[1].replace(
                    ".tif", "_BorderMask.tif")
            nameBorderMaskTMP = os.path.split(
                currentOrtho.GetParameterValue(outputParameter))[1].replace(
                    ".tif", "_BorderMask_TMP.tif")
            bandMathMask = os.path.join(workingDirectory, nameBorderMaskTMP)
            currentOrtho_out = currentOrtho
            if self.wMode: currentOrtho_out.GetParameterValue(outputParameter)
            maskBM = OtbAppBank.CreateBandMathApplication({
                "il":
                currentOrtho_out,
                "exp":
                "im1b1<0.0011?1:0",
                "ram":
                str(self.RAMPerProcess),
                "pixType":
                'uint8',
                "out":
                bandMathMask
            })
            if self.wMode: maskBM.ExecuteAndWriteOutput()
            else: maskBM.Execute()

            borderMaskOut = os.path.join(workingDirectory, nameBorderMask)
            maskBM_out = maskBM
            if self.wMode: maskBM_out.GetParameterValue("out")
            borderMask = OtbAppBank.CreateBinaryMorphologicalOperation({
                "in":
                maskBM,
                "out":
                borderMaskOut,
                "ram":
                str(self.RAMPerProcess),
                "pixType":
                "uint8",
                "filter":
                "opening",
                "ballxradius":
                5,
                "ballyradius":
                5
            })
            masks.append((borderMask, maskBM))

        return masks