資源簡介
matlab開發-FloodFill3D。該程序在二進制矩陣中填充三維區域。

代碼片段和文件信息
function?[B]?=?FloodFill3D(A?slice);
%?[B]?=?FloodFill3D(A?slice);
%?This?program?flood?fills?a?6-connected?3D?region.?The?input?matrix?MUST
%?be?a?binary?image.?The?user?will?select?a?seed?(point)?in?the?matrix?to
%?initiate?the?flood?fill.?You?must?specify?the?matrix?slice?in?which?you
%?wish?to?place?the?seed.
%?
%?A?=?binary?matrix
%?slice?=?a?chosen?slice?in?the?matrix?where?you?wish?to?place?the?seed.
%
%?Enjoy
%?F.?Dinath
A?=?single(A);??????%?In?case?a?logical?matrix?comes?in.
A(1::)?=?NaN;?????%?Pad?the?border?of?the?matrix
A(end::)?=?NaN;???%?so?the?program?doesn‘t?attempt?
A(:1:)?=?NaN;?????%?to?seek?voxels?outside?the?matrix
A(:end:)?=?NaN;???%?boundry?during?the?for?loop?below.
A(::1)?=?NaN;?????%
A(::end)?=?NaN;???%
imagesc(A(::slice));
title(‘select?seed?on?figure‘);
k?=?waitforbuttonpress;
point?=?get(gca‘CurrentPoint‘);?%?button?down?detected
point?=?[fliplr(round(point(21:2)))?slice];
if?A(point(1)?point(2)?point(3));
????A(point(1)?point(2)?point(3))?=?NaN;
????a{1}?=?sub2ind(size(A)?point(1)?point(2)?point(3));
????i?=?1;
????while?1
????????i?=?i+1;
????????a{i}?=?[];
????????[x?y?z]?=?ind2sub(size(A)?a{i-1});
????????ob?=?nonzeros((A(sub2ind(size(A)?x?y?z-1))?==?1).*sub2ind(size(A)?x?y?z-1));
????????A(ob)?=?NaN;
????????a{i}?=?[a{i}?ob‘];
????????ob?=?nonzeros((A(sub2ind(size(A)?x?y?z+1))?==?1).*sub2ind(size(A)?x?y?z+1));
????????A(ob)?=?NaN;
????????a{i}?=?[a{i}?ob‘];
????????ob?=?nonzeros((A(sub2ind(size(A)?x-1?y?z))?==?1).*sub2ind(size(A)?x-1?y?z));
????????A(ob)?=?NaN;
????????a{i}?=?[a{i}?ob‘];
????????ob?=?nonzeros((A(sub2ind(size(A)?x+1?y?z))?==?1).*sub2ind(size(A)?x+1?y?z));
????????A(ob)?=?NaN;
????????a{i}?=?[a{i}?ob‘];
????????ob?=?nonzeros((A(sub2ind(size(A)?x?y-1?z))?==?1).*sub2ind(size(A)?x?y-1?z));
????????A(ob)?=?NaN;
????????a{i}?=?[a{i}?ob‘];
????????ob?=?nonzeros((A(sub2ind(size(A)?x?y+1?z))?==?1).*sub2ind(size(A)?x?y+1?z));
????????A(ob)?=?NaN;
????????a{i}?=?[a{i}?ob‘];
????????if?isempty(a{i});
????????????break;
????????end
%?????????imagesc(A(::slice));
%?????????drawnow;
????end
end
b?=?cell2mat(a);
b?=?sort(b2);
B?=?logical(zeros(size(A)));
B(b)?=?1;
imagesc(B(::slice));
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2245??2006-09-05?22:55??FloodFill3D.m
?????文件?????????359??2006-09-05?22:56??FloodFill3Dexample.m
?????文件??????979915??2006-09-05?22:37??A.mat
評論
共有 條評論