Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!news.aset.psu.edu!not-for-mail
From: dvt <dvt+usenet@psu.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to find Horizontal & Vertical Gradients?
Date: Mon, 07 Jan 2008 13:23:52 -0500
Organization: Penn State University, Center for Academic Computing
Lines: 43
Message-ID: <fltqnr$103u$1@f04n12.cac.psu.edu>
References: <fd664390-3ad5-4a89-9f65-a824f963677c@q39g2000hsf.googlegroups.com> <flovn7$102o$1@f04n12.cac.psu.edu> <flq4nh$81v$1@fred.mathworks.com>
NNTP-Posting-Host: nat2.arl.psu.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: f04n12.cac.psu.edu 1199730235 32894 128.118.40.77 (7 Jan 2008 18:23:55 GMT)
X-Complaints-To: usenet@f04n12.cac.psu.edu
NNTP-Posting-Date: Mon, 7 Jan 2008 18:23:55 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.9 (Windows/20071031)
In-Reply-To: <flq4nh$81v$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:444704


Selwyna Bas wrote:
> dvt <dvt+usenet@psu.edu> wrote in message <flovn7
> $102o$1@f04n12.cac.psu.edu>...

>> x = rand(10);
>> i = 3:8;
>> j = 3:8;
>> DH(i,j) = abs( x(i,j-2) + x(i,j+2) - 2*x(i,j) )  +...
>>      abs( x(i,j-1) - x(i,j+1) );
>> DV(i,j) =abs( x(i-2,j) + x(i+2,j) - 2*x(i,j) )  +...
>>      abs( x(i-1,j) - x(i+1,j) );
>> mask = ((DH+35)< DV);
>> G(i,j) = ( x(i,j-1) + x(i,j+1) ) /2 +...
>>      ( 2*x(i,j) - x(i,j-2) - x(i,j+2) )/4;
>> G = mask .* G;

> What is the meaning of G = mask .* G;

mask is a variable containing ones where DH+35<DV, zeros elsewhere. 
Multiplying mask by G leaves nonzero values in the matrix G wherever 
DH+35<DV, and zeros elsewhere. If you don't want zeros elsewhere, you 
can modify the definition of mask... maybe you'd rather have NaN?

> Also explain whats the neccesity of this?
>  x = rand(10);

x is a 10x10 random matrix; the code should calculate the gradient of 
that matrix. You shouldn't need that line, since you already have a 
matrix to operate upon. Note that the rest of the code assumes a 10x10 
matrix, since i and j are 3:8. You'll have to modify to suit your needs.

BTW, I don't like using i and j as variables, since I often use them in 
complex numbers. I usually use ii and jj instead.

>> Ga = zeros(10); %preallocate
>> DHa = Ga;
>> DVa = Ga;

oops... those three lines are unnecessary.

-- 
Dave
dvt at psu dot edu