def heralick_from_image(input, outdir, params,xyoff,nbands=8, debug = False): """ :param input: :param outdir: :param params: :param xyoff: :param nbands: :param debug: :return: """ if not os._exists(outdir): os.mkdir(outdir) for i in range(1, nbands + 1): params[4] = str(i) # set the channel # get image min and max min, max = utility.get_minmax(inputimage, i) print(min, max) params[8] = str(min) params[10] = str(max) # update parameters with the offset angle for x, y in xyoff: newparams = params + ['-parameters.xoff', str(x), '-parameters.yoff', str(y)] newparams[12] = outdir + '/HaralickChannel' + newparams[4] + newparams[6] + 'xoff' + newparams[ 14] + 'yoff' + newparams[16] + '.tif' # set output print("computing haralick for " + newparams[2] + "\n" + "channel " + newparams[4] + " wait for a few hours :D ") msg, err = compute_haralick(newparams, debug) if err: if not (err == "\r\n" or err == "\r" or err == "\n"): # windows, oldmac, unix print(" some heraick from the image could not be created , script is stopping") sys.exit(1)
def heralick_NDI(rootpath, ndipath, params, xyoff, inimgfrmt = ['.tif'], debug=False): """ :param rootpath: :param ndipath: :param params: :param xyoff: :param inimgfrmt: :param debug: :return: """ imgs = os.listdir(ndipath) if not os.path.exists(rootpath + "haralick"): os.mkdir(rootpath + "haralick") if not os.path.exists(rootpath + "haralick/NDI"): os.mkdir(rootpath + "haralick/NDI") outdir = rootpath + "haralick/NDI" for i in imgs: if os.path.isfile(ndipath + '/' + i) and (os.path.splitext(ndipath + '/' + i)[-1] in inimgfrmt): params[2] = ndipath + '/' + i params[4] = '1' # get image min and max min, max = utility.get_minmax(ndipath + '/' + i) print(min, max) params[8] = str(min) params[10] = str(max) # update parameters with the offset angle for x, y in xyoff: newparams = params + ['-parameters.xoff', str(x), '-parameters.yoff', str(y)] newparams[12] = outdir + '/' + i + 'HaralickChannel' + newparams[4] + newparams[6] \ + 'xoff' + newparams[14] + 'yoff' + newparams[16] + '.tif' # set output print("computing haralick for " + params[2] + "\n" + "channel " + params[4] + " wait for a few hours :D ") if debug: import datetime as time starttime = time.datetime.now() msg, err = compute_haralick(newparams, debug) if debug: endtime = time.datetime.now() print('elapsed time') print(endtime - starttime) # about 2h 25 minutes if err: if not (err == "\r\n" or err == "\r" or err == "\n"): # windows, oldmac, unix print(" some NDI heralick images could not be created , script is stopping") sys.exit(1)