Example #1
0
def compute_haralick(params, debug=False):
    """ compute haralick with the passed parameters
        possible Parameters:
        -progress         <boolean>        Report progress
        -in               <string>         Input Image  (mandatory)
        -channel          <int32>          Selected Channel  (mandatory, defaultvalue is 1)
        -ram              <int32>          Available RAM (Mb)  (optional, off bydefault, default value is 128)
        -parameters.xrad  <int32>          X Radius  (mandatory, default value is 2)
        -parameters.yrad  <int32>          Y Radius  (mandatory, default value is 2)
        -parameters.xoff  <int32>          X Offset  (mandatory, default value is 1)
        -parameters.yoff  <int32>          Y Offset  (mandatory, default value is 1)
        -parameters.min   <float>          Image Minimum  (mandatory, default value is 0)
        -parameters.max   <float>          Image Maximum  (mandatory, default value is 255)
        -parameters.nbbin <int32>          Histogram number of bin  (mandatory,default value is 8)
        -texture          <string>         Texture Set Selection [simple/advanced/higher]
        (mandatory, default value is simple)
        -out              <string> [pixel] Output Image  [pixel=uint8/uint16/int16/uint32/int32/float/double]
        (default value is float) (optional, on by default)
        -inxml            <string>         Load otb application from xml file  (optional, off by default)
    :param params: list of parameters, see above for the possible parameters
    :param debug: output all the messages?
    :return: msg, err
    """

    # print("compute Haralick for image " + params[2] + "\n" + "channel" + params[4])
    msg, err = utility.run_tool(params)
    if err:
        print(err)
    if debug:
        print(msg)
    return msg, err
Example #2
0
def scale_image(rootpath, inputimage, exact= True, debug=False):
    """
    :param rootpath:
    :param inputimage:
    :param scaledout:
    :param exact:
    :param debug:
    :return: the output image path
    """

    if exact:  # scale all the bands exactly from 0 to 255 with orfeo
        print("scaling image exactly from 0 to 255, wait....")
        scaledout = rootpath + "rasterRescaled0_255.tif"
        out, err = utility.convert_raster(inputimage, scaledout)

        if debug:
            print(out)

        if err:
            if not (err == "\r\n" or err == "\r" or err == "\n"):  # windows, oldmac, unix
                print(err)
                sys.exit(1)

    else:  # scale all the bands within 0 to 255 with gdal
        print("scaling image within 0 to 255, wait....")
        scaledout = rootpath + "rasterRescaledWithin0_255.tif"
        out, err = utility.run_tool(['gdal_translate.exe', inputimage, scaledout, "-scale"])

        if debug:
            print(out)

        if err:
            if not (err == '\r\n' or err == '\r' or err == '\n'):  # windows, oldmac, unix
                print(err)
                print("the input image could not be rescaled, script is stopping")
                sys.exit(1)

    return scaledout