- Use the skeleton of the structure ("bwskel") to find the wavy centerline.
- Assign a parameter (like arc length) to the centerline to help map the volume to a straight pipe.
- Calculate the planes perpendicular to the centerline at each point to sample the structure's cross-section.
- Map the 3D points of each cross-section to a 2D plane to "unwrap" the structure.
- Create a straight cylindrical grid and interpolate the unwrapped values onto it.
- Use the interpolated grid to reconstruct the structure as a straight pipe.
Straightening a curved cylindrical structure
13 views (last 30 days)
Show older comments
Hello!
I have a solid, wavy, cylindrical structure (with varying values inside) created from a skeleton (bwskel) in a volume. It's kind of squigly and doesn't have any particular direction. I would like to transform this to a cylindrical structure so it displays as a striaght pipe with the correct (interpolated?) values inside. Any ideas on how to do it efficiently? Thanks.
NG
0 Comments
Answers (2)
Pratyush
on 13 Feb 2024
Hi Cat-22,
To straighten a wavy cylindrical structure in MATLAB and maintain the internal values, you would follow these general steps:
Hope this helps.
0 Comments
Ayush
on 21 Jan 2025 at 11:04
I understand you need to transform a curvy cylinder structure in MATLAB and interpolate the internal values, if required.
You can follow these general guidelines for achieving the same:
- Obtain the skeleton (bwskel) of the wavy cylindrical structure to define the centerline.
- Use a smoothing spline (e.g., csaps) to fit a smooth curve to the skeleton’s centerline to approximate a straight path.
- For each point along the smoothed curve, map the values from the original volume to a straightened path using interpolation.
- Create a new volume with the transformed straight pipe, ensuring the original values are appropriately assigned along the straightened structure.
- Display the original and transformed volumes using 3D visualization to verify the transformation.
Here is a pseudo MATLAB code for the same: (I have added comments to make it more readable and clear)
bwskel = your_skeleton_data;
volume_data = your_volume_data;
% Step 2: Extract the centerline of the skeleton
skeleton_centerline = extract_centerline(bwskel);
% Step 3: Fit a smooth curve (e.g., B-spline or cubic spline) to the skeleton centerline
t = 1:length(skeleton_centerline); % parameter for skeleton points
x = skeleton_centerline(:, 1);
y = skeleton_centerline(:, 2);
z = skeleton_centerline(:, 3);
% Fit a B-spline to the skeleton centerline
pp_x = csaps(t, x, smoothing_param);
pp_y = csaps(t, y, smoothing_param);
pp_z = csaps(t, z, smoothing_param);
% Generate a smoothed centerline
t_fine = linspace(1, length(skeleton_centerline), num_points_fine);
x_smooth = ppval(pp_x, t_fine);
y_smooth = ppval(pp_y, t_fine);
z_smooth = ppval(pp_z, t_fine);
% Step 4: Resample the values from the original volume along the smoothed centerline
% For each point along the smoothed centerline, find the nearest voxel in the original volume
% Initialize the new straightened volume
new_volume = zeros(size(volume_data));
for i = 1:length(t_fine)
% Find the nearest voxel in the original volume corresponding to (x_smooth(i), y_smooth(i), z_smooth(i))
[ix, iy, iz] = round([x_smooth(i), y_smooth(i), z_smooth(i)]);
ix = min(max(ix, 1), size(volume_data, 1));
iy = min(max(iy, 1), size(volume_data, 2));
iz = min(max(iz, 1), size(volume_data, 3));
value_at_position = volume_data(ix, iy, iz); % Adjust this if you want more complex interpolation
new_volume(ix, iy, iz) = value_at_position;
end
figure;
subplot(1, 2, 1);
imshow3D(volume_data);
title('Original Volume');
subplot(1, 2, 2);
imshow3D(new_volume);
title('Straightened Volume');
% Helper function for centerline extraction (if needed)
function centerline = extract_centerline(bwskel)
[rows, cols, slices] = ind2sub(size(bwskel), find(bwskel));
centerline = [rows, cols, slices];
end
% Helper function to visualize 3D volumes (adjust based on your needs)
function imshow3D(volume)
slice_idx = round(linspace(1, size(volume, 3), 10));
for i = 1:length(slice_idx)
imagesc(squeeze(volume(:, :, slice_idx(i))));
axis equal;
title(['Slice ' num2str(slice_idx(i))]);
pause(0.1);
end
end
You can read more about "ppval" function here: https://www.mathworks.com/help/matlab/ref/ppval.html
Hope it helps!
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!