Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ags_grabber
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Larkin Heintzman
ags_grabber
Commits
b1e3ecce
Commit
b1e3ecce
authored
Mar 01, 2023
by
Bryson Howell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started a python script to convert .mat matrices into formats useable in Unity
parent
3f2a0b02
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
0 deletions
+75
-0
kentland_heightmap.png
unity_data/kentland_heightmap.png
+0
-0
kentland_heightmap.raw
unity_data/kentland_heightmap.raw
+0
-0
unity_heightmap.py
unity_heightmap.py
+75
-0
No files found.
unity_data/kentland_heightmap.png
0 → 100644
View file @
b1e3ecce
2.21 KB
unity_data/kentland_heightmap.raw
0 → 100644
View file @
b1e3ecce
File added
unity_heightmap.py
0 → 100644
View file @
b1e3ecce
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
scipy.io
import
loadmat
from
PIL
import
Image
import
cv2
#Loads matlab matrices created by feature_set.py as numpy arrays
def
main
():
#Load the matlab matrix
dir
=
'./matlab_data/'
savedir
=
'./unity_data/'
filename
=
'BW_LFandInac_Zelev_kentland.mat'
matdict
=
loadmat
(
dir
+
filename
,
appendmat
=
False
)
#Testing stuff
k
=
matdict
.
keys
()
print
(
k
)
#These are square numpy arrays of equal size
elev
=
matdict
[
'sZelev'
]
#Values are height of grid cell (in meters)
linfeat
=
matdict
[
'BWLF'
]
#Values are 1 for linear feature present, 0 for none
obstacles
=
matdict
[
'BWInac'
]
#Values are 1 for obstacle, 0 for clear
make_heightmap
(
elev
,
savedir
)
return
#Converts the terrain height data in the .mat files into a grayscale heightmap
#that can be loaded into Unity. Heightmaps are 16-bit grayscale images saved in
#the RAW format.
def
make_heightmap
(
elev
,
savedir
):
name
=
savedir
+
"kentland_heightmap.raw"
#fig = plt.figure()
#plt.imshow(elev)
#plt.show()
#Normalize values to be between 0-1 and preview as grayscale image
elev_gray
=
np
.
float16
((
elev
-
np
.
min
(
elev
))
/
(
np
.
max
(
elev
)
-
np
.
min
(
elev
)))
#elev_gray = np.ushort(elev)
#elev_gray = np.uint16(elev)
fig
=
plt
.
figure
()
plt
.
imshow
(
elev_gray
)
plt
.
show
()
f
=
open
(
name
,
'w'
)
#Convert to raw format image
img
=
Image
.
fromarray
(
elev_gray
)
img
=
img
.
convert
(
'L'
)
#img = img.convert('I;16')
img
.
save
(
name
,
'PNG'
)
#Should I add L or B to the end (endian)
img
.
show
()
#cv2.imshow('Kentland Heightmap',elev_gray)
#cv2.waitKey(0)
#cv2.imwrite('kentland_heightmap.raw',elev_gray)
return
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment