Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Matrices -> Building weighted kernels

Posted on 2011-02-16
Medium Priority
893 Views
Right, I'll admit I am no good with matrix math. No matter how many time I study it, it does not stay in my brain.

So, I am trying to build weighted kernels for some image processing. They are 3x3 kernels, and I need them for the various directions listed in the code section (8 different directions). I have one for West, just need to learn how to do the others.

This is for use with Processing and Jama, which is fun enough not having a proper IDE.

Thanks,
Ryan
``````Matrix kernel =
new Matrix(new double[][]{{ 1, 1, 0},
{ 0, 0, 0},
{-1,-1, 0}}).times(0.25); // West

Matrix[] computeCost(PImage image) {

//
// @todo Create kernels
// @note Use constants NW, N, NE, W, E, SW, S, and SE (see above)
//       If you don't use these properly, 'neighborCost' will not work correctly
//

//
// @todo Compute the cost for each RGB band
//

//
// the cost matrix is defined as the magnitude of the cost over the RGB bands
// and is negated and normalized with respect the maximum value
//

return cost;
}

//
// Different directions (do not edit these values)
//
static final int NW = 0; // These values are ordered top to bottom, left to right as in:
static final int N  = 1; //
static final int NE = 2; //  NW  N  NE
static final int W  = 3; //    \ | /
static final int E  = 4; // W -  ?  - E
static final int SW = 5; //    / | \
static final int S  = 6; //  SW  S  SE
static final int SE = 7; //
``````
0
Question by:rossryan
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 31

Accepted Solution

GwynforWeb earned 2000 total points
ID: 34915861
Without knowing the full details of what the kernels are wanted to do I suggest the following

for  N
new Matrix(new double[][]{{ 1, 0, -1},
{ 1, 0, -1},
{ 0, 0,  0}}).times(0.25); // North

for NW
new Matrix(new double[][]{{ 0, -1, 0},
{ 1, 0, -1},
{ 0, 1,  0}}).times(0.25); // North West

0

LVL 31

Expert Comment

ID: 34916035
....  I can clearly see you are detecting directional gradients/edges but I am not sure what convention you are adopting for differentiating  NE form SW etc.  I have guessed and am probably right, but not sure.
0

Author Comment

ID: 34921208
Hmm. The TA is of the opinion that rotating the matrices by 90 degree increments should be enough.

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This is a research brief on the potential colonization of humans on Mars.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
###### Suggested Courses
Course of the Month7 days, 15 hours left to enroll