Forum

Author Topic: color coded texturing  (Read 3858 times)

frank.stremke

  • Full Member
  • ***
  • Posts: 206
    • View Profile
color coded texturing
« on: May 04, 2015, 05:09:47 PM »
hello
i have seen the color coded (by altitude) texturing on the website
it looks realy cool and i read somewhere it was done by a scribt anyone knows which one it was and where to find it.
thanks
frank

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14103
    • View Profile
Re: color coded texturing
« Reply #1 on: May 04, 2015, 09:35:02 PM »
Hello Frank,

On the image on the tutorial page has been generated with the help of Python code, coloring the mesh vertices according to the elevation values.
Best regards,
Alexey Pasumansky,
Agisoft LLC

frank.stremke

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: color coded texturing
« Reply #2 on: May 04, 2015, 09:56:00 PM »
Is this script availible?
Frank

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14103
    • View Profile
Re: color coded texturing
« Reply #3 on: May 04, 2015, 10:24:27 PM »
Hello Frank,

Sure, I just need to modify it for the actual version.
Best regards,
Alexey Pasumansky,
Agisoft LLC

frank.stremke

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: color coded texturing
« Reply #4 on: May 04, 2015, 10:31:46 PM »
Excellent thanks looking forward to that
Frqnk

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14103
    • View Profile
Re: color coded texturing
« Reply #5 on: May 08, 2015, 02:06:48 PM »
Hello Frank,

Here's the script (mesh model should be generated before the script run):

Code: [Select]
#Script compatibility - Agisoft PhotoScan Professional v. 1.1.6

import PhotoScan

def calculate_color(z, max, min):

thresh = [(max + 2 * min) / 3, (max + min) / 2, (2 * max + min) / 3, max]

if z < thresh[0]:
r = 0
g =  (z - min )/ (thresh[0] - min) * 255
b = 255
color = (r, g, b)
elif z < thresh[1]:
r = 0
g = 255
b = (thresh[1] - z) / (thresh[1] - thresh[0]) * 255
color = (r, g, b)
elif z < thresh[2]:
r = (z - thresh[1]) / (thresh[2] - thresh[1]) * 255
g = 255
b = 0
color = (r, g, b)
else:
r = 255
g = (thresh[3] - z) / (thresh[3] - thresh[2]) * 255
b = 0
color = (r, g, b)
return color

doc = PhotoScan.app.document
chunk = doc.chunk
num = len(chunk.model.vertices)

min, max = 5.1E9, -5.1E9

if not chunk.crs:  #Local coordinates
print('Script only works correctly for real coordinate systems\nPerforming script for local coordinates')
PhotoScan.app.messageBox('Script only works correctly for real coordinate systems\nPerforming script for local coordinates')

for i in range (0, num):
p = chunk.model.vertices[i]

vt = chunk.transform.matrix.mulp(p.coord)

if vt.z > max:
max = vt.z
else:
if vt.z < min:
min = vt.z

for i in range (0, num):
p = chunk.model.vertices[i]

vt = chunk.transform.matrix.mulp(p.coord)

p.color = calculate_color(vt.z, max, min)

else:   #projected
PhotoScan.app.messageBox("Performing script")
proj = chunk.crs

for i in range (0, num):
p = chunk.model.vertices[i]

vt = chunk.transform.matrix.mulp(p.coord)

vt = proj.project(vt)

if vt.z > max:
max = vt.z
else:
if vt.z < min:
min = vt.z

for i in range (0, num):
p = chunk.model.vertices[i]

vt = chunk.transform.matrix.mulp(p.coord)
vt = proj.project(vt)

p.color = calculate_color(vt.z, max, min)

PhotoScan.app.messageBox("Script finished, please, update view window")
PhotoScan.app.update()
Best regards,
Alexey Pasumansky,
Agisoft LLC