http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534
MATLAB Central Newsreader  Implementing Mean Curvature Flow (MCF) for an image in Matlab
Feed for thread: Implementing Mean Curvature Flow (MCF) for an image in Matlab
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Tue, 21 Jun 2011 14:30:19 +0000
Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#842176
Padmavathy Subramanian
Hi I need to write a Matlab program in which I need to be able to calulate the gaussian gradient of the image, followed by computation of the Mean Curvature Flow (MCF) using this formula :<br>
<br>
k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2)(Iy^2)]^ 3/2}<br>
<br>
I am able to calculate the gaussian gradient but I need some help to understand this formula and suggestions on how I could implement this using Matlab. Any guidance/ help that I can get on this is much appreciated!<br>
<br>
Thankyou!

Tue, 21 Jun 2011 18:22:04 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#842224
Roger Stafford
"Padmavathy Subramanian" wrote in message <itq9tr$4a3$1@newscl01ah.mathworks.com>...<br>
> Hi I need to write a Matlab program in which I need to be able to calulate the gaussian gradient of the image, followed by computation of the Mean Curvature Flow (MCF) using this formula :<br>
> <br>
> k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2)(Iy^2)]^ 3/2}<br>
> <br>
> I am able to calculate the gaussian gradient but I need some help to understand this formula and suggestions on how I could implement this using Matlab. Any guidance/ help that I can get on this is much appreciated!<br>
> <br>
> Thankyou!<br>
           <br>
That formula doesn't look right to me. Curvature should be inversely proportional to a distance measure, whereas your expression looks proportional to distance squared if I interpret its symbols correctly. My guess is that at least an addition sign has been lost in the denominator expression.<br>
<br>
Could you please give us a reference to the formula.<br>
<br>
Roger Stafford

Tue, 21 Jun 2011 20:40:18 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#842253
Roger Stafford
"Padmavathy Subramanian" wrote in message <itq9tr$4a3$1@newscl01ah.mathworks.com>...<br>
> Hi I need to write a Matlab program in which I need to be able to calulate the gaussian gradient of the image, followed by computation of the Mean Curvature Flow (MCF) using this formula :<br>
> <br>
> k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2)(Iy^2)]^ 3/2}<br>
> <br>
> I am able to calculate the gaussian gradient but I need some help to understand this formula and suggestions on how I could implement this using Matlab. Any guidance/ help that I can get on this is much appreciated!<br>
> <br>
> Thankyou!<br>
        <br>
Yes, that formula you gave is undoubtedly lacking an addition sign, Padmavathy. It should be (in my opinion):<br>
<br>
k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2) + (Iy^2)]^3/2}<br>
<br>
or if Ix, Iy, Ixx, Ixy, and Iyy are matrices, the matlab format would be:<br>
<br>
k = (Ix.^2.*Iyy2*Ix.*Iy.*Ixy+Iy.^2.*Ixx)./(Ix.^2+Iy.^2).^(3/2);<br>
<br>
where Ix, Iy are partial first derivatives (gradient components) and Ixx, Ixy, and Iyy are partial second derivatives.<br>
<br>
This can be interpreted as the curvature of contours of constant intensity:<br>
<br>
I(x,y) = c.<br>
<br>
The sign of k will be positive if the contour bends toward the area of lower intensity and negative otherwise.<br>
<br>
You can derive the formula by the appropriate total and partial differentiation of I(x,y) = c and applying the wellknown formula in calculus for the curvature of a curve.<br>
<br>
I presume the above is what is meant by "mean curvature flow" as applied to images, though I am unfamiliar with it by that name.<br>
<br>
Roger Stafford

Thu, 23 Jun 2011 13:17:04 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#842598
Padmavathy Subramanian
Hi Roger, <br>
<br>
Sorry about the typo error in the formula. The formula you gave is correct. <br>
<br>
Below are the steps that I calculated in my matlab program<br>
1. Compute Ix and Iy <br>
Ix=imfilter(I,hx,'replicate','conv');<br>
Iy=imfilter(I,hy,'replicate','conv');<br>
where hx and hy are 2D gaussian kernels along x direction and y direction <br>
<br>
2. Compute Ixx, Ixy and Iyy <br>
I get stuck in calulating these three matrices and I need advise on how to do it. <br>
<br>
<br>
"Roger Stafford" wrote in message <itqvji$et2$1@newscl01ah.mathworks.com>...<br>
> "Padmavathy Subramanian" wrote in message <itq9tr$4a3$1@newscl01ah.mathworks.com>...<br>
> > Hi I need to write a Matlab program in which I need to be able to calulate the gaussian gradient of the image, followed by computation of the Mean Curvature Flow (MCF) using this formula :<br>
> > <br>
> > k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2)(Iy^2)]^ 3/2}<br>
> > <br>
> > I am able to calculate the gaussian gradient but I need some help to understand this formula and suggestions on how I could implement this using Matlab. Any guidance/ help that I can get on this is much appreciated!<br>
> > <br>
> > Thankyou!<br>
>         <br>
> Yes, that formula you gave is undoubtedly lacking an addition sign, Padmavathy. It should be (in my opinion):<br>
> <br>
> k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2) + (Iy^2)]^3/2}<br>
> <br>
> or if Ix, Iy, Ixx, Ixy, and Iyy are matrices, the matlab format would be:<br>
> <br>
> k = (Ix.^2.*Iyy2*Ix.*Iy.*Ixy+Iy.^2.*Ixx)./(Ix.^2+Iy.^2).^(3/2);<br>
> <br>
> where Ix, Iy are partial first derivatives (gradient components) and Ixx, Ixy, and Iyy are partial second derivatives.<br>
> <br>
> This can be interpreted as the curvature of contours of constant intensity:<br>
> <br>
> I(x,y) = c.<br>
> <br>
> The sign of k will be positive if the contour bends toward the area of lower intensity and negative otherwise.<br>
> <br>
> You can derive the formula by the appropriate total and partial differentiation of I(x,y) = c and applying the wellknown formula in calculus for the curvature of a curve.<br>
> <br>
> I presume the above is what is meant by "mean curvature flow" as applied to images, though I am unfamiliar with it by that name.<br>
> <br>
> Roger Stafford

Fri, 24 Jun 2011 06:16:05 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#842717
Roger Stafford
"Padmavathy Subramanian" wrote in message <itvecg$3pn$1@newscl01ah.mathworks.com>...<br>
> Below are the steps that I calculated in my matlab program<br>
> 1. Compute Ix and Iy <br>
> Ix=imfilter(I,hx,'replicate','conv');<br>
> Iy=imfilter(I,hy,'replicate','conv');<br>
> where hx and hy are 2D gaussian kernels along x direction and y direction <br>
> <br>
> 2. Compute Ixx, Ixy and Iyy <br>
> I get stuck in calulating these three matrices and I need advise on how to do it. <br>
         <br>
For Ixx, Ixy, and Iyy I would try using the three second partial derivatives of the 2D gaussian distribution function to make gaussian kernels hxx, hxy, and hyy in a manner analogous to the way you created hx and hy. Guanglei Xiong has a FEX file written in 2005 which finds the gaussian gradient with hx and hy, probably much as you have done. If you follow that example but use second partial derivatives instead of first partial derivatives, I would think you could create Ixx, Ixy, and Iyy without any great difficulty. I would guess you could use the same sigma as in Ix and Iy. Of course you will have to arrange that everything is properly scaled.<br>
<br>
You probably already have this FEX link, but in case you don't, it is located at:<br>
<br>
<a href="http://www.mathworks.com/matlabcentral/fileexchange/8060gradientusingfirstorderderivativeofgaussian/content/gaussgradient/gaussgradient.m">http://www.mathworks.com/matlabcentral/fileexchange/8060gradientusingfirstorderderivativeofgaussian/content/gaussgradient/gaussgradient.m</a><br>
<br>
Roger Stafford

Thu, 30 Jun 2011 16:35:27 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#843565
Padmavathy Subramanian
Hi Roger, <br>
Thankyou for the suggestion!! <br>
I understand how the gaussian function works by itself but i'm not able to relate it to the matlab codes and how do they then derive at the gaussian kernel ?<br>
Any explanation or help is much appreciated.. !<br>
<br>
"Roger Stafford" wrote in message <iu1a35$k5o$1@newscl01ah.mathworks.com>...<br>
> "Padmavathy Subramanian" wrote in message <itvecg$3pn$1@newscl01ah.mathworks.com>...<br>
> > Below are the steps that I calculated in my matlab program<br>
> > 1. Compute Ix and Iy <br>
> > Ix=imfilter(I,hx,'replicate','conv');<br>
> > Iy=imfilter(I,hy,'replicate','conv');<br>
> > where hx and hy are 2D gaussian kernels along x direction and y direction <br>
> > <br>
> > 2. Compute Ixx, Ixy and Iyy <br>
> > I get stuck in calulating these three matrices and I need advise on how to do it. <br>
>          <br>
> For Ixx, Ixy, and Iyy I would try using the three second partial derivatives of the 2D gaussian distribution function to make gaussian kernels hxx, hxy, and hyy in a manner analogous to the way you created hx and hy. Guanglei Xiong has a FEX file written in 2005 which finds the gaussian gradient with hx and hy, probably much as you have done. If you follow that example but use second partial derivatives instead of first partial derivatives, I would think you could create Ixx, Ixy, and Iyy without any great difficulty. I would guess you could use the same sigma as in Ix and Iy. Of course you will have to arrange that everything is properly scaled.<br>
> <br>
> You probably already have this FEX link, but in case you don't, it is located at:<br>
> <br>
> <a href="http://www.mathworks.com/matlabcentral/fileexchange/8060gradientusingfirstorderderivativeofgaussian/content/gaussgradient/gaussgradient.m">http://www.mathworks.com/matlabcentral/fileexchange/8060gradientusingfirstorderderivativeofgaussian/content/gaussgradient/gaussgradient.m</a><br>
> <br>
> Roger Stafford

Fri, 01 Jul 2011 12:50:28 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#843718
Padmavathy Subramanian
Given <br>
Ix=imfilter(I,hx,'replicate','conv');<br>
Iy=imfilter(I,hy,'replicate','conv');<br>
<br>
For Ixx Iyy, i use below formulas<br>
Ixx = imfilter(Ix,hx,'replicate','conv');<br>
Iyy = imfilter(Iy,hy,'replicate','conv');<br>
<br>
For Ixy, i use two formulas<br>
Ixy1 = imfilter(Ix,hy,'replicate','conv'); <br>
Ixy2 = imfilter(Iy,hx,'replicate','conv'); <br>
<br>
But Ixy1 and Ixy2 are different. Please advise if i use the formula correctly.<br>
<br>
Thanks<br>
<br>
<br>
"Padmavathy Subramanian" wrote in message <iui8kf$k1h$1@newscl01ah.mathworks.com>...<br>
> Hi Roger, <br>
> Thankyou for the suggestion!! <br>
> I understand how the gaussian function works by itself but i'm not able to relate it to the matlab codes and how do they then derive at the gaussian kernel ?<br>
> Any explanation or help is much appreciated.. !<br>
> <br>
> "Roger Stafford" wrote in message <iu1a35$k5o$1@newscl01ah.mathworks.com>...<br>
> > "Padmavathy Subramanian" wrote in message <itvecg$3pn$1@newscl01ah.mathworks.com>...<br>
> > > Below are the steps that I calculated in my matlab program<br>
> > > 1. Compute Ix and Iy <br>
> > > Ix=imfilter(I,hx,'replicate','conv');<br>
> > > Iy=imfilter(I,hy,'replicate','conv');<br>
> > > where hx and hy are 2D gaussian kernels along x direction and y direction <br>
> > > <br>
> > > 2. Compute Ixx, Ixy and Iyy <br>
> > > I get stuck in calulating these three matrices and I need advise on how to do it. <br>
> >          <br>
> > For Ixx, Ixy, and Iyy I would try using the three second partial derivatives of the 2D gaussian distribution function to make gaussian kernels hxx, hxy, and hyy in a manner analogous to the way you created hx and hy. Guanglei Xiong has a FEX file written in 2005 which finds the gaussian gradient with hx and hy, probably much as you have done. If you follow that example but use second partial derivatives instead of first partial derivatives, I would think you could create Ixx, Ixy, and Iyy without any great difficulty. I would guess you could use the same sigma as in Ix and Iy. Of course you will have to arrange that everything is properly scaled.<br>
> > <br>
> > You probably already have this FEX link, but in case you don't, it is located at:<br>
> > <br>
> > <a href="http://www.mathworks.com/matlabcentral/fileexchange/8060gradientusingfirstorderderivativeofgaussian/content/gaussgradient/gaussgradient.m">http://www.mathworks.com/matlabcentral/fileexchange/8060gradientusingfirstorderderivativeofgaussian/content/gaussgradient/gaussgradient.m</a><br>
> > <br>
> > Roger Stafford

Sat, 02 Jul 2011 04:03:09 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#843822
Roger Stafford
"Padmavathy Subramanian" wrote in message <iui8kf$k1h$1@newscl01ah.mathworks.com>...<br>
> Hi Roger, <br>
> Thankyou for the suggestion!! <br>
> I understand how the gaussian function works by itself but i'm not able to relate it to the matlab codes and how do they then derive at the gaussian kernel ?<br>
> Any explanation or help is much appreciated.. !<br>
          <br>
The following is my version of what I believe you need for the five gaussian kernels in your curvature problem.<br>
<br>
The notion of a derivative implies the presence of a distance measure. In this code I have assumed that the distance between pixels is to be regarded as a unit distance. You should be able to continue with that assumption up to the evaluation of curvature. At this point if you wish a different unit of distance, you can easily rescale that initial curvature value, which is inversely proportional to distance.<br>
<br>
You will notice that initial evaluations below of the five kernels, hxx, hxy, hyy, hx, and hy are subjected to a rescaling and adjustment process. This is because the theoretical forms will possess a certain amount of error due to its use with discrete points over a finite span. After these corrections the kernels should have the property that any image intensity function of the quadratic form<br>
<br>
I(x,y) = A*x^2/2 + B*x*y + C*y^2/2 + D*x + E*y + F<br>
<br>
after convolution with these respective five kernels will result in the five partial derivatives, Ixx = A, Ixy = B, Iyy = C, Ix = D, and Iy = E at the point x = 0, y = 0, as you would expect, provided the kernel does not extend beyond the image boundary. The quantities x and y here are considered to be in units of pixel distance.<br>
<br>
I don't know the number of kernel pixels you have in mind, but I recommend that the standard deviation, sigma, you use be onethird or less of the pixel distance, m, from the center to the edge of the square kernel. The kernels will have a 2*m+1 by 2*m+1 size.<br>
<br>
Here is the kernel generation code:<br>
<br>
sigma = 4; % Standard deviation  chosen by the user<br>
m = 12; % Form kernels of size 2*m+1 by 2*m+1  also chosen by user<br>
[x,y] = meshgrid(m:m);<br>
h = exp((x.^2+y.^2)/(2*sigma^2)); % Start with 2D gaussian distrib.<br>
hx = x.*h;<br>
hx = hx/(sum(sum(x.*hx))); % Rescale hx appropriately<br>
hy = hx.';<br>
hxx = x.^2.*h;<br>
t = [sum(sum(x.^2.*hxx)),sum(sum(x.^2.*h)); ...<br>
sum(sum(y.^2.*hxx)),sum(sum(y.^2.*h))]\[2;0];<br>
hxx = t(1)*hxx+t(2)*h; % Use approp. lin. comb. of x.^2.*h and h<br>
hyy = hxx.';<br>
hxy = x.*y.*h;<br>
hxy = hxy/sum(sum(x.*y.*hxy)); % Rescale hxy<br>
<br>
Notice that the normalizing factor, 2*pi*sigma^2, was not used in h above because subsequent rescaling made that superfluous.<br>
<br>
I would recommend you use surf(x,y,hx), surf(x,y,hxx), etc. to visualize these five kernels. You will notice that if sigma is chosen too large, these surface kernel plots will begin to show an increasing departure from an ideal shape.<br>
<br>
Roger Stafford

Sun, 03 Jul 2011 04:45:24 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#843879
Roger Stafford
"Roger Stafford" wrote in message <ium59t$iaj$1@newscl01ah.mathworks.com>...<br>
> sigma = 4; % Standard deviation  chosen by the user<br>
> m = 12; % Form kernels of size 2*m+1 by 2*m+1  also chosen by user<br>
> [x,y] = meshgrid(m:m);<br>
> h = exp((x.^2+y.^2)/(2*sigma^2)); % Start with 2D gaussian distrib.<br>
> hx = x.*h;<br>
> hx = hx/(sum(sum(x.*hx))); % Rescale hx appropriately<br>
> hy = hx.';<br>
> hxx = x.^2.*h;<br>
> t = [sum(sum(x.^2.*hxx)),sum(sum(x.^2.*h)); ...<br>
> sum(sum(y.^2.*hxx)),sum(sum(y.^2.*h))]\[2;0];<br>
> hxx = t(1)*hxx+t(2)*h; % Use approp. lin. comb. of x.^2.*h and h<br>
> hyy = hxx.';<br>
> hxy = x.*y.*h;<br>
> hxy = hxy/sum(sum(x.*y.*hxy)); % Rescale hxy<br>
          <br>
The following code produces the same kernels, hx, hy, hxx, hyy, and hxy, (within round off error) as in the previous code but does so with fewer computations, in case you are interested in efficiency in generating kernels.<br>
<br>
sigma = 4; % Standard deviation  chosen by the user<br>
m = 12; % Form kernels of size 2*m+1 by 2*m+1  also chosen by user<br>
x = m:m;<br>
h = exp(x.^2/(2*sigma^2));<br>
a = sum(h);<br>
b = sum(x.^2.*h);<br>
c = sum(x.^4.*h);<br>
d = 2/(a*cb^2);<br>
e = b/a*d;<br>
t = x.*h/b;<br>
hxy = t.'*t;<br>
hx = h.'*(t/(a));<br>
hy = hx.';<br>
hxx = h.'*(d*x.^2.*he*h);<br>
hyy = hxx.';<br>
<br>
Roger Stafford

Wed, 06 Jul 2011 13:57:07 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#844316
Padmavathy Subramanian
Thank you so much for your code.<br>
<br>
I have verified with my code and both can create a similar Gaussian kernels hx,hy,hxx,hxy,hyy.<br>
<br>
Now, i can use these kernels to convolute with the input image I to generate Ix,Iy,Ixx,Ixy,Iyy.<br>
<br>
What i notice is Ix And Iy contains a lot of 0s. For example at i=5,j=5, Ix(5,5)=Iy(5,5)=0. Therefore, what puzzles me is how the curvature can be computed, given the below formula:<br>
k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2) + (Iy^2)]^3/2}<br>
<br>
because now the denominator is 0 (Ix^2+Iy^2).<br>
<br>
I really need an explanation for this. Please help!<br>
<br>
<br>
<br>
<br>
"Roger Stafford" wrote in message <iuos54$ddp$1@newscl01ah.mathworks.com>...<br>
> "Roger Stafford" wrote in message <ium59t$iaj$1@newscl01ah.mathworks.com>...<br>
> > sigma = 4; % Standard deviation  chosen by the user<br>
> > m = 12; % Form kernels of size 2*m+1 by 2*m+1  also chosen by user<br>
> > [x,y] = meshgrid(m:m);<br>
> > h = exp((x.^2+y.^2)/(2*sigma^2)); % Start with 2D gaussian distrib.<br>
> > hx = x.*h;<br>
> > hx = hx/(sum(sum(x.*hx))); % Rescale hx appropriately<br>
> > hy = hx.';<br>
> > hxx = x.^2.*h;<br>
> > t = [sum(sum(x.^2.*hxx)),sum(sum(x.^2.*h)); ...<br>
> > sum(sum(y.^2.*hxx)),sum(sum(y.^2.*h))]\[2;0];<br>
> > hxx = t(1)*hxx+t(2)*h; % Use approp. lin. comb. of x.^2.*h and h<br>
> > hyy = hxx.';<br>
> > hxy = x.*y.*h;<br>
> > hxy = hxy/sum(sum(x.*y.*hxy)); % Rescale hxy<br>
>           <br>
> The following code produces the same kernels, hx, hy, hxx, hyy, and hxy, (within round off error) as in the previous code but does so with fewer computations, in case you are interested in efficiency in generating kernels.<br>
> <br>
> sigma = 4; % Standard deviation  chosen by the user<br>
> m = 12; % Form kernels of size 2*m+1 by 2*m+1  also chosen by user<br>
> x = m:m;<br>
> h = exp(x.^2/(2*sigma^2));<br>
> a = sum(h);<br>
> b = sum(x.^2.*h);<br>
> c = sum(x.^4.*h);<br>
> d = 2/(a*cb^2);<br>
> e = b/a*d;<br>
> t = x.*h/b;<br>
> hxy = t.'*t;<br>
> hx = h.'*(t/(a));<br>
> hy = hx.';<br>
> hxx = h.'*(d*x.^2.*he*h);<br>
> hyy = hxx.';<br>
> <br>
> Roger Stafford

Wed, 06 Jul 2011 16:29:10 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#844351
Roger Stafford
"Padmavathy Subramanian" wrote in message <iv1pjj$62o$1@newscl01ah.mathworks.com>...<br>
> Thank you so much for your code.<br>
> I have verified with my code and both can create a similar Gaussian kernels hx,hy,hxx,hxy,hyy.<br>
> Now, i can use these kernels to convolute with the input image I to generate Ix,Iy,Ixx,Ixy,Iyy.<br>
> What i notice is Ix And Iy contains a lot of 0s. For example at i=5,j=5, Ix(5,5)=Iy(5,5)=0. Therefore, what puzzles me is how the curvature can be computed, given the below formula:<br>
> k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2) + (Iy^2)]^3/2}<br>
> because now the denominator is 0 (Ix^2+Iy^2).<br>
> I really need an explanation for this. Please help!<br>
         <br>
I have no way of advising you on that because I have not seen the data you are processing. However I find it rather strange that Ix and Iy should both be exactly zero at the same point in the image. Are you sure about that? Perhaps they simply look zero in a display because they are small in comparison to other values being displayed along with them. Try using "format long" to display individual values of Ix and Iy at those same points. I venture to guess they are not exactly zero.<br>
<br>
Also bear in mind that because you found it necessary to do filtering with gaussian kernels, the results are bound to only be approximate. You may have to experiment with choosing optimum sigma values and best values for the range of the kernels (what I called 'm') to get the best filtering.<br>
<br>
In evaluating the accuracy of these gaussian kernels, I urge you to make that test I described earlier. Create an artificial image of a quadratic form:<br>
<br>
I(x,y) = A(xx0)^2/2+B*(xx0)*(yy0)+C*(yy0)^2/2+D*(xx0)+E*(yy0)+F<br>
<br>
for some point (x0,y0) and for various arbitrary values of A, B, C, D, E, and F, and see how close Ixx(x0,y0), Ixy(x0,y0), Iyy(x0,y0), Ix(x0,y0), and Iy(x0,y0) are respectively to A, B, C, D, and E. I designed the code I wrote for you to do well on such a test.<br>
<br>
Roger Stafford

Wed, 06 Jul 2011 16:49:16 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#844356
ImageAnalyst
On Jul 6, 9:57 am, "Padmavathy Subramanian" <sso...@gmail.com> wrote:<br>
> Thank you so much for your code.<br>
> I have verified with my code and both can create a similar Gaussian kernels hx,hy,hxx,hxy,hyy.<br>
> Now, i can use these kernels to convolute with the input image I to generate Ix,Iy,Ixx,Ixy,Iyy.<br>
> What i notice is Ix And Iy contains a lot of 0s. For example at i=5,j=5, Ix(5,5)=Iy(5,5)=0. Therefore, what puzzles me is how the curvature can be computed, given the below formula:<br>
> k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2) + (Iy^2)]^3/2}<br>
<br>
I've only briefly dived into understanding this thread so perhaps I<br>
shouldn't say anything but...it appears that your lx and lx are 2D<br>
arrays so make sure you use the "dot" form of the operations if you<br>
want to perform the operation elementbyelement, for example lx.^2<br>
and not lx^2, and use ./ and not /. I'm also not sure why you're<br>
stuffing the numerator and denominator into cells with {} rather than<br>
using() but maybe that's just an equation like you'd see in a math<br>
book and not real MATLAB code (is so, ignore what I said).<br>
k = (Ix .^ 2 .* Iyy  2 .* Ix .* Iy .* Ixy + Iy .^ 2 .* Ixx) / (Ix .^<br>
2 + Iy .^ 2) .^ (3/2)

Sat, 09 Jul 2011 16:04:10 +0000
Re: Implementing Mean Curvature Flow (MCF) for an image in Matlab
http://www.mathworks.com/matlabcentral/newsreader/view_thread/309534#844859
Padmavathy Subramanian
Hi Roger, <br>
<br>
There is a region in the image with only 1 colour (white in this case) and that's why Ix = Iy = 0 exactly....<br>
<br>
<br>
"Roger Stafford" wrote in message <iv22gm$4be$1@newscl01ah.mathworks.com>...<br>
> "Padmavathy Subramanian" wrote in message <iv1pjj$62o$1@newscl01ah.mathworks.com>...<br>
> > Thank you so much for your code.<br>
> > I have verified with my code and both can create a similar Gaussian kernels hx,hy,hxx,hxy,hyy.<br>
> > Now, i can use these kernels to convolute with the input image I to generate Ix,Iy,Ixx,Ixy,Iyy.<br>
> > What i notice is Ix And Iy contains a lot of 0s. For example at i=5,j=5, Ix(5,5)=Iy(5,5)=0. Therefore, what puzzles me is how the curvature can be computed, given the below formula:<br>
> > k = {[(Ix^2)(Iyy)]  [2IxIyIxy] + [(Iy^2)(Ixx)]} / {[(Ix^2) + (Iy^2)]^3/2}<br>
> > because now the denominator is 0 (Ix^2+Iy^2).<br>
> > I really need an explanation for this. Please help!<br>
>          <br>
> I have no way of advising you on that because I have not seen the data you are processing. However I find it rather strange that Ix and Iy should both be exactly zero at the same point in the image. Are you sure about that? Perhaps they simply look zero in a display because they are small in comparison to other values being displayed along with them. Try using "format long" to display individual values of Ix and Iy at those same points. I venture to guess they are not exactly zero.<br>
> <br>
> Also bear in mind that because you found it necessary to do filtering with gaussian kernels, the results are bound to only be approximate. You may have to experiment with choosing optimum sigma values and best values for the range of the kernels (what I called 'm') to get the best filtering.<br>
> <br>
> In evaluating the accuracy of these gaussian kernels, I urge you to make that test I described earlier. Create an artificial image of a quadratic form:<br>
> <br>
> I(x,y) = A(xx0)^2/2+B*(xx0)*(yy0)+C*(yy0)^2/2+D*(xx0)+E*(yy0)+F<br>
> <br>
> for some point (x0,y0) and for various arbitrary values of A, B, C, D, E, and F, and see how close Ixx(x0,y0), Ixy(x0,y0), Iyy(x0,y0), Ix(x0,y0), and Iy(x0,y0) are respectively to A, B, C, D, and E. I designed the code I wrote for you to do well on such a test.<br>
> <br>
> Roger Stafford