Reputation: 1485
I have a thickness function that defined as
is a function that h(x)= 1
when the distance between the two surfaces is
within an acceptable range [d+f D-f]
, otherwise h(x)= 0
; D,d and f are const. x
is a value in phi
matrix. And other function c is defined as
Given d,D,f and phi
. How to compute the h(phi) and c(phi) by matlab? I would like to show my implementation. Could you see and give me some comment? Thanks
function h=compute_h(phi)
d=1;D=5;f=1;
h=zeros(size(phi));
idx1=find(phi<=d&phi>D);
idx2=find(phi>(d+f)&phi<(D-f));
idx3=find(phi>d&phi<=(d+f));
idx4=find(phi>(D-f)&phi<=D);
h(idx1)=0;
h(idx2)=1;
h(idx3)=1-((phi(idx3)-d-f)./f).^2;
h(idx4)=1-((phi(idx4)-D+f)./f).^2;
end
%% Defined phi
[Height Wide] = size(Img);% Assume size Img is 11 by 11
[xx yy] = meshgrid(1:Wide,1:Height);
phi = (sqrt(((xx - 3).^2 + (yy - 3).^2 )) - 3);
c=(1-compute_h(abs(phi)).*sign(phi).*sign(abs(phi)-D+f)
Upvotes: 0
Views: 38
Reputation: 3440
It looks like you're on the right track. You don't need to use find
though.
function C = StackOverflow(Img, d, D, f)
[Height, Width] = size(Img);% Assume size Img is 11 by 11
[xx, yy] = meshgrid(1:Width,1:Height);
phi = (sqrt(((xx - 3).^2 + (yy - 3).^2 )) - 3);
C = c(phi, d, D, f);
end
function H = h(x, d, D, f)
H = zeros(size(x));
c1 = (d + f < x) & (x < D - f);
c2 = (d < x) & (x <= d + f);
c3 = (D - f <= x) & (x <= D);
H(c1) = 1;
H(c2) = 1 - ((x(c2) - d - f)/(f)).^2;
H(c3) = 1 - ((x(c3) - D - f)/(f)).^2;
end
function C = c(phi, d, D, f)
c1 = (abs(phi) >= D - f);
c2 = (abs(phi) <= d + f);
C = zeros(size(phi));
C(c1) = (1 - h(abs(phi(c1)), d, D, f)) .* (sign(phi(c1)));
C(c2) = (1 - h(abs(phi(c1)), d, D, f)) .* (-sign(phi(c2)));
end
Upvotes: 2