OpenStreetMap logo OpenStreetMap

blkatbyhh's Diary

Recent diary entries

A guide to mapping with the help of image segmentation

Posted by blkatbyhh on 26 November 2022 in English. Last updated on 27 November 2022.

This guide is a translation of my previous diary written in Chinese. The motivation for developing this method is trying to find a way to map vast areas of forests with minimum human effort.

Methodology

The OpenStreetMap data is based on nodes and vector ways. Manual mapping requires a mapper to put nodes on the satellite pictures and connect nodes by mouse clicking, which is a time-consuming process. This guide proposes a software-assisted workflow to ease the mapping process, it includes the following steps.

  1. Raster image acquiring and segmentation
  2. Raster image preparation
  3. Vectorization
  4. Mapping to OSM

Raster image acquiring and segmentation

Software used in this step:

  • JOSM
  • Fiji (Fiji Is Just ImageJ)

Install the JOSM plugin importvec and restart JOSM, Download the map data of the region of interest (ROI), choose a satellite source and download the image. Hide the data layer and take a snapshot of the satellite image on (ROI). Save the snapshot as JPG or PNG file.

Open the snapshot image in Fiji. Turn to the menu: Plugins, Segmentation, Trainable Weka Segmentation. A new Weka window will pop up containing the image. On the right side of the window, there are two preset classes 1 and 2 representing features to be recognized in the image. Create more if needed with create new class button on the left side, and in settings button, you can rename the preset class 1 and 2 to meaningful names to avoid mistakes made by yourself.

Now you can use your mouse left click and hold to draw a curve on the image and click “add to class” button to tag the feature and repeat to create several items. Double-click an item to remove it if you tag it wrong. You don’t have to precisely draw along the edge of the feature, just draw a random curve inside it. When you have collected several items, you can click train classifier in the top-left corner to, well, train the classifier.

See full entry

使用图像识别法进行半自动开荒

Posted by blkatbyhh on 22 November 2022 in Chinese (China) (‪中文(中国大陆)‬). Last updated on 27 November 2022.

前言

虽然Openstreetmap是不面向渲染绘图,但日常看到地图上欧洲一片绿意盎然而东亚地区即使在胡焕庸线以东也是一片空白,实在是有碍观瞻。本地已有的大片自然地貌有国际友人协助开荒,但毕竟不是长久之计。然则大陆地区绘图者寥寥,很难做到大面积开荒,如能使用一些半自动化工具或可以加快开荒速度。故此摸索了一套工具链,希望能有所帮助。

方法

Openstreetmap的数据是矢量路径,手动绘制的过程是以卫星和航拍图为底图进行路径描摹后修整,这一过程最费时费力的是照片判读和路径描摹。本文提出的方法就是尝试用自动化/半自动化的方式减轻这个过程的劳动强度,缩短工时。本方法包括以下几个流程

  1. 图像获取和自动化识别
  2. 位图预处理
  3. 矢量化
  4. 绘图

图像获取和自动化识别

使用的工具

  • JOSM

  • Fiji (Fiji Is Just ImageJ)

JOSM使用方法不赘述。选择合适的卫星图做为底图,隐藏数据层后截图获得位图(raster image)保存。

在Fiji中打开图片,使用Fiji提供的plugin, Segmentation, Trainable Weka Segmentation工具进行图像识别。启动该工具后,先按需建立分类(class),预设有2个分类class 1和class 2。如图像中包含树林,河流,村庄和农田,则需新建两个分类,再去setting里将class 1, 2更名(不更名也没关系,但有明确含义的名字可以避免自己犯错)。用鼠标按住左键画任意曲线的方式在卫星图中指示特征后,点击右侧分类的按钮将曲线加入该类的列表,如有分类失误可以双击列表项移除。指示特征不必精确画出边界,在特征范围内随意标注既可。每个分类都添加若干条目后,点击左上的train classifier进行分类器训练。计算结束后会在图片上叠加用不同颜色标识的分类结果,在这个阶段可以评估分类器有效性,对分类识别失败的地方进行修正标注后重新训练分类器,直到结果满意,在这个阶段不必追求严格精准,因为精准的曲线需要大量控制点描述,而JOSM限制单一路径控制点不能超过2000个,后序的矢量化处理也会精简掉大量控制点。在软件界面点击create result获取结果图片。

位图预处理

使用的工具

  • Fiji (Fiji Is Just ImageJ)

使用Weka Segmentation获得的结果图片包含多个分类,以上述四个分类为例,各个分类的像素点赋值为0, 1, 2和3,下一步是选出需要的分类。使用Fiji的内嵌功能Image, Adjust, Threshold,在弹出的对话框中,滑动上下两个阈值滑块,选出分类的像素点赋值,同时图片中会显示出当前阈值选区。选好后点击Apply应用阈值选择结果。

通常在此步获得的图片还有大量孤立小像素点,本着抓大放小的原则可以去除掉。通过执行N次Process, Binary, Erode功能腐蚀掉所有图形的边界吃掉小点,再执行N次Process, Binary, Dilate将存活的图形膨胀回来。此时得到的边界当然和最初识别的边界存在差异,但前述已说过,只要偏差不是太离谱,误差都应该在可控范围内。另外建议使用Binary下的fill holes功能避免区域嵌套,导入JOSM以后还得处理复合多边形,徒增工作量。如果不想保留贴边的区域,可以用Flood Fill Tool把黑区填充成白色,如果边缘部分和想保留的部分有连接,可以使用Process, Binary, Watershed功能把图形分割成小块再填充掉不要的部分,用Process, Binary, Close~功能把Watershed的切分拼回去。此时已完成位图的预处理,File, Save as PNG保存后就可以进入下一步矢量化了。

矢量化

使用的工具

  • inkscape

将预处理后的位图导入inkscape,使用Path, Trace Bitmap功能,Detection Mode选默认的Brightness cutoff,选中位图后Apply获得矢量路径。矢量路径是叠加在位图上的,拖动一下就可以看到结果。路径内部是填充的,可以在Object, Fill and Stroke功能里取消填充,绘制路径,得到图形干净的边界线。然后保存为svg格式的矢量图就可以了。

绘图

使用的工具

  • JOSM

  • JOSM插件importvec

安装importvec后,JOSM可以打开svg矢量图,导入svg后会问你比例,随便吧,反正也不知道具体是多少,需要缩放调整的。

See full entry