I'm trying to code a function that calculate an orientation or gradient directions of image without using the Built-in method in boofCV library which is
GradientToEdgeFeatures.direction(derivX,derivY,orientation);
derivX is image derivative in x-direction.
derivY is image derivative in Y-direction.
orientation is image for storing the value of gradient directions.
magnitude is image for storing the value of gradient directions.
The output from the last Built-in method for 3x3 image=
Orientation 1.5707964
Orientation 1.5707964
Orientation 1.5707964
Orientation 1.5707964
Orientation 1.5707964
Orientation 1.5707964
Orientation 1.5707964
Orientation 1.5707964
Orientation 1.5707964
I wrote the code for this step and also for calculating the Magnitude as following:
for (int i = 0; i < Orientation.getHeight(); i++) {
for (int j = 0; j < orientation.getWidth(); j++) {
float valueOfOrientation = (float) ((float)Math.atan2(derivY.get(j, i), derivX.get(j, i)));
orientation.set(j, i,valueOfOrientation);
System.out.println("Orientation"+valueOfOrientation );
}
}
for (int i = 0; i < (magnitude.getHeight()); i++) {
for (int j = 0; j <( magnitude.getWidth()); j++) {
float valueXMag=(float) Math.pow(derivX.get(j, i),2);
float valueYMag=(float) Math.pow(derivY.get(j, i),2);
float magnitudeValue=(float) Math.sqrt(valueXMag+valueYMag);
magnitude.set(j, i,magnitudeValue );
System.out.println("Magnitude "+magnitudeValue);
}
}
But the value of output for 3x3 Image=
Orientation-1.5707964
Orientation-1.5707964
Orientation-1.5707964
Orientation-1.5707964
Orientation0.0
Orientation-1.5707964
Orientation-1.5707964
Orientation-1.5707964
Orientation-1.5707964
Magnitude 1.9073486E-6
Magnitude 1.9073486E-6
Magnitude 1.9073486E-6
Magnitude 1.9073486E-6
Magnitude 0.0
Magnitude 1.9073486E-6
Magnitude 1.9073486E-6
Magnitude 1.9073486E-6
Magnitude 1.9073486E-6
which is not equal to the Built-in method.
What is causing this and how can I solve this? Thanks in advance!
P.S Sorry for my writing mistakes. English in not my native language.