Skip to content

Commit

Permalink
Bug fixes and file reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
mchristoffersen committed Dec 5, 2016
1 parent 4d63621 commit 09d1549
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Mac Stuff
.DS_Store

#Combined example tif
out.tif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and will produce the output tiffs "kclimg.tif" from the k-means unsupervised cla

The analyzate.sh script will takes the path to a folder with the band images, the process_vbash.py script, and the gdal_merge.py script as an argument and automates the process. It is buggy sometimes though. Usage is like this:

./analyzate.sh /path/to/image/and/script/directory
./run_combined.sh /path/to/image/and/script/directory

The script will not work if the process_vbash.py and gdal_merge.py scripts are not in the given directory along with the images.

75 changes: 47 additions & 28 deletions process_vbash.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python

from osgeo import gdal
from gdalconst import *
import numpy as np
Expand All @@ -16,19 +15,30 @@
path_to_classification_images = input[2]
list_classification_images = np.array(input[3].split(','))

path_to_output = path_to_source_raster[:-7]

####Make class mask array####
####THIS MUST BE ADDED TO WHEN YOU ADD A CLASSIFICATION IMAGE####
####ADD IMAGES TO THE END OF THE STRING LIST AND THE BOTTOM OF THIS LIST####
####SEE "class.txt" FILE FOR CLASS INDICES###
zer = np.zeros((10,10))
citymsk = zer + 5
city2msk = zer + 5
cloudmsk = zer + 1
cloud2msk = np.zeros((200,10)) + 1
ruralmsk = zer + 4
rural2msk = np.zeros((50,10)) + 4
shadowmsk = zer + 2
watermsk = zer + 3
#citymsk = zer
#city2msk = zer
#cloudmsk = zer + 1
#cloud2msk = np.zeros((200,10)) + 1
#ruralmsk = zer + 2
#rural2msk = np.zeros((50,10)) + 2
#shadowmsk = zer + 3
#watermsk = zer + 4
azer = np.zeros((335,10))
agrimsk = azer + 1
czer = np.zeros((248,10))
citymsk = czer + 2
#undevmsk = zer + 2
wzer = np.zeros((175,10))
watermsk = wzer + 3
uzer = np.zeros((340,10))
undevmsk = uzer + 4
###ADD NEW CLASS MASK ARRAYS BELOW HERE###


Expand Down Expand Up @@ -104,7 +114,7 @@
mldc = sp.MahalanobisDistanceClassifier(trcls)

#Classify image and display results
(kclmap,c) = sp.kmeans(barall,12,20) #unsupervised
(kclmap,c) = sp.kmeans(barall,12,30) #unsupervised
gclmap = gmlc.classify_image(barall) #supervised
mclmap = mldc.classify_image(barall) #supervised

Expand Down Expand Up @@ -167,35 +177,39 @@ def num2colB(arg):
b = np.array(kclmap).astype('uint8')

print 'Kmeans Unsupervised Classification .tif Generation'
pc = 0
for i in range(m):
pcc = int(float(i)/m*100)
if pcc != pc:
pc = pcc
print str(pc) +'%'
#pc = 0
#for i in range(m):
# pcc = int(float(i)/m*100)
# if pcc != pc:
# pc = pcc
# sys.stdout.write(" " + str(pc) +'%\r')
# sys.stdout.flush()

for j in range(n):
r[i][j] = num2colR(r[i][j])
g[i][j] = num2colG(g[i][j])
b[i][j] = num2colB(b[i][j])
# for j in range(n):
# r[i][j] = num2colR(r[i][j])
# g[i][j] = num2colG(g[i][j])
# b[i][j] = num2colB(b[i][j])

rgbcom = np.dstack((r,g,b)).astype('uint8')
kclimg = Image.fromarray(rgbcom)
kclimg.save('kclimg.tif')
#rgbcom = np.dstack((r,g,b)).astype('uint8')
#kclimg = Image.fromarray(rgbcom)
#kclimg.save(path_to_output + 'kclimg.tif')


#Convert gaussian mean array
r = np.array(gclmap).astype('uint8')
g = np.array(gclmap).astype('uint8')
b = np.array(gclmap).astype('uint8')

print ' 100%'

print 'Gaussian Mean Supervised Image Classification .tif Generation'
pc = 0
for i in range(m):
pcc = int(float(i)/m*100)
if pcc != pc:
pc = pcc
print str(pc) + '%'
sys.stdout.write(" " + str(pc) +'%\r')
sys.stdout.flush()

for j in range(n):
r[i][j] = num2colR(r[i][j])
Expand All @@ -204,7 +218,9 @@ def num2colB(arg):

rgbcom = np.dstack((r,g,b)).astype('uint8')
gclimg = Image.fromarray(rgbcom)
gclimg.save('gclimg.tif')
gclimg.save(path_to_output + 'gclimg.tif')

print ' 100%'


#Convert mahalanobis array
Expand All @@ -218,16 +234,19 @@ def num2colB(arg):
pcc = int(float(i)/m*100)
if pcc != pc:
pc = pcc
print str(pc) + '%'

sys.stdout.write(" " + str(pc) +'%\r')
sys.stdout.flush()

for j in range(n):
r[i][j] = num2colR(r[i][j])
g[i][j] = num2colG(g[i][j])
b[i][j] = num2colB(b[i][j])

rgbcom = np.dstack((r,g,b)).astype('uint8')
mclimg = Image.fromarray(rgbcom)
mclimg.save('mclimg.tif')
mclimg.save(path_to_output + 'mclimg.tif')

print ' 100%'



Expand Down
8 changes: 4 additions & 4 deletions analyzate.sh → run_combined.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fend=".tif"

cmd="$1/gdal_merge.py -o $1/out.tif -seperate -v "
cmd="gdal_merge.py -o $1/out.tif -seperate -v "

for i in $( ls $1/*.TIF ); do
cmd="$cmd $i"
Expand All @@ -18,9 +18,9 @@ for i in $( ls $py2 ); do
py3="$py3,$i"
done
py3=${py3:1}
py4=4
py5=4
py4=7
py5=7

$1/process_vbash.py $py1 $py2 $py3 $py4 $py5
./process_vbash.py $py1 $py2 $py3 $py4 $py5


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 09d1549

Please sign in to comment.