Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Windows
      • Office
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • Visual Paradigm
  • IBM
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Windows
      • Office
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/How to obtain the average diameter of a segment of a graph?

How to obtain the average diameter of a segment of a graph?

PuTI / 2025-04-29
How to obtain the average diameter of a segment of a graph?
Matlab News

I have a graph structure that is formed after binarizing an image of blood vessels and obtaining the skeleton, then creating a graph structure. The graph looks like this:

K >> graph =

graph with properties:

Edges: [773×2 table]
Nodes: [773×0 table]

Which means I have 773 edges and each edge has 2 vertices. The graph edges look like this:
EndNodes Weight
__________ ______

1 2 1
1 53 1.4142
2 3 1
3 4 1
4 5 1

Now, at the end of the graph creation, I have other helper functions that help me create a diameters table with points that have been inferred on the binary image between the vessel walls. So, for each graph point the algorithm tries to look for walls and once found it saves the coordinates and other values in a table.
This is how the table gets created and how it looks like:

diam_tab = table();
for i = 1:n_line % for all the lines detected
row = cell(1,7);
row{1} = dt(i,:); % the diameter measured
row{2} = t; % the time dimension
row{3} = fs; % the frame sampling rate
row{4} = squeeze(permute(w1_t(i,:,:), [1, 3, 2])); % The value coordiantes of the first wall
row{5} = squeeze(permute(w2_t(i,:,:), [1, 3, 2])); % The value coordinates of the second wall
row{6} = line_type(i); % just a string, not relevant
row{7} = util.make_uuid(); % an UUID attached
diam_tab = [diam_tab; row];
end

And finally look like this:

y x fs z1 z2 type UUID
______________ ______________ ______ ________________ ________________ ________ ________________________________________

1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘6ada1ae1-00f8-4d9b-aa7a-80c7be26aaa1’}
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘b8da617c-f55f-418c-88dc-5862c968a637’}

Now, what I want to do is, modify this table so that it doesn’t take all of the 773 rows but instead only like an average of the diameters over a certain segment of the graph. Let’s suppose say that the graph has a Y shape, I would like to obtain, every lets say 10 points an average diameter of that section.
Then, finally, the diam_tab table will not have 773 rows, but only the ones left after averaging over several sections of the graph, let’s say for a graph length of 100 the result would be 100 rows, but I want to get instead the average of the graph at sections of length for ex 10, which would leave me with 10 rows.
And finally, the diam_table would be updated to reflect these values, or at the very least replaced by a similar functioning table.
So far, this is what I turned up with in my code, which isn’t exactly working well as it seems to only get center points between two nodes and then breaks when I attach the created structure to the graph.
function diameters_table = segment_vessel_table(ts, diam_tab)
graph = ts.load_var(‘center_line’).graph;
[y, x] = find(ts.load_var(‘binary_image’));
node_coordinates = [x, y];

n_vessels = height(diam_tab);
midpoints = zeros(n_vessels, 2);

n_samples_graph = 5;

for i = 1:n_vessels
z1 = diam_tab.z1{i};
z2 = diam_tab.z2{i};
mids = (z1 + z2) / 2;
midpoints(i, 🙂 = mean(mids, 2);
end

idx = round(linspace(1, size(z1, 2), n_samples_graph));
sample_points = mean((z1(:, idx) + z2(:, idx)) / 2, 2);

graph = calculate_branch_centers(graph, node_coordinates);
distances = pdist2(midpoints, graph.Nodes.branch_centers);
[~, branch_idx] = min(distances, [], 2);

diam_tab.branch_id = branch_idx;
diameters_table = diam_tab;
end

function graph = calculate_branch_centers(graph, node_coordinates)
n_edges = height(graph.Edges);
branch_centers = zeros(n_edges, 2);

for i = 1:n_edges
node1 = graph.Edges.EndNodes(i, 1);
node2 = graph.Edges.EndNodes(i, 2);
p1 = node_coordinates(node1, :);
p2 = node_coordinates(node2, :);
branch_centers(i, 🙂 = (p1 + p2) / 2;
end

graph.branch_centers = branch_centers; % it breaks here
end

function [xs, x_names, fs] = load_vars(trial)
ts = trial.load_var("tseries");
diam_tab = ts.load_var("diameters");

diam_tab = segment_vessel_table(ts, diam_tab);

dt = diam_tab{:, "y"};
t = diam_tab.x;
t = t(1,:);

xs = TimeSeries(t, dt’);
x_names = "diameter";

% Freq bands is another part that works and not shown atm
for i = 1:size(freq_bands,1)
name = freq_bands{i,1};
xs = [xs; bands.(name)];
x_names = [x_names; name];
end
endI have a graph structure that is formed after binarizing an image of blood vessels and obtaining the skeleton, then creating a graph structure. The graph looks like this:

K >> graph =

graph with properties:

Edges: [773×2 table]
Nodes: [773×0 table]

Which means I have 773 edges and each edge has 2 vertices. The graph edges look like this:
EndNodes Weight
__________ ______

1 2 1
1 53 1.4142
2 3 1
3 4 1
4 5 1

Now, at the end of the graph creation, I have other helper functions that help me create a diameters table with points that have been inferred on the binary image between the vessel walls. So, for each graph point the algorithm tries to look for walls and once found it saves the coordinates and other values in a table.
This is how the table gets created and how it looks like:

diam_tab = table();
for i = 1:n_line % for all the lines detected
row = cell(1,7);
row{1} = dt(i,:); % the diameter measured
row{2} = t; % the time dimension
row{3} = fs; % the frame sampling rate
row{4} = squeeze(permute(w1_t(i,:,:), [1, 3, 2])); % The value coordiantes of the first wall
row{5} = squeeze(permute(w2_t(i,:,:), [1, 3, 2])); % The value coordinates of the second wall
row{6} = line_type(i); % just a string, not relevant
row{7} = util.make_uuid(); % an UUID attached
diam_tab = [diam_tab; row];
end

And finally look like this:

y x fs z1 z2 type UUID
______________ ______________ ______ ________________ ________________ ________ ________________________________________

1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘6ada1ae1-00f8-4d9b-aa7a-80c7be26aaa1’}
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘b8da617c-f55f-418c-88dc-5862c968a637’}

Now, what I want to do is, modify this table so that it doesn’t take all of the 773 rows but instead only like an average of the diameters over a certain segment of the graph. Let’s suppose say that the graph has a Y shape, I would like to obtain, every lets say 10 points an average diameter of that section.
Then, finally, the diam_tab table will not have 773 rows, but only the ones left after averaging over several sections of the graph, let’s say for a graph length of 100 the result would be 100 rows, but I want to get instead the average of the graph at sections of length for ex 10, which would leave me with 10 rows.
And finally, the diam_table would be updated to reflect these values, or at the very least replaced by a similar functioning table.
So far, this is what I turned up with in my code, which isn’t exactly working well as it seems to only get center points between two nodes and then breaks when I attach the created structure to the graph.
function diameters_table = segment_vessel_table(ts, diam_tab)
graph = ts.load_var(‘center_line’).graph;
[y, x] = find(ts.load_var(‘binary_image’));
node_coordinates = [x, y];

n_vessels = height(diam_tab);
midpoints = zeros(n_vessels, 2);

n_samples_graph = 5;

for i = 1:n_vessels
z1 = diam_tab.z1{i};
z2 = diam_tab.z2{i};
mids = (z1 + z2) / 2;
midpoints(i, 🙂 = mean(mids, 2);
end

idx = round(linspace(1, size(z1, 2), n_samples_graph));
sample_points = mean((z1(:, idx) + z2(:, idx)) / 2, 2);

graph = calculate_branch_centers(graph, node_coordinates);
distances = pdist2(midpoints, graph.Nodes.branch_centers);
[~, branch_idx] = min(distances, [], 2);

diam_tab.branch_id = branch_idx;
diameters_table = diam_tab;
end

function graph = calculate_branch_centers(graph, node_coordinates)
n_edges = height(graph.Edges);
branch_centers = zeros(n_edges, 2);

for i = 1:n_edges
node1 = graph.Edges.EndNodes(i, 1);
node2 = graph.Edges.EndNodes(i, 2);
p1 = node_coordinates(node1, :);
p2 = node_coordinates(node2, :);
branch_centers(i, 🙂 = (p1 + p2) / 2;
end

graph.branch_centers = branch_centers; % it breaks here
end

function [xs, x_names, fs] = load_vars(trial)
ts = trial.load_var("tseries");
diam_tab = ts.load_var("diameters");

diam_tab = segment_vessel_table(ts, diam_tab);

dt = diam_tab{:, "y"};
t = diam_tab.x;
t = t(1,:);

xs = TimeSeries(t, dt’);
x_names = "diameter";

% Freq bands is another part that works and not shown atm
for i = 1:size(freq_bands,1)
name = freq_bands{i,1};
xs = [xs; bands.(name)];
x_names = [x_names; name];
end
end I have a graph structure that is formed after binarizing an image of blood vessels and obtaining the skeleton, then creating a graph structure. The graph looks like this:

K >> graph =

graph with properties:

Edges: [773×2 table]
Nodes: [773×0 table]

Which means I have 773 edges and each edge has 2 vertices. The graph edges look like this:
EndNodes Weight
__________ ______

1 2 1
1 53 1.4142
2 3 1
3 4 1
4 5 1

Now, at the end of the graph creation, I have other helper functions that help me create a diameters table with points that have been inferred on the binary image between the vessel walls. So, for each graph point the algorithm tries to look for walls and once found it saves the coordinates and other values in a table.
This is how the table gets created and how it looks like:

diam_tab = table();
for i = 1:n_line % for all the lines detected
row = cell(1,7);
row{1} = dt(i,:); % the diameter measured
row{2} = t; % the time dimension
row{3} = fs; % the frame sampling rate
row{4} = squeeze(permute(w1_t(i,:,:), [1, 3, 2])); % The value coordiantes of the first wall
row{5} = squeeze(permute(w2_t(i,:,:), [1, 3, 2])); % The value coordinates of the second wall
row{6} = line_type(i); % just a string, not relevant
row{7} = util.make_uuid(); % an UUID attached
diam_tab = [diam_tab; row];
end

And finally look like this:

y x fs z1 z2 type UUID
______________ ______________ ______ ________________ ________________ ________ ________________________________________

1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘6ada1ae1-00f8-4d9b-aa7a-80c7be26aaa1’}
1×19682 double 1×19682 double 21.383 {2×19682 double} {2×19682 double} "vessel" {‘b8da617c-f55f-418c-88dc-5862c968a637’}

Now, what I want to do is, modify this table so that it doesn’t take all of the 773 rows but instead only like an average of the diameters over a certain segment of the graph. Let’s suppose say that the graph has a Y shape, I would like to obtain, every lets say 10 points an average diameter of that section.
Then, finally, the diam_tab table will not have 773 rows, but only the ones left after averaging over several sections of the graph, let’s say for a graph length of 100 the result would be 100 rows, but I want to get instead the average of the graph at sections of length for ex 10, which would leave me with 10 rows.
And finally, the diam_table would be updated to reflect these values, or at the very least replaced by a similar functioning table.
So far, this is what I turned up with in my code, which isn’t exactly working well as it seems to only get center points between two nodes and then breaks when I attach the created structure to the graph.
function diameters_table = segment_vessel_table(ts, diam_tab)
graph = ts.load_var(‘center_line’).graph;
[y, x] = find(ts.load_var(‘binary_image’));
node_coordinates = [x, y];

n_vessels = height(diam_tab);
midpoints = zeros(n_vessels, 2);

n_samples_graph = 5;

for i = 1:n_vessels
z1 = diam_tab.z1{i};
z2 = diam_tab.z2{i};
mids = (z1 + z2) / 2;
midpoints(i, 🙂 = mean(mids, 2);
end

idx = round(linspace(1, size(z1, 2), n_samples_graph));
sample_points = mean((z1(:, idx) + z2(:, idx)) / 2, 2);

graph = calculate_branch_centers(graph, node_coordinates);
distances = pdist2(midpoints, graph.Nodes.branch_centers);
[~, branch_idx] = min(distances, [], 2);

diam_tab.branch_id = branch_idx;
diameters_table = diam_tab;
end

function graph = calculate_branch_centers(graph, node_coordinates)
n_edges = height(graph.Edges);
branch_centers = zeros(n_edges, 2);

for i = 1:n_edges
node1 = graph.Edges.EndNodes(i, 1);
node2 = graph.Edges.EndNodes(i, 2);
p1 = node_coordinates(node1, :);
p2 = node_coordinates(node2, :);
branch_centers(i, 🙂 = (p1 + p2) / 2;
end

graph.branch_centers = branch_centers; % it breaks here
end

function [xs, x_names, fs] = load_vars(trial)
ts = trial.load_var("tseries");
diam_tab = ts.load_var("diameters");

diam_tab = segment_vessel_table(ts, diam_tab);

dt = diam_tab{:, "y"};
t = diam_tab.x;
t = t(1,:);

xs = TimeSeries(t, dt’);
x_names = "diameter";

% Freq bands is another part that works and not shown atm
for i = 1:size(freq_bands,1)
name = freq_bands{i,1};
xs = [xs; bands.(name)];
x_names = [x_names; name];
end
end graph, table, handles, image processing MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

Optimal decimation to Log Simulation Data
2025-05-18

Optimal decimation to Log Simulation Data

I need to use a scope to display the current i and the power P as functions of the voltage V, with the curves obtained for various irradiance levels and temperatures
2025-05-18

I need to use a scope to display the current i and the power P as functions of the voltage V, with the curves obtained for various irradiance levels and temperatures

Break in and break away points on Root Locus
2025-05-18

Break in and break away points on Root Locus

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss