How to pass from a set of points to lines interpolating them?

Hi everyone! I have obtained the following skeletonization
However, if you zoom, you see that the pink lines are not lines but they are series of rectangles that contain points, like you can see in this figure here below.
I would like to know how to pass from these points (contained in the rectangles) to approximate lines that trace the skeletonization in pink (Maybe there is an approximative interpolation that can do this (?)). Could anyone help me? Thanks in advance

4 件のコメント

Image Analyst
Image Analyst 2022 年 6 月 12 日
Why do they need to be perfectly straight lines? In other words, what are you prevented from doing if the lines are curved as they are now?
Have you see interp1
Matt J
Matt J 2022 年 6 月 12 日
Do you just want to connect the centers of the pixels with line segments, like in the following?
load Image
warning off
p=cellfun( @polyshape, bwboundaries(Image));
imagesc(Image); colormap(gray); axis image
hold on;
plot(p(1),'EdgeColor','r','FaceColor','none','LineWidth',3);
hold off
Loren99
Loren99 2022 年 6 月 12 日
@Matt J yes I would like to apply something like this to my case, can you help me?
Loren99
Loren99 2022 年 6 月 12 日
編集済み: Loren99 2022 年 6 月 12 日
@Image Analyst sorry I was wrong to write. They don't have to be straight lines, but lines instead of points (so they can be also curve lines)

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2022 年 6 月 12 日
編集済み: Matt J 2022 年 6 月 12 日

0 投票

Image=load('codice_opcode.mat').out;
B=bwboundaries(Image); B(1)=[];
imagesc(Image); colormap(gray); axis image;
hold on
for i=1:numel(B)
[x,y]=cellBoundary(Image,B{i});
plot(x,y,'r','LineWidth',2)
end
hold off
zoom(4)
function [x,y]=cellBoundary(BW,b)
sz=size(BW);
Z=false(sz);
Z( sub2ind(sz,b(:,1),b(:,2)) )=1;
Z=imdilate(Z,ones(3))&BW;
b=bwboundaries(Z,'noholes');
[x,y]=deal(b{1}(:,2), b{1}(:,1));
end

4 件のコメント

Loren99
Loren99 2022 年 6 月 13 日
@Matt J thanks for your answer, it does what I need. Could I ask you to explain me better and in detail what do these lines of codes in your function cellBoundary do? Thanks
Z( sub2ind(sz,b(:,1),b(:,2)) )=1;
Z=imdilate(Z,ones(3))&BW;
b=bwboundaries(Z,'noholes');
[x,y]=deal(b{1}(:,2), b{1}(:,1));
Matt J
Matt J 2022 年 6 月 13 日
編集済み: Matt J 2022 年 6 月 13 日
The first two lines create an image consisting of just one cell from your skeletonization. If you insert a break point there and do imshow(Z,[]) you can display this image to see what ti looks like.
The 3rd and 4th line extract the boundary pixel coordinates of that cell and assign them to x and y.
Loren99
Loren99 2022 年 6 月 14 日
編集済み: Loren99 2022 年 6 月 14 日
@Matt J thanks. I have a last question; besides this procedure that does what I wanted, is there also a way to obtain in the workspace the [x,y] coordinates of all the cells that compose my sketch? In fact, because of the 'for cicle' I obtain in the workspace only the [x,y] coordinates of the last cell.
Matt J
Matt J 2022 年 6 月 14 日
Just put the output of cellBoundary somewhere convenient, e.g.,
[x{i},y{i}]=cellBoundary(Image,B{i});

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 6 月 12 日

編集済み:

2022 年 9 月 15 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by