[GRASS-SVN] r74330 - grass/trunk/scripts/i.pansharpen
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Mar 30 07:44:27 PDT 2019
Author: cmbarton
Date: 2019-03-30 07:44:27 -0700 (Sat, 30 Mar 2019)
New Revision: 74330
Modified:
grass/trunk/scripts/i.pansharpen/i.pansharpen.py
Log:
fixed rare possible bug in histogram matching algorithm and made all output maps integer CELL maps (because they actually are)
Modified: grass/trunk/scripts/i.pansharpen/i.pansharpen.py
===================================================================
--- grass/trunk/scripts/i.pansharpen/i.pansharpen.py 2019-03-29 17:02:43 UTC (rev 74329)
+++ grass/trunk/scripts/i.pansharpen/i.pansharpen.py 2019-03-30 14:44:27 UTC (rev 74330)
@@ -284,9 +284,9 @@
if sproc:
# serial processing
e = '''eval(k = "$ms1" + "$ms2" + "$ms3")
- "$outr" = 1.0 * "$ms3" * "$panmatch3" / k
- "$outg" = 1.0 * "$ms2" * "$panmatch2" / k
- "$outb" = 1.0 * "$ms1" * "$panmatch1" / k'''
+ "$outr" = 1 * round("$ms3" * "$panmatch3" / k)
+ "$outg" = 1 * round("$ms2" * "$panmatch2" / k)
+ "$outb" = 1 * round("$ms1" * "$panmatch1" / k)'''
grass.mapcalc(e, outr=outr, outg=outg, outb=outb,
panmatch1=panmatch1, panmatch2=panmatch2,
panmatch3=panmatch3, ms1=ms1, ms2=ms2, ms3=ms3,
@@ -293,13 +293,13 @@
overwrite=True)
else:
# parallel processing
- pb = grass.mapcalc_start('%s_blue = (1.0 * %s * %s) / (%s + %s + %s)' %
+ pb = grass.mapcalc_start('%s_blue = 1 * round((%s * %s) / (%s + %s + %s))' %
(out, ms1, panmatch1, ms1, ms2, ms3),
overwrite=True)
- pg = grass.mapcalc_start('%s_green = (1.0 * %s * %s) / (%s + %s + %s)' %
+ pg = grass.mapcalc_start('%s_green = 1 * round((%s * %s) / (%s + %s + %s))' %
(out, ms2, panmatch2, ms1, ms2, ms3),
overwrite=True)
- pr = grass.mapcalc_start('%s_red = (1.0 * %s * %s) / (%s + %s + %s)' %
+ pr = grass.mapcalc_start('%s_red = 1 * round((%s * %s) / (%s + %s + %s))' %
(out, ms3, panmatch3, ms1, ms2, ms3),
overwrite=True)
@@ -413,75 +413,75 @@
if sproc:
# serial processing
- outr = '%s_red' % out
- outg = '%s_green' % out
- outb = '%s_blue' % out
+ outr = '%s_red' % out
+ outg = '%s_green' % out
+ outb = '%s_blue' % out
- cmd1 = "$outb = (1.0 * $panmatch1 * $b1evect1) + ($pca2 * $b1evect2) + ($pca3 * $b1evect3) + $b1mean"
- cmd2 = "$outg = (1.0 * $panmatch2 * $b2evect1) + ($pca2 * $b2evect2) + ($pca3 * $b2evect3) + $b2mean"
- cmd3 = "$outr = (1.0 * $panmatch3 * $b3evect1) + ($pca2 * $b3evect2) + ($pca3 * $b3evect3) + $b3mean"
+ cmd1 = "$outb = 1 * round(($panmatch1 * $b1evect1) + ($pca2 * $b1evect2) + ($pca3 * $b1evect3) + $b1mean)"
+ cmd2 = "$outg = 1 * round(($panmatch2 * $b2evect1) + ($pca2 * $b2evect2) + ($pca3 * $b2evect3) + $b2mean)"
+ cmd3 = "$outr = 1 * round(($panmatch3 * $b3evect1) + ($pca2 * $b3evect2) + ($pca3 * $b3evect3) + $b3mean)"
- cmd = '\n'.join([cmd1, cmd2, cmd3])
+ cmd = '\n'.join([cmd1, cmd2, cmd3])
- grass.mapcalc(cmd, outb=outb, outg=outg, outr=outr,
- panmatch1=panmatch1,
- panmatch2=panmatch2,
- panmatch3=panmatch3,
- pca2=pca2,
- pca3=pca3,
- b1evect1=b1evect1,
- b2evect1=b2evect1,
- b3evect1=b3evect1,
- b1evect2=b1evect2,
- b2evect2=b2evect2,
- b3evect2=b3evect2,
- b1evect3=b1evect3,
- b2evect3=b2evect3,
- b3evect3=b3evect3,
- b1mean=b1mean,
- b2mean=b2mean,
- b3mean=b3mean,
- overwrite=True)
+ grass.mapcalc(cmd, outb=outb, outg=outg, outr=outr,
+ panmatch1=panmatch1,
+ panmatch2=panmatch2,
+ panmatch3=panmatch3,
+ pca2=pca2,
+ pca3=pca3,
+ b1evect1=b1evect1,
+ b2evect1=b2evect1,
+ b3evect1=b3evect1,
+ b1evect2=b1evect2,
+ b2evect2=b2evect2,
+ b3evect2=b3evect2,
+ b1evect3=b1evect3,
+ b2evect3=b2evect3,
+ b3evect3=b3evect3,
+ b1mean=b1mean,
+ b2mean=b2mean,
+ b3mean=b3mean,
+ overwrite=True)
else:
# parallel processing
- pb = grass.mapcalc_start('%s_blue = (%s * %f) + (%s * %f) + (%s * %f) + %f'
- % (out,
- panmatch1,
- b1evect1,
- pca2,
- b1evect2,
- pca3,
- b1evect3,
- b1mean),
- overwrite=True)
+ pb = grass.mapcalc_start('%s_blue = 1 * round((%s * %f) + (%s * %f) + (%s * %f) + %f)'
+ % (out,
+ panmatch1,
+ b1evect1,
+ pca2,
+ b1evect2,
+ pca3,
+ b1evect3,
+ b1mean),
+ overwrite=True)
- pg = grass.mapcalc_start('%s_green = (%s * %f) + (%s * %f) + (%s * %f) + %f'
- % (out,
- panmatch2,
- b2evect1,
- pca2,
- b2evect2,
- pca3,
- b2evect3,
- b2mean),
- overwrite=True)
+ pg = grass.mapcalc_start('%s_green = 1 * round((%s * %f) + (%s * %f) + (%s * %f) + %f)'
+ % (out,
+ panmatch2,
+ b2evect1,
+ pca2,
+ b2evect2,
+ pca3,
+ b2evect3,
+ b2mean),
+ overwrite=True)
- pr = grass.mapcalc_start('%s_red = (%s * %f) + (%s * %f) + (%s * ''%f) + %f'
- % (out,
- panmatch3,
- b3evect1,
- pca2,
- b3evect2,
- pca3,
- b3evect3,
- b3mean),
- overwrite=True)
+ pr = grass.mapcalc_start('%s_red = 1 * round((%s * %f) + (%s * %f) + (%s * %f) + %f)'
+ % (out,
+ panmatch3,
+ b3evect1,
+ pca2,
+ b3evect2,
+ pca3,
+ b3evect3,
+ b3mean),
+ overwrite=True)
- pb.wait(), pg.wait(), pr.wait()
- try:
- pb.terminate(), pg.terminate(), pr.terminate()
- except:
- ""
+ pb.wait(), pg.wait(), pr.wait()
+ try:
+ pb.terminate(), pg.terminate(), pr.terminate()
+ except:
+ ""
# Cleanup
grass.run_command('g.remove', flags='f', quiet=True, type='raster',
@@ -554,7 +554,7 @@
for j in arrays[target]:
# find the grey value in target that corresponds to the cdf
# closest to the original cdf
- if j[1] == i[1] + min_difference or j[1] == i[1] - min_difference:
+ if j[1] <= i[1] + min_difference and j[1] >= i[1] - min_difference:
# build a reclass rules file from the original grey value and
# corresponding grey value from target
out_line = "%d = %d\n" % (i[0], j[0])
More information about the grass-commit
mailing list