| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import argparse |
| 16 |
import os |
| 17 |
import math |
| 18 |
import numpy as np |
| 19 |
import jiplib as jl |
| 20 |
|
| 21 |
parser=argparse.ArgumentParser() |
| 22 |
parser.add_argument("-input","--input",help="Path of the input raster dataset",dest="input",required=True,type=str) |
| 23 |
parser.add_argument("-filter","--filter",help="filter function",dest="filter",required=False,type=str) |
| 24 |
parser.add_argument("-band","--band",help="band to filter (leave empty to filter all bands)",dest="band",required=False,type=int,nargs='+') |
| 25 |
parser.add_argument("-size","--size",help="size",dest="size",required=False,type=int,default=3) |
| 26 |
parser.add_argument("-nodata","--nodata",help="no data value",dest="nodata",required=False,type=int,nargs='+') |
| 27 |
parser.add_argument("-output","--output",help="Path of the classification output raster dataset",dest="output",required=False,type=str) |
| 28 |
args = parser.parse_args() |
| 29 |
|
| 30 |
|
| 31 |
if True: |
| 32 |
jimlist=jl.createJimList() |
| 33 |
if args.band: |
| 34 |
for band in args.band: |
| 35 |
jim0=jl.createJim(filename=args.input,band=band) |
| 36 |
print("mean of jim0:{}".format(jim0.getStats({'function':'mean'}))) |
| 37 |
projection=jim0.getProjection() |
| 38 |
gt=jim0.getGeoTransform() |
| 39 |
np0=jl.jim2np(jim0) |
| 40 |
jim=jl.np2jim(np0) |
| 41 |
print("mean of jim:{}".format(jim.getStats({'function':'mean'}))) |
| 42 |
print("number of cols in jim:{}".format(jim.nrOfCol())) |
| 43 |
print("number of rows in jim:{}".format(jim.nrOfRow())) |
| 44 |
|
| 45 |
|
| 46 |
if args.filter: |
| 47 |
if args.nodata: |
| 48 |
print("filter with nodata value {}".format(args.nodata)) |
| 49 |
jimlist.pushImage(jim.filter2d({'filter':args.filter,'dx':args.size,'dy':args.size,'nodata':args.nodata})) |
| 50 |
else: |
| 51 |
print("filter") |
| 52 |
jimlist.pushImage(jim.filter2d({'filter':args.filter,'dx':args.size,'dy':args.size})) |
| 53 |
else: |
| 54 |
print("jim.crop.nrOfCol():{}".format(jim.crop({}).nrOfCol())) |
| 55 |
jimlist.pushImage(jim.crop({})) |
| 56 |
print("stacking {} bands".format(jimlist.getSize())) |
| 57 |
jim=jimlist.stack({'verbose':2}) |
| 58 |
print("number of cols in jim:{}".format(jim.nrOfCol())) |
| 59 |
print("number of rows in jim:{}".format(jim.nrOfRow())) |
| 60 |
print("mean of stacked jim:{}".format(jim.getStats({'function':'mean'}))) |
| 61 |
else: |
| 62 |
jim0=jl.createJim(filename=args.input) |
| 63 |
projection=jim0.getProjection() |
| 64 |
gt=jim0.getGeoTransform() |
| 65 |
np0=jl.jim2np(jim0) |
| 66 |
jim=jl.np2jim(np0) |
| 67 |
|
| 68 |
|
| 69 |
if args.filter: |
| 70 |
if args.nodata: |
| 71 |
print("filter with nodata value {}".format(args.nodata)) |
| 72 |
jim=jim.filter2d({'filter':args.filter,'dx':args.size,'dy':args.size,'nodata':args.nodata}) |
| 73 |
else: |
| 74 |
print("filter") |
| 75 |
jim=jim.filter2d({'filter':args.filter,'dx':args.size,'dy':args.size}) |
| 76 |
print("number of cols in jim:{}".format(jim.nrOfCol())) |
| 77 |
print("number of rows in jim:{}".format(jim.nrOfRow())) |
| 78 |
print("mean of stacked jim:{}".format(jim.getStats({'function':'mean'}))) |
| 79 |
print("number of output bands:{}".format(jim.nrOfBand())) |
| 80 |
print(jim.getStats({'function':'mean'})) |
| 81 |
if args.output: |
| 82 |
print("write output to {}".format(args.output)) |
| 83 |
jim.write({'filename':args.output,'co':['COMPRESS=LZW','TILED=YES']}) |
| 84 |
jim.close() |
| 85 |
print("Success: filter2d") |
| 86 |
try: |
| 87 |
print("ok") |
| 88 |
except: |
| 89 |
print("Failed: filter2d") |