diff --git a/Notebooks/Custom rasters from LiDAR data.ipynb b/Notebooks/Custom rasters from LiDAR data.ipynb index 41d8248..a2233aa 100644 --- a/Notebooks/Custom rasters from LiDAR data.ipynb +++ b/Notebooks/Custom rasters from LiDAR data.ipynb @@ -70,7 +70,7 @@ " xdata.append(infile.x)\n", " ydata.append(infile.y)\n", " #idata.append(infile.intensity)\n", - " idata.append(infile.z)\n", + " idata.append(infile.num_returns)\n", " \n", " \n", "data = np.array((np.concatenate(xdata), np.concatenate(ydata), np.concatenate(idata))).T\n", @@ -83,7 +83,7 @@ "metadata": {}, "outputs": [], "source": [ - "plt.hist(data[:,2], 1000)\n", + "plt.hist(data[:,2], 4)\n", "plt.show()" ] }, @@ -93,18 +93,36 @@ "metadata": {}, "outputs": [], "source": [ - "extremum = .001\n", - "tresholds = np.percentile(data[:,2], [extremum, 1 - extremum])\n", + "extremum = 0.5\n", + "tresholds = np.percentile(data[:,2], [extremum, 100 - extremum])\n", "display(tresholds)\n", "\n", - "filtered_data = data.copy()\n", - "filtered_data[:,2][data[:,2] < tresholds[0]] = tresholds[0]\n", - "filtered_data[:,2][data[:,2] > tresholds[1]] = tresholds[1]\n", + "filtered_data = data[:,2].copy()\n", + "filtered_data[data[:,2] < tresholds[0]] = tresholds[0]\n", + "filtered_data[data[:,2] > tresholds[1]] = tresholds[1]\n", "\n", - "plt.hist(filtered_data[:,2], 1000)\n", + "plt.hist(filtered_data, 100)\n", "plt.show()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "(data[:,2] < tresholds[0]).sum(), (data[:,2] > tresholds[1]).sum()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tresholds[1]" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -391,8 +409,12 @@ "sampled_data = np.array([[0, 0, 5], [9, 9, 5], [0, 9, 10], [20, 0, 10]])\n", "\n", "def rasterize(coords, values, resolution, method='cubic'):\n", - " xmin, xmax = coords[:,0].min(), coords[:,0].max()\n", - " ymin, ymax = coords[:,1].min(), coords[:,1].max()\n", + " #if isinstance(coords, np.array):\n", + " # xmin, xmax = coords[:,0].min(), coords[:,0].max()\n", + " # ymin, ymax = coords[:,1].min(), coords[:,1].max()\n", + " #else:\n", + " xmin, xmax = coords[0].min(), coords[0].max()\n", + " ymin, ymax = coords[1].min(), coords[1].max()\n", "\n", " gridx, gridy = np.mgrid[xmin:xmax:resolution, ymin:ymax:resolution]\n", " \n", @@ -418,6 +440,15 @@ "plt.show()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data.shape, filtered_data.shape" + ] + }, { "cell_type": "code", "execution_count": null, @@ -425,7 +456,8 @@ "outputs": [], "source": [ "treshold = -1\n", - "raster = rasterize(data[:treshold,:2], should_have_keep_idata[:treshold], 0.5, 'nearest')\n", + "#raster = rasterize(data[:treshold,:2], should_have_keep_idata[:treshold], 0.5, 'nearest')\n", + "raster = rasterize(data[:,:2], filtered_data, 0.5, 'cubic')\n", "\n", "plt.figure(figsize=figsize)\n", "plt.imshow(raster.T, origin='lower')\n", @@ -438,7 +470,21 @@ "metadata": {}, "outputs": [], "source": [ - "plt.imsave('../Res/my_raster.png', raster.T, origin='lower')" + "#raster = rasterize(data[:treshold,:2], should_have_keep_idata[:treshold], 0.5, 'nearest')\n", + "raster = rasterize((infile.x, infile.y), infile.num_returns, 1, 'nearest')\n", + "\n", + "plt.figure(figsize=figsize)\n", + "plt.imshow(raster.T, origin='lower')\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.imsave('../Res/my_raster_cubic.png', raster.T, origin='lower')" ] }, {