Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Curl
Date: Tue, 21 Feb 2012 12:30:12 +0000 (UTC)
Organization: Univ of Edinburgh
Lines: 56
Message-ID: <ji02ok$lck$1@newscl01ah.mathworks.com>
References: <jhuk27$8og$1@newscl01ah.mathworks.com> <jhut4q$4d4$1@newscl01ah.mathworks.com> <jhvsac$388$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1329827412 21908 172.30.248.38 (21 Feb 2012 12:30:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 21 Feb 2012 12:30:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1590682
Xref: news.mathworks.com comp.soft-sys.matlab:758330

"arron" wrote in message <jhvsac$388$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jhut4q$4d4$1@newscl01ah.mathworks.com>...
> > "arron" wrote in message <jhuk27$8og$1@newscl01ah.mathworks.com>...
> > > Hi everyone. I am having trouble with the curl function in the following code:
> > > 
> > > -------------------------------------------------------------------
> > > Iter = 10;
> > > I = zeros(x,y);
> > > sigma = 3;
> > > G = fspecial('gaussian', 5, sigma);
> > > 
> > > for n = 1:Iter
> > > A = conv2(I, G, 'same');
> > > %B = curl of A.
> > > end
> > > -------------------------------------------------------------------
> > > 
> > > So not too complicated...but I would just like to find the curl of A. Can anyone help? Thanks!
> > - - - - - - - - -
> >   With 'I' set to all zeros, that would make A all zeros, so all its partial derivatives would also be zero.
> > 
> >   Assuming you don't really mean that, another objection is that curl is ordinarily meaningful only in a three-dimensional vector field.  However, not only is your A defined only in 2D space, it is not a vector field but only a scalar field and the curl concept cannot be applied with it.  If you want the curl of the gradient of A, that would always be identically zero.
> > 
> >   I think you should explain what you really have in mind so that we do not have to guess.
> > 
> > Roger Stafford
> 
> ---------------------------------------------------------------------
> 
> HI Roger, thanks for your reply. Ok you can see how I'm getting myself confused. Essentially, I want to create a magnetic field using the gradient of a greyscale image. So the algorithm would go:
> 
> 1. Turn image into a matrix (2d)
> 2. Take image derivatives to find the edges (like a sobel or canny filter)
> 3. Get the signed distance matrix
> 4. Convolve the image derivatives with the inverse of the signed distance matrix. This should give me the B field.

I understand what you are doing, as the previous poster said, you want the curl of A which is actually a 3D field. However, if A is constant along one dimension the curl can be found using something like:

% sample A over a grid
gridspace = 1;

% get suitible sample positions on an n x n grid  
[xi,yi] = meshgrid(minx:gridspace:maxx, miny:gridspace:maxy);

% get z-directed A at every point on the grid somehow (up to you)

% A is constant in z so curl formula reduced to:
%
% curl A = [dA/dy] i + [-dA/dx] j + 0 k
% Get numerical gradients of A in x and y directions
[delAdelx, delAdely] = gradient(interpA, gridspace, gridspace);

Bx = delAdely;
By = -delAdelx;

You need to look at the actual definition of the curl function to understand why this is so.