function phi = ac_SDF_2D(type, dims, varargin)
% FUNCTION U = AC_SDF_2D(TYPE, DIMS, VARARGIN)
% Generate some patterns of 2D sign distance functions.
% Inputs:
% TYPE --- Type of the pattern. Can be one of "circle", "rectangle",
% "circle_array" and "chess_box".
% DIMS --- Size of the pattern.
% VARARGIN --- For "circle", {center, radius}. For "rectangle",
% {margin to the boundary}. For "circle_array", {radius of each
% circle, distance between ajacent circles}. For "chess_box",
% {number of rows, number of columns}.
% Output:
% U --- Pattern generated as levelset.
%
% Example:
% dims = [300,400];
% center = [100,200]; radius = 100;
% phi1 = ac_SDF_2D('circle', dims, center, radius);
%
% margin = 100;
% phi2 = ac_SDF_2D('rectangle', dims, margin);
%
% radius = 80; circle_distance = 100;
% phi3 = ac_SDF_2D('circle_array', dims, radius, circle_distance);
%
% n_rows = 4; n_cols = 5;
% phi4 = ac_SDF_2D('chess_box', dims, n_rows, n_cols);
%
% figure;
% subplot(221); imshow(phi1,[]);
% subplot(222); imshow(phi2,[]);
% subplot(223); imshow(phi3,[]);
% subplot(224); imshow(phi4,[]);
% colormap(jet);
%%
if nargin < 2 || isempty(type)
type = 'circle';
end
switch lower(type)
case 'circle'
fcn = @circle_SDF;
case 'rectangle'
fcn = @rectangle_SDF;
case 'circle_array'
fcn = @circle_array_SDF;
case 'chess_box'
fcn = @chess_box_SDF;
otherwise
error('Unrecognised type %s.', upper(type));
end
phi = feval(fcn, dims, varargin{:});
%%
function phi = circle_SDF(dims, center, radius)
if nargin < 2
center = dims(2:-1:1)/2;
end
if nargin < 3
radius = 1/3*min(dims);
end
[X,Y] = meshgrid(1:dims(2),1:dims(1));
phi = radius - sqrt((X-center(1)).^2 + (Y-center(2)).^2);
%%
function phi = rectangle_SDF(dims, margin)
if nargin < 2
margin = 4;
end
top = margin;
left = margin;
bottom= dims(1) - margin + 1;
right = dims(2) - margin + 1;
phi = zeros(dims);
phi(top, left:right) = 1;
phi(bottom, left:right) = 1;
phi(top:bottom, left) = 1;
phi(top:bottom, right) = 1;
phi = -bwdist(phi);
phi(top:bottom, left:right) = - phi(top:bottom, left:right);
%%
function phi = circle_array_SDF(dims, radius, circle_dist)
% circle_dist - distance between two circles
phi = zeros(dims);
phi(round(circle_dist/2):circle_dist:dims(1),...
round(circle_dist/2):circle_dist:dims(2)) = 1;
phi = radius - bwdist(phi);
%%
function phi = chess_box_SDF(dims, n_row, n_col)
r = round(1:(dims(1)-1)/n_row:dims(1));
c = round(1:(dims(2)-1)/n_col:dims(2));
% build the signed matrix
s = ones(dims);
for j = 1:1:length(c)-1
col_idx = c(j):c(j+1)-1;
black_or_white = mod(j+1,2);
for i = 1:1:length(r)-1
black_or_white = ~black_or_white;
if black_or_white
s(r(i):r(i+1)-1, col_idx) = -1;
end
end
end
% build the zeros set
phi = zeros(dims);
for i = 1:length(c)
phi(:,c(i)) = 1;
end
for i = 1:length(r)
phi(r(i),:) = 1;
end
% build the SDF
phi = bwdist(phi);
phi = phi.*s;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于matlab的Convection2D内含数据集和源码.zip (15个子文件)
基于matlab的Convection2D内含数据集和源码
test2dConvectSparse.m 758B
convect2d.m 1KB
convect2d.m~ 1005B
distance_function2d.m 240B
div2d.m 196B
ac_SDF_2D.m 3KB
reinitBoundaries2d.m 209B
curvature.m 2KB
ac_reinit.m 1KB
images
convection2D.fig 32KB
sparsePoints.eps 9KB
contour_init.fig 7KB
sparsePoints.fig 4KB
test2dConvect.m 1KB
test2dConvectSparse.m~ 758B
共 15 条
- 1
资源评论
AI拉呱
- 粉丝: 2876
- 资源: 5511
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 电线线路残旧残坏检测22-YOLO(v5至v9)、COCO、CreateML、Darknet、Paligemma、TFRecord、VOC数据集合集.rar
- 基于抽象链条推理的大型语言模型高效工具使用方法研究
- Discord Clone 使用 React、ReactQuery、Tailwindcss、Redux、Socket IO、NodeJS、Express、MongoDB 和 Redis .zip
- 任务向量与算术操作:一种高效模型编辑方法
- 基于亚控KingFusion平台的燃气云平台应用
- decrypt-redis-2.8 源代码注释.zip
- 4511895645616541
- 基于工业数据库的油气田生产数据采集与管理应用
- CVE-2014-4210+Redis 未授权访问.zip
- 01111111111
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功