-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathblobi.m
54 lines (49 loc) · 1.37 KB
/
blobi.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function varargout=blobi(Nj,plotit)
% varargout=blobi(Nj,plotit)
%
% Makes an embedded indicator function for a random blob.
%
% INPUT:
%
% Nj Smoothness measure [default: 3]
% plotit 1 Will make a plot
% 0 Will not make a plot
%
% OUTPUT:
%
% I The indicator function
%
% Last modified by fjsimons-at-alum.mit.edu, 01/26/2023
% Defaults
defval('Nj',3)
defval('plotit',0)
% Random smoothish blob, only make one, really could use RANDCIRC, but hey
[xb,yb]=blob(1,Nj);
% Embedding and grid coarseness
emb=4; grd=1;
rx=range(xb); ry=range(yb);
% Get some idea of the blob-dependent thus random spacing
%x=linspace(min(xb)-rx/4,max(xb)+rx/emb,length(xb)/2);
%y=linspace(min(yb)-ry/4,max(yb)+ry/emb,length(yb)/2);
% The above two lines always yield the same dimension
x=min(xb)-rx/4:grd*median(abs(diff(xb))):max(xb)+rx/emb;
y=min(yb)-ry/4:grd*median(abs(diff(yb))):max(yb)+ry/emb;
if isempty(x) || isempty(y); kb; error('refine grid'); end
% Make grid
[X,Y]=meshgrid(x,y);
% Find the inside of the blob
I=inpolygon(X,Y,xb,yb);
if plotit==1
imagesc(x,y,I)
hold on
plot(xb,yb,'k','LineWidth',2)
hold off
axis image xy
longticks(gca,2)
t=title(sprintf('%i x %i / %i%% coverage',...
size(I,1),size(I,2),round(100*sum(I(:))/prod(size(I)))));
movev(t,ry/emb/10)
end
% Optional output
varns={I};
varargout=varns(1:nargout);