Solved

Matrices -> Building weighted kernels

Posted on 2011-02-16
3
884 Views
Last Modified: 2012-05-11
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; //

Open in new window

0
Comment
Question by:rossryan
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 500 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



The rest follow from symmetry
0
 
LVL 31

Expert Comment

by:GwynforWeb
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

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

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now