-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathduck.m
60 lines (50 loc) · 924 Bytes
/
duck.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
55
56
57
58
59
60
function varargout=duck(p,t)
% [d,D]=DUCK(p,t)
%
% INPUT:
%
% p A color threshold [defaulted]
% t A cutoff row [defaulted]
%
% OUTPUT:
%
% d The duck's contour
% D The duck's image
%
% SEE ALSO:
%
% PUSS
%
% Last modified by fjsimons-at-alum.mit.edu, 08/10/2022
% Where I keep the file
fname=fullfile(getenv('EPS'),'duck.mat');
if exist(fname,'file')
load(fname)
else
defval('p',30)
defval('t',417)
% Get the image
D=imread(fullfile(getenv('EPS'),'duck.jpg'));
% Black and white
D(D>p)=255;
D(D<=p)=0;
% Reflection point
D(t:end,:,:)=deal(255);
% Sum it all up
D=nanmean(double(D),3);
% Contour
d=contourc(D,[255 255]);
d=d(:,2:end)';
% Save
save(fullfile(getenv('EPS'),'duck.mat'),'d','D')
end
% Optional output
if nargout==0
image(D)
colormap(gray(2))
hold on
plot(d(:,1),d(:,2),'y','LineWidth',2)
hold off
end
varns={d,D};
varargout=varns(1:nargout);