{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Additional tools for PB-M3C2\n", "\n", "
\n", "WARNING: The implementation of this method is experimental and under active development.\n", "
" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "In this notebook, we will provide extension to the [PB-M3C2 workflow](pbm3c2.ipynb) that will be occasionally useful based on your application." ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "## Generation of non-correspondent pairs" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "For best training results, the user should provide both pairs of segments that do correspond to each other, as well as pairs of segments that do not correspond. In manual labelling workflows, it is much easier to produce high quality corresponding pairs that it is to produce non-corresponding pairs. Here, we provide a function that allows you to generate pairs of non-corresponding segments automatically based on heuristic. The general procedure is exactly the same as in [the base workflow](pbm3c2.ipynb) and will not be further explained here." ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "import py4dgeo" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "py4dgeo.set_interactive_backend(\"vtk\")" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "epoch0, epoch1 = py4dgeo.read_from_xyz(\n", " \"plane_horizontal_t1.xyz\", \"plane_horizontal_t2.xyz\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "alg = py4dgeo.PBM3C2()" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "(\n", " xyz_epoch0,\n", " xyz_epoch1,\n", " extracted_segments,\n", ") = alg.export_segmented_point_cloud_and_segments(\n", " epoch0=epoch0,\n", " epoch1=epoch1,\n", ")" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "Now, we will use labelling data from the file `testdata-labelling-correspondent-only.csv`, which does not contain any pairs of non-corresponding segments. Running `add_no_corresponding_seg` on this data, we automatically generate these. There are two heuristics that can be selected through the `algorithm` parameter:\n", "* `random`: For each segment in one epoch, label a random segment from the neighborhood in the other epoch as non-corresponding.\n", "* `closes`: For each segment in one epoch, take the closest segment in the other epoch and label it non-corresponding.\n", "\n", "The neighborhood of a segment is defined by the threshold parameter given as `threshold_max_distance`." ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "augmented_extended_y = py4dgeo.add_no_corresponding_seg(\n", " segments=extracted_segments,\n", " threshold_max_distance=5,\n", " algorithm=\"random\",\n", " extended_y_file_name=\"testdata-labelling-correspondent-only.csv\",\n", ")" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "We can then run the training algorithm, passing directly the augmented labelling data:" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "alg.training(\n", " extracted_segments_file_name=\"extracted_segments.seg\",\n", " extended_y=augmented_extended_y,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "distances, uncertainties = alg.compute_distances(epoch0=epoch0, epoch1=epoch1)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.0" } }, "nbformat": 4, "nbformat_minor": 5 }