Skip to content

Commit 87ecf10

Browse files
authored
Image2GSLIB
Code to convert an image to a GSLIB grid in Geo-EAS format.
1 parent 77a4239 commit 87ecf10

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

image2GSLIB.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import csv, sys
2+
import os
3+
import numpy as np
4+
import pandas as pd
5+
from scipy import misc
6+
7+
# Michael Pyrcz, Univ. of Texas at Austin, @GeostatsGuy
8+
#
9+
# Python Script to convert a JPG to intensity GSLIB File
10+
# python filter.py input_filename output_filename
11+
#
12+
# Example:
13+
#
14+
# python image2GSLIB my_image_file.jpg my_GSLIB_file.dat
15+
#
16+
def Dataframe2GSLIB(data_file,df):
17+
colArray = []
18+
colArray = df.columns
19+
ncol = len(df.columns)
20+
nrow = len(df.index)
21+
file_out = open(data_file, "w")
22+
file_out.write(data_file + '\n')
23+
file_out.write(str(ncol) + '\n')
24+
for icol in range(0, ncol):
25+
file_out.write(df.columns[icol] + '\n')
26+
27+
for irow in range(0, nrow):
28+
for icol in range(0, ncol):
29+
file_out.write(str(df.iloc[irow,icol])+ ' ')
30+
file_out.write('\n')
31+
32+
file_out.close()
33+
34+
filename = sys.argv[1]
35+
outname = sys.argv[2]
36+
37+
arr = misc.imread(filename)
38+
39+
nx = arr.shape[0]
40+
ny = arr.shape[1]
41+
42+
arr2 = np.zeros((nx*ny,4))
43+
44+
count = 0
45+
46+
for ix in range(0, nx):
47+
for iy in range(0, ny):
48+
iix = int(nx-1) - int(ix)
49+
arr2[count,0] = int(255) - (int(arr[iix,iy,0]) + int(arr[iix,iy,1]) + int(arr[iix,iy,2]))/3
50+
arr2[count,1] = (int(arr[ix,iy,0]))
51+
arr2[count,2] = (int(arr[ix,iy,1]))
52+
arr2[count,3] = (int(arr[ix,iy,2]))
53+
count = count + 1
54+
55+
df = pd.DataFrame(arr2)
56+
colArray = []
57+
colArray.append("Intensity")
58+
colArray.append("Red")
59+
colArray.append("Green")
60+
colArray.append("Blue")
61+
df.columns = colArray
62+
63+
print("Written file is " + str(ny) + " by " + str(nx) + " - v1.2")
64+
65+
Dataframe2GSLIB(outname,df)

0 commit comments

Comments
 (0)