从2D边界图像创建国家图

时间:2015-03-02 12:26:39

标签: matlab image-processing graph

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

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

我该怎么做呢?我猜SVG会更容易,但大多数情况下我都会遇到“平坦的”PNG或JPG。

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

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

enter image description here

1 个答案:

答案 0 :(得分:4)

这是我尝试过的。我专注于给定图像的较小区域,以便轻松地说明这一概念。

  • 提取白色区域
  • 标记提取的白色区域
  • 用足够大的内核扩大标记图像。因此,标签值较低的区域将填充附近高标签值区域的像素
  • 对于每个标签区域,检查相应扩张区域中的唯一值。这将为您提供区域关联(边缘)
  • 通过这种方式,您可以逐步构建关联。例如

    标签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
    

输入图片:

enter image description here

标记图像(手动编号):

enter image description here

标签区域:

enter image description here

社团:

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
相关问题