Curl of Gaussian image derivatives matlab

In summary, the conversation is about creating a magnetic field from an image contour using a Gaussian derivative function. The code involves calculating first-order derivatives in the x and y directions, finding the cross product of these derivatives, and using them to update the vector field to calculate the magnetic field. The person asking for help is facing difficulties with taking the curl of the image derivatives and is seeking tips and assistance from the forum.
  • #1
arronslacey
9
0
Hi guys, I am trying to create a magnetic field from an image contour and an attempt to create an active contour model. I have a function which takes the image derivative via a Guassian:

Code:
    function J=ImageDerivatives2D(I,sigma,type)
  % Gaussian based image derivatives
  %
  %  J=ImageDerivatives2D(I,sigma,type)
  %
  % inputs,
  %   I : The 2D image
  %   sigma : Gaussian Sigma
  %   type : 'x', 'y', 'xx', 'xy', 'yy'
  %
  % outputs,
  %   J : The image derivative
  %
% Make derivatives kernels
[x,y]=ndgrid(floor(-3*sigma):ceil(3*sigma),floor(-3*sigma):ceil(3*sigma));
switch(type)
    case 'x'
        DGauss=-(x./(2*pi*sigma^4)).*exp(-(x.^2+y.^2)/(2*sigma^2));
    case 'y'
        DGauss=-(y./(2*pi*sigma^4)).*exp(-(x.^2+y.^2)/(2*sigma^2));
    case 'xx'
        DGauss = 1/(2*pi*sigma^4) * (x.^2/sigma^2 - 1) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
    case {'xy','yx'}
        DGauss = 1/(2*pi*sigma^6) * (x .* y)           .* exp(-(x.^2 + y.^2)/(2*sigma^2));
    case 'yy'
        DGauss = 1/(2*pi*sigma^4) * (y.^2/sigma^2 - 1) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
end        
J = conv2(I,DGauss,'same');
and now i need to take the curl of those image derivatives to get the pseudo magnetic field. having a bit of trouble with that though:

Code:
   % Squared magnitude of force field
  Fx= Fext(:,:,1);
  Fy= Fext(:,:,2);
% Calculate magnitude
sMag = Fx.^2+ Fy.^2;
% Set new vector-field to initial field
u=Fx;  v=Fy;
for i=1:Iterations,
  % First order image derivatives
  Uxx=ImageDerivatives2D(u,Sigma,'x');
  Uyy=ImageDerivatives2D(u,Sigma,'y');
    Vxx=ImageDerivatives2D(v,Sigma,'x');
    Vyy=ImageDerivatives2D(v,Sigma,'y');
    % Compute curl and update vector field
    u = u + cross(Uxx,Uyy,3);
    v = v + cross(Vxx,Vyy,3);
  end
Fext(:,:,1) = u;
Fext(:,:,2) = v;
anyone have any tips as the second script does not work. i can to the divergence and laplacian easily as they are just first and second derivatives, but the curl is proving a bit of a problem. Any help would be great thanks!
 
Physics news on Phys.org
  • #2


Thank you for sharing your progress and asking for help. It seems like you are on the right track with your approach to creating a magnetic field from an image contour using the Gaussian derivative function. However, I can see that you are running into some difficulties with taking the curl of the image derivatives.

Taking the curl of a vector field involves finding the cross product of the first-order derivatives in the x and y directions. In your code, you have correctly calculated these derivatives (Uxx, Uyy, Vxx, Vyy) using the Gaussian derivative function. However, in order to take the curl, you will need to find the cross product using the "cross" function in MATLAB.

The syntax for the cross product function is as follows:

C = cross(A,B,dim)

where A and B are the vectors to be crossed, and dim specifies the dimension along which the cross product is taken. In your case, you will need to find the cross product of the first-order derivatives Uxx and Uyy, and Vxx and Vyy, along the third dimension (dim=3).

Once you have calculated the cross product, you can update your vector field (u and v) by adding it to the existing field. This will give you the updated vector field which can be used to calculate the magnetic field.

I hope this helps you in solving your problem. If you continue to face difficulties, please do not hesitate to reach out for further assistance. Good luck with your research!
 

FAQ: Curl of Gaussian image derivatives matlab

What is the "Curl" in the context of Gaussian image derivatives in Matlab?

The "Curl" refers to a mathematical operation that measures the rotation or circular motion of a vector field. In the context of Gaussian image derivatives in Matlab, it is used to analyze the direction and magnitude of the change in intensity of an image.

How are Gaussian image derivatives calculated in Matlab?

Gaussian image derivatives in Matlab are calculated using the "imgradientxy" function, which takes in an image as input and returns the x and y components of the gradient at each pixel. These components are then used to calculate the magnitude and direction of the gradient.

What is the purpose of using Gaussian image derivatives?

The purpose of using Gaussian image derivatives is to enhance or extract features from an image. By analyzing the intensity changes in different directions, it is possible to identify edges and other important features in an image.

What are the advantages of using Gaussian image derivatives over other methods?

Gaussian image derivatives offer several advantages over other methods, including noise reduction, accurate localization of edges, and the ability to handle images with varying intensity levels. They also provide a smooth and continuous representation of the image, making it easier to analyze and process.

How can I use Gaussian image derivatives in Matlab for image processing applications?

Gaussian image derivatives can be used for various image processing applications, such as edge detection, image segmentation, and feature extraction. By using the gradient information, it is possible to identify and isolate specific features in an image, which can then be further processed or analyzed.

Similar threads

Replies
10
Views
2K
Replies
2
Views
2K
Replies
3
Views
3K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
7
Views
1K
Back
Top