How to fill interior as different color

5 vues (au cours des 30 derniers jours)
M.S. Khan
M.S. Khan le 17 Sep 2019
Commenté : M.S. Khan le 28 Fév 2021
Hi Mathwork community,
Using below code, i can get boundary as blue color and gaps filled as yellow color but i want to fill the interior as green color.
Thanks in advance for all help.
s = load('Result_matrix.mat');
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
  4 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 17 Sep 2019
Thanks @Bruno
@M.S. Khan
Are you looking for following one? Bruno provided the answer, please do confirm.
test11.png
M.S. Khan
M.S. Khan le 17 Sep 2019
Yes Mr. Kalyan. i want background as blue, boundary as yellow, filles holes as red and interior as green.
Thanks for cooperation.

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 17 Sep 2019
Modifié(e) : Bruno Luong le 17 Sep 2019
Fill the hole with imfill
Next you can color your integer image by defining the appropriate colormap
% Generate test image contains values in 0:4
[~,~,I]=histcounts(peaks,5);
I = I-1;
imagesc(I)
colormap([1 0 0; % color of 0 value
0 1 0; % color of 1 value
0 0 1; % color of 2 value
0 0 0; % color of 3 value
1 1 1])% color of 4 value
set(gca,'Clim',[-0.5 max(I(:))+0.5]);
colorbar
color.png
  16 commentaires
Bruno Luong
Bruno Luong le 18 Sep 2019
I fail to see the relationship between saving and coloring. What is your motivation of you asking unrelated question to this thread?
"Please post the question you might have each step as a series of indepent questions."
M.S. Khan
M.S. Khan le 28 Fév 2021
Hi Dear Bruno Luong,
i am using your above code to fill the gaps on boundary surface of cone but could not succeed to fill the gaps.
i have tried to change the ie. P=[1 2 3; 8 0 4;7 6 5] but its giving me errors.
Please guide me.
The file of cone with gaps on the boundary is attached.
Thanks for all your kind cooperations and guidance.
Regards

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Green dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by