How to fill the gaps on the boundary surface of the cone using MATLAB?

4 visualizzazioni (ultimi 30 giorni)
Hi Mathworks community members
I am utilizing the Dr. Bruno Luong's code to fill the gaps. i am using P=[1 2 3; 8 0 4; 7 6 5] to fill the gaps on the boundary surface but some gaps cannot be filled successfuly. using this code, the gaps were filled as 3s. So, i need to adjust the P because its not filling all the gaps. Please anyone can guide me how to overcome this problem.
Aorg = load()
Aorg = s.Aorg;
gapmax = 10;
[m,n] = size(Aorg);
A = double(Aorg>0);
P=[1 2 3;
8 0 4;
7 6 5];
Apad = zeros(m+2,n+2);
maxattempt = 10;
for niter = 1:maxattempt
Apad(2:end-1,2:end-1) = A>0;
B = zeros(m,n,8);
for k=1:8
[i,j] = find(P==k);
B(:,:,k) = Apad(i-2+(2:end-1),j-2+(2:end-1));
end
As = A>0 & sum(diff(B(:,:,[1:8 1]),1,3)==1,3)<=1;
[y,x] = find(As);
if isempty(x)
break
end
p = length(x);
xy = [x,y];
xy1 = reshape(xy,1,[],2);
xy2 = reshape(xy,[],1,2);
d = sum(abs(xy1-xy2),3);
d(d==0) = NaN;
i = (1:size(d,1))';
[dmin,j] = min(d,[],2);
keep = dmin <= gapmax;
i = i(keep);
j = j(keep);
for k=1:length(i)
xyi = xy(i(k),:);
xyj = xy(j(k),:);
dxy = xyi-xyj;
if abs(dxy(1)) > abs(dxy(2))
xr = linspace(xyi(1),xyj(1),abs(dxy(1))+1);
yr = round(interp1([xyi(1),xyj(1)],[xyi(2),xyj(2)],xr));
else
yr = linspace(xyi(2),xyj(2),abs(dxy(2))+1);
xr = round(interp1([xyi(2),xyj(2)],[xyi(1),xyj(1)],yr));
end
A(sub2ind(size(A),yr(2:end-1),xr(2:end-1))) = 3;
end
end

Risposte (1)

Image Analyst
Image Analyst il 1 Mar 2021
The code didn't run so I repaired and improved it below. Other than that I don't know anything about it because unfortunately there are no comments in it to explain it. Good programming practice requires comments.
However I thought that in your other post you said that my bwconvexhull() method was working fine. If it's not anymore, then let me know why not.
Aorg = load('Matrix_Boundary_fills_1s_only.txt')
subplot(2, 1, 1);
imshow(Aorg, []);
title('Input : Aorg', 'FontSize', 20);
gapmax = 10;
[m,n] = size(Aorg);
A = double(Aorg>0);
P=[1 2 3;
8 0 4;
7 6 5];
Apad = zeros(m+2,n+2);
maxattempt = 10;
for niter = 1:maxattempt
Apad(2:end-1,2:end-1) = A>0;
B = zeros(m,n,8);
for k=1:8
[i,j] = find(P==k);
B(:,:,k) = Apad(i-2+(2:end-1),j-2+(2:end-1));
end
As = A>0 & sum(diff(B(:,:,[1:8 1]),1,3)==1,3)<=1;
[y,x] = find(As);
if isempty(x)
break
end
p = length(x);
xy = [x,y];
xy1 = reshape(xy,1,[],2);
xy2 = reshape(xy,[],1,2);
d = sum(abs(xy1-xy2),3);
d(d==0) = NaN;
i = (1:size(d,1))';
[dmin,j] = min(d,[],2);
keep = dmin <= gapmax;
i = i(keep);
j = j(keep);
for k=1:length(i)
xyi = xy(i(k),:);
xyj = xy(j(k),:);
dxy = xyi-xyj;
if abs(dxy(1)) > abs(dxy(2))
xr = linspace(xyi(1),xyj(1),abs(dxy(1))+1);
yr = round(interp1([xyi(1),xyj(1)],[xyi(2),xyj(2)],xr));
else
yr = linspace(xyi(2),xyj(2),abs(dxy(2))+1);
xr = round(interp1([xyi(2),xyj(2)],[xyi(1),xyj(1)],yr));
end
A(sub2ind(size(A),yr(2:end-1),xr(2:end-1))) = 3;
end
end
subplot(2, 1, 2);
imshow(A, []);
title('Output : A', 'FontSize', 20);
  3 Commenti
Image Analyst
Image Analyst il 2 Mar 2021
Why can't you just use beconvhull?
chImage = bwconvhull(binaryImage);
perimeterImage = bwperim(chImage);
M.S. Khan
M.S. Khan il 3 Mar 2021
Thanks image analyst. Yes, i am using: perimeterImage = bwperim(chImage);
but in the image, i am getting gaps as shown in the image with blue color. which is making problem for me. First, i want to fill all the gaps on the boundary surface and then will apply bwperim() to acheive complete outer shell without any gaps on it.
Also, i think,
chImage = bwconvhull(binaryImage)
can only be used for convex images which cannot cover the concave images.
My objective is covering the gaps on the boundary surface.
i have used the above code to fill the gaps and label with 3 but still i could not succeed to fill all the gaps. Any guidance please.
Regards

Accedi per commentare.

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by