Skip to content

Commit

Permalink
i.histo.match (#150)
Browse files Browse the repository at this point in the history
speed up database operations
  • Loading branch information
metzm committed Apr 22, 2020
1 parent b181fdd commit 3abfe72
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion grass7/imagery/i.histo.match/i.histo.match.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
############################################################################
#
Expand Down Expand Up @@ -104,6 +104,8 @@ def main():
query_create = "CREATE TABLE \"t%s\" (grey_value integer,pixel_frequency " % iname
query_create += "integer, cumulative_histogram integer, cdf real)"
curs.execute(query_create)
index_create = "CREATE UNIQUE INDEX \"t%s_grey_value\" ON \"t%s\" (grey_value) " % (iname, iname)
curs.execute(index_create)
# set the region on the raster
grass.use_temp_region()
grass.run_command('g.region', raster=i)
Expand All @@ -113,6 +115,7 @@ def main():
stats = stats_out.communicate()[0].decode('utf-8').split('\n')[:-1]
stats_dict = dict(s.split(':', 1) for s in stats)
cdf = 0
curs.execute("BEGIN")
# for each number in the range
for n in range(0, max_value):
# try to insert the values otherwise insert 0
Expand All @@ -127,6 +130,7 @@ def main():
insert = "INSERT INTO \"t%s\" VALUES (%i, 0, %i, 0.000000)" % (
iname, n, cdf)
curs.execute(insert)
curs.execute("COMMIT")
db.commit()
# number of pixel is the cdf value
numPixel = cdf
Expand Down Expand Up @@ -167,6 +171,8 @@ def main():
query_create = "CREATE TABLE %s (grey_value integer,average " % table_ave
query_create += "integer, cumulative_histogram integer, cdf real)"
curs.execute(query_create)
index_create = "CREATE UNIQUE INDEX \"%s_grey_value\" ON \"%s\" (grey_value) " % (table_ave, table_ave)
curs.execute(index_create)
cHist = 0
# for each number in the range
for n in range(0, max_value):
Expand Down

0 comments on commit 3abfe72

Please sign in to comment.