Last active
November 8, 2016 16:17
-
-
Save JossWhittle/b90d85b395c3a8fed0153a214a3de7a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| graph contour_tree { | |
| layout="dot" | |
| rankdir=UD | |
| ranksep="0.02" | |
| graph [fontname="helvetica"]; | |
| node [fontname="helvetica"]; | |
| edge [fontname="helvetica"]; | |
| s_3539 [label="108" fontcolor="#0CADBC" shape=none] | |
| s_3459 [label="163" fontcolor="#92BF72" shape=none] | |
| s_3460 [label="163" fontcolor="#92BF72" shape=none] | |
| s_3577 [label="163" fontcolor="#92BF72" shape=none] | |
| s_3580 [label="163" fontcolor="#92BF72" shape=none] | |
| s_3581 [label="163" fontcolor="#92BF72" shape=none] | |
| s_3584 [label="163" fontcolor="#92BF72" shape=none] | |
| s_122 [label="189" fontcolor="#CCBB5B" shape=none] | |
| s_183 [label="189" fontcolor="#CCBB5B" shape=none] | |
| s_1464 [label="191" fontcolor="#D0BB59" shape=none] | |
| s_3539 -- s_3459 -- s_3460 -- s_3577 -- s_3580 -- s_3581 -- s_3584 -- s_122 -- s_183 -- s_1464 [style=invis] | |
| v_3539[label="v3539" fontcolor="#0CADBC" color="#0CADBC" style="setlinewidth(2)"] | |
| v_3459[label="v3459" fontcolor="#92BF72" color="#92BF72" style="setlinewidth(2)"] | |
| v_3460[label="v3460" fontcolor="#92BF72" color="#92BF72" style="setlinewidth(2)"] | |
| v_3577[label="v3577" fontcolor="#92BF72" color="#92BF72" style="setlinewidth(2)"] | |
| v_3580[label="v3580" fontcolor="#92BF72" color="#92BF72" style="setlinewidth(2)"] | |
| v_3581[label="v3581" fontcolor="#92BF72" color="#92BF72" style="setlinewidth(2)"] | |
| v_3584[label="v3584" fontcolor="#92BF72" color="#92BF72" style="setlinewidth(2)"] | |
| v_122[label="v122" fontcolor="#CCBB5B" color="#CCBB5B" style="setlinewidth(2)"] | |
| v_183[label="v183" fontcolor="#CCBB5B" color="#CCBB5B" style="setlinewidth(2)"] | |
| v_1464[label="v1464" fontcolor="#D0BB59" color="#D0BB59" style="setlinewidth(2)"] | |
| v_3539 -- v_3459 -- v_3460 -- v_3577 -- v_3580 -- v_3581 -- v_3584 -- v_122 -- v_183 -- v_1464 [style=invis] | |
| v_3577 -- v_3580 [label=" a = 8 p = 0" fontcolor="#94BF72" color="#94BF72" style="setlinewidth(2)"] | |
| v_3581 -- v_3460 [label=" a = 2 p = 0" fontcolor="#94BF72" color="#94BF72" style="setlinewidth(2)"] | |
| v_1464 -- v_183 [label=" a = 55 p = 2" fontcolor="#D2BB59" color="#D2BB59" style="setlinewidth(2)"] | |
| v_122 -- v_183 [label=" a = 1 p = 0" fontcolor="#CEBB5A" color="#CEBB5A" style="setlinewidth(2)"] | |
| v_3539 -- v_3580 [label=" a = 2360 p = 55" fontcolor="#94BF72" color="#94BF72" style="setlinewidth(2)"] | |
| v_3584 -- v_3459 [label=" a = 6 p = 0" fontcolor="#94BF72" color="#94BF72" style="setlinewidth(2)"] | |
| v_183 -- v_3460 [label=" a = 1158 p = 26" fontcolor="#CEBB5A" color="#CEBB5A" style="setlinewidth(2)"] | |
| v_3580 -- v_3459 [label=" a = 4 p = 0" fontcolor="#94BF72" color="#94BF72" style="setlinewidth(2)"] | |
| v_3460 -- v_3459 [label=" a = 4 p = 0" fontcolor="#94BF72" color="#94BF72" style="setlinewidth(2)"] | |
| { rank = same; s_3539; v_3539; } | |
| { rank = same; s_3459; v_3459; } | |
| { rank = same; s_3460; v_3460; } | |
| { rank = same; s_3577; v_3577; } | |
| { rank = same; s_3580; v_3580; } | |
| { rank = same; s_3581; v_3581; } | |
| { rank = same; s_3584; v_3584; } | |
| { rank = same; s_122; v_122; } | |
| { rank = same; s_183; v_183; } | |
| { rank = same; s_1464; v_1464; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| img = double(rgb2gray(imread('test2.bmp'))); | |
| [ct, ct_img] = ContourTree(img); | |
| % For an n x 2 matrix of edge end nodes, ct(n,2) | |
| % and an image ct_img(w,h) where each pixels value | |
| % is the endpoint of the superarc containing it. | |
| % Unique vertices (critical points) | |
| vs = unique([ct(:,1), ct(:,2)]); | |
| fs = []; | |
| for i = 1:numel(vs) | |
| [x,y] = ind2sub(size(img), vs(i)); | |
| fs = [fs, int32(img(x,y))]; | |
| end | |
| % Sort critical points by height function | |
| [~, fsidx] = sort(fs); | |
| vs = vs(fsidx); | |
| cmap = parula(256); | |
| fid = fopen('ct.dot','wt'); | |
| fprintf(fid, 'graph contour_tree {\n'); | |
| fprintf(fid, '\tlayout="dot"\n'); | |
| fprintf(fid, '\trankdir=UD\n'); | |
| fprintf(fid, '\tranksep="0.02"\n'); | |
| fprintf(fid, '\tgraph [fontname="helvetica"];\n'); | |
| fprintf(fid, '\tnode [fontname="helvetica"];\n'); | |
| fprintf(fid, '\tedge [fontname="helvetica"];\n'); | |
| % Create support graph | |
| for i = 1:numel(vs) | |
| [x,y] = ind2sub(size(img), vs(i)); | |
| f = int32(img(x,y)); | |
| fprintf(fid, '\ts_%-4d [label="%d" fontcolor="%s" shape=none]\n', vs(i), f, rgb2hex(cmap(f,:))); | |
| end | |
| % Support edges | |
| fprintf(fid, '\ts_%-4d', vs(1)); | |
| for i = 2:numel(vs) | |
| fprintf(fid, ' -- s_%-4d', vs(i)); | |
| end | |
| fprintf(fid, ' [style=invis]\n'); | |
| % Critical points | |
| for i = 1:numel(vs) | |
| [x,y] = ind2sub(size(img), vs(i)); | |
| f = int32(img(x,y)); | |
| fprintf(fid, '\tv_%d[label="v%d" fontcolor="%s" color="%s" style="setlinewidth(2)"]\n', vs(i), vs(i), rgb2hex(cmap(f,:)), rgb2hex(cmap(f,:))); | |
| end | |
| % Critical support edges | |
| fprintf(fid, '\tv_%-4d', vs(1)); | |
| for i = 2:numel(vs) | |
| fprintf(fid, ' -- v_%-4d ', vs(i)); | |
| end | |
| fprintf(fid, ' [style=invis]\n'); | |
| % Super Arcs | |
| for i = 1:size(ct(:,1)) | |
| if (ct(i,1) ~= ct(i,2)) | |
| [x,y] = ind2sub(size(img), ct(i,1)); | |
| f = img(x,y); | |
| p = f; | |
| [x,y] = ind2sub(size(img), ct(i,2)); | |
| f = int32(max(img(x,y), f)) + 1; | |
| p = int32(abs(p - img(x,y))); | |
| fprintf(fid, '\tv_%-4d -- v_%-4d [label=" a = %d p = %d" fontcolor="%s" color="%s" style="setlinewidth(2)"]\n', ct(i,1), ct(i,2), numel(ct_img(ct_img == ct(i,1))), p, rgb2hex(cmap(f,:)), rgb2hex(cmap(f,:))); | |
| end | |
| end | |
| % Link Critical points to support structure | |
| for i = 1:numel(vs) | |
| fprintf(fid, '\t{ rank = same; s_%d; v_%d; }\n', vs(i), vs(i)); | |
| end | |
| fprintf(fid, '}\n'); | |
| fclose(fid); | |
| system(sprintf('dot -Teps "ct.dot" > "ct.eps"'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment