【问题标题】:Creating graph of countries from 2D border image从 2D 边界图像创建国家图表
【发布时间】:2015-03-02 12:26:38
【问题描述】:

我有几张 PNG、JPG 或 SVG 格式的 2D 图表,显示了相关国家、地区和城市的黑白图。边框为黑色,其余为白色。地图很简单;没有图标,只有边框。

我想以编程方式创建代表连接国家的节点图。 (A国连接到B和C,C连接到A和D......等等)。国家名称或标签无关紧要,可以任意选择。

我该怎么做呢?我想 SVG 会更容易,但大多数情况下我都坚持使用“平面”PNG 或 JPG。

请注意,地图并不总是真实世界的区域。不可能通过其他来源简单地查找哪些国家与哪些国家相关。

编辑:添加了世界地图的示例图像。这是我能在短时间内找到的最接近我的问题的方法: http://i.imgur.com/zcQ4HSi.png

【问题讨论】:

  • 你能发布一些例子吗?这很难理解,这可能会让你的问题结束。
  • 感谢 Ander Biguri,添加了示例图片。
  • 在你的图片中,有水吗?还是只是一堆带有黑色边框的白色区域?
  • 您可能想研究dual graph 的概念,或者:bwconncomp/bwlabeln

标签: matlab image-processing graph


【解决方案1】:

这是我尝试过的。我将重点放在给定图像的较小区域上,以便轻松说明这个概念。

  • 提取白色区域
  • 标记提取的白色区域
  • 使用足够大的内核扩展标记图像。因此,具有低标签值的区域将被附近高标签值区域的像素填充
  • 对于每个标签区域,检查相应扩张区域中的唯一值。这将为您提供区域关联(边缘)
  • 这样,您将逐步建立关联。例如

    标签 1 的关联:1 2 5 8 9 表示区域 1 与区域 2、5、8 和 9 相连

    标签 2 的关联:2 3 4 5 表示区域 2 与区域 3、4 和 5 等相连。

    im = imread('aus2.png');
    gr = rgb2gray(im);
    % get the white regions
    white = gr > 200;
    % label the image. you might have to erode the image before labelling
    % because even with 4-connectivity you might get merged regions
    lbl = bwlabel(white, 4);
    figure, imshow(label2rgb(lbl))
    % dilating the labeled image will propogate its maxima. 
    % a region with low label value will be populated with the nearby high
    % label values as a result of the dilation
    di = imdilate(lbl, ones(5));
    
    figure
    levels = unique(lbl);
    % skip the label value 0 as it is the background
    for i = levels(2):levels(end)
         subplot(1, levels(end), i), imshow(lbl == i), title(['label:' num2str(i)])
         % check each region for its unique values
         ['associations for label ' num2str(i) ':   ' num2str(unique(di(lbl == i))')]
    end
    

输入图像:

带标签的图片(手动编号):

标签区域:

协会:

associations for label 1:   1  2  5  8  9
associations for label 2:   2  3  4  5
associations for label 3:   3  4  6
associations for label 4:   4  5  6  7  8
associations for label 5:   5  8
associations for label 6:   6  7
associations for label 7:   7  8
associations for label 8:   8  9
associations for label 9:   9

【讨论】:

    猜你喜欢
    • 2021-03-03
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    相关资源
    最近更新 更多