Forum

Author Topic: Measure 3D height from 2D image  (Read 2735 times)

AnnaS

  • Newbie
  • *
  • Posts: 24
    • View Profile
Measure 3D height from 2D image
« on: May 05, 2021, 06:14:48 PM »
Hello,

I'm trying to measure char height on trees from aerial imagery. I'm using the ruler tool in Metashape. I'm wondering if you have recommendations for other tools in Metashape that would allow me to measure char height more accurately.

My plan without a better tool is to measure char height in the images and then get some validaiton measurements in the field to create at least a correlative structure of char height across our site. However, I figure many brilliant minds before me have needed this, so there might be a tool out there that I'm missing.

I've considered and dismissed measuring char height in the dense point cloud. The flight overlap was low enough that the 3D reconstruction of many trees is poor.

Thank you,
Anna
« Last Edit: May 05, 2021, 06:24:52 PM by AnnaS »

c-r-o-n-o-s

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Measure 3D height from 2D image
« Reply #1 on: May 05, 2021, 08:26:31 PM »
You can place a marker on the picture (right mouse clock)  and you will see the coordinates...
But trees are probably very difficult to "hit".
« Last Edit: May 05, 2021, 08:32:16 PM by c-r-o-n-o-s »

Paulo

  • Hero Member
  • *****
  • Posts: 1020
    • View Profile
Re: Measure 3D height from 2D image
« Reply #2 on: May 05, 2021, 08:36:36 PM »
Hi all,

placing a marker with right click Add Marker will probably result (in case of higher part of tree) in a point somewhere on the ground as the point cloud is not detailed enough to represent  tree structure fathfully.

I see the only way to measure correctly the heights is to use stereo mode measurement (see Stereoscopic measurements and vectorization in Chapter 5 of User Manual or following tutorial https://agisoft.freshdesk.com/support/solutions/articles/31000153699-stereo-pair-selection-measurements-and-navigation). This is equivalent to use right click Place Marker option where the marker must be marked in at least 2 photos....
« Last Edit: May 05, 2021, 09:08:10 PM by Paulo »
Best Regards,

Paul Pelletier,
Surveyor

Paulo

  • Hero Member
  • *****
  • Posts: 1020
    • View Profile
Re: Measure 3D height from 2D image
« Reply #3 on: May 06, 2021, 12:40:45 AM »
Hi again,

First screen capture shows the result of measuring top of light pole in stereo mode (images DJI_0223 and DJI_0224) and in mono (image DJI_0224). The result in height is quite different (4 m) as point cloud is sparse and there are no points on top of light pole.

Please support, look at the recurrent renderer fail error I get while using stereo mode....attached is error log....

PS. Redid the measurement from base to top of light post and got 3.56 m in stereo mode and 55.3 cm in mono, see 2nd screen capture. Beats me, but this time I no longer get the renderer fail error message!
In last capture, I show stereo distance measurement as seen in dense cloud model view....
« Last Edit: May 06, 2021, 07:55:37 AM by Paulo »
Best Regards,

Paul Pelletier,
Surveyor

JMR

  • Sr. Member
  • ****
  • Posts: 446
    • View Profile
Re: Measure 3D height from 2D image
« Reply #4 on: May 10, 2021, 12:55:52 AM »
Hello, Paul.
Drawing a point on one single photo (2D) is a risky idea. If one wants to use monoscopic approach it is necessary to use markers attached to the shape (point in your case). By means of this special type of markers, the user can pin the same vertex on different images and it leads to a perfectly well determined elevation.
Using stereo input is very well suited for the task but honestly I would not recommend anyone to use anaglyph method for longer than 5 mins. If one wants to use stereo, having a professional stereo display like Pluraview is a must.
I would suggest to the OP to draw a few points on one photo where he/she sees the tip of the trees, then select all points and attach markers by context menu (this can also be automated in tools/markers/attach markers). Then jump to next image and move markers to same corresponding points on trees, a third photo will give chance for check or further refinement.
This type of markers cannot be hidden or removed in 1.7.2 but will be removable in next version coming soon.
By using foint shapes for the measurement one gains interesting advantages over using regular markers:
  • Shapes can hold attriutes (like tree species, log diameter, etc)
  • Shapes can be organised in layers
  • Shapes can be exported as text or CAD files
  • Points with markers attached wont play any role on alignment and wont be in conflict with actual markers used for reference


Regards
José Martínez
Geobit & Accupixel
Metashape training

Paulo

  • Hero Member
  • *****
  • Posts: 1020
    • View Profile
Re: Measure 3D height from 2D image
« Reply #5 on: May 10, 2021, 01:30:59 AM »
Thanks Jose, for the insight!

I am completely in agreement with your suggestion of not using mono measurement as I showed in my post the error introduced in using mono foto measurements vs stereo.
Your idea of placing points with attached markers is surely interesting vs using stereo with no spacial  hardware (anaglyph seems quite tresome after some).
Best Regards,

Paul Pelletier,
Surveyor

AnnaS

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Measure 3D height from 2D image
« Reply #6 on: May 12, 2021, 03:41:54 AM »
José, could you elaborate on how your post relates to measuring char height on a tree from a 2D image? I'm using the point shapes to mark the base of every tree and to store information about each tree (presence of regrowth post-fire, char height, etc.). I don't understand how placing points in a few photos on a tree helps me measure char (fire scar) height on a tree trunk. Thank you for elaborating.
Best,
Anna

Paulo

  • Hero Member
  • *****
  • Posts: 1020
    • View Profile
Re: Measure 3D height from 2D image
« Reply #7 on: May 12, 2021, 06:56:42 AM »
AnnaS,

let me show another example where I placed 2 points of a tree as seen on one image:

- one at base of tree called Base;
- one on tree where branches start to go out (equivalent to your char ht) called Height.

Base is correctly placed on 3d model as dense cloud accurately models the ground. However, point Height is not correctly placed as dense cloud does not represent these fine tree structures. To correctly place Height in 3dmodel you would need to open the next image and mark Height on it... See screen capture

Hope this help to clear things up....
« Last Edit: May 12, 2021, 07:19:11 AM by Paulo »
Best Regards,

Paul Pelletier,
Surveyor

AnnaS

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Measure 3D height from 2D image
« Reply #8 on: May 12, 2021, 06:02:46 PM »
Thank you for explaining again, Paul.

I see now that placing a point at the top of the char height and then fixing it in a few more images will place the marker correctly in the 3D model. However, it's not clear to me how this helps me measure the char height. I don't know of a tool other than the ruler to measure between the two markers. Do you have any suggestions? The height of the char in the 2D image is roughly the same whether before I mark the char with points (image pre) or after (image post).

Paulo

  • Hero Member
  • *****
  • Posts: 1020
    • View Profile
Re: Measure 3D height from 2D image
« Reply #9 on: May 12, 2021, 06:33:37 PM »
AnnaS,

clearly the measurement in mono mode (only one foto) gives basically same result as measuring 2 points (base and hi) in at least 2 fotos because in your case the dense cloud includes the burnt out part of the trees (as seen in the model view)... But this is not always the case depending on many factors (type of imagery, resolution, tree width, etc...)

To assure correct measurements in every case (and discarding using stereo setup), I would recommend for each char height in a photo to place a Shape Polyline ( 2 vertices base and hi part) whre 2nd vertex (hi part of burnt area) is measured in at least 2 images....
Best Regards,

Paul Pelletier,
Surveyor

AnnaS

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Measure 3D height from 2D image
« Reply #10 on: May 12, 2021, 07:59:34 PM »
Awesome. How do I see the measurement (m) of a polyline shape?

Paulo

  • Hero Member
  • *****
  • Posts: 1020
    • View Profile
Re: Measure 3D height from 2D image
« Reply #11 on: May 12, 2021, 09:23:52 PM »
You can always use context menu Measure to see the measurements of a selected shape (perimeter 3D) or you could use a script to populate all your shapes with this distance as in attached example where the shapes are kept in a layer called Char Heights and distances are kept in attribute called 3D_distance  as well as difference in z kept in attribute Delta_Z :
Code: [Select]
chunk = Metashape.app.document.chunk
T = chunk.transform.matrix
for shape in chunk.shapes:
    if shape.group.label != 'Char Heights':   # only shapes in Char Heights layer
        continue
    if shape.is_attached:                     # case of shape with attached markers
        vzs = [chunk.shapes.crs.project(T.mulp(i.position)).z for i in chunk.markers if i.key in shape.vertex_ids]
        shape.attributes['Delta_Z'] = str(round(vzs[-1]-vzs[0],3))
    else:
        shape.attributes['Delta_Z'] = str(round(shape.vertices[-1].z-shape.vertices[0].z,3))
    shape.attributes['3D_distance'] = str(round(shape.perimeter3D(),3))

see attached screen copy...

2nd attachment shows result of using Measure tool (right click context menu) on a selected polyline Shape from Char Heights layer and compares with its attributes....
« Last Edit: May 13, 2021, 06:07:54 AM by Paulo »
Best Regards,

Paul Pelletier,
Surveyor

AnnaS

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Measure 3D height from 2D image
« Reply #12 on: May 19, 2021, 05:08:23 AM »
Hi Paulo,

Thank you for elaborating. This helps, and I'm using your suggestion.

One final thing is how to use that python code you shared to automatically create a 3D_distance attribute. I use agisoft's GUI, and do not normally use python. I tried putting the code you shared into the console with the layer name changed for what I'm using, but I kept getting syntax errors. Is the console the right place to start? Or should I put your code into a python script and run it from the tools menu?

Thank you for the help.
Anna

Paulo

  • Hero Member
  • *****
  • Posts: 1020
    • View Profile
Re: Measure 3D height from 2D image
« Reply #13 on: May 19, 2021, 06:07:12 AM »
Hello AnnaS,

if you copy the code and paste into the console then it will add attributes Delta_Z and 3D_distance to each shape belonging to layer Char Heights. Of course you can adapt it by changing layer name, attibute names.... If you get errors in the console please specify so it can be analysed....The code can also be saved in a file named for example, addshape_3Ddistance.py, adapt it and run in Mestashape with run script....

I modified the code to process only Polylines on specified layer (Char Heights):
Code: [Select]
chunk = Metashape.app.document.chunk
T = chunk.transform.matrix
for shape in chunk.shapes:
    if shape.group.label != 'Char Heights' or shape.type != Metashape.Shape.Type.Polyline:   # only polyline shapes in Char Heights layer
        continue
    if shape.is_attached:                     # case of shape with attached markers
        vzs = [chunk.shapes.crs.project(T.mulp(i.position)).z for i in chunk.markers if i.key in shape.vertex_ids]
        shape.attributes['Delta_Z'] = str(abs(round(vzs[-1]-vzs[0],3)))
    else:
        shape.attributes['Delta_Z'] = str(abs(round(shape.vertices[-1].z-shape.vertices[0].z,3)))
    shape.attributes['3D_distance'] = str(round(shape.perimeter3D(),3))

This way if you have points or polygons on specified layer they will not be processed...
« Last Edit: May 19, 2021, 08:11:18 AM by Paulo »
Best Regards,

Paul Pelletier,
Surveyor

AnnaS

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Measure 3D height from 2D image
« Reply #14 on: May 19, 2021, 08:06:41 PM »
Wonderful! I saved your code as a .py file and ran the script through the Tools menu. Thanks a bunch, Paulo