Ask Your Question
-2

Accessing the Value for each Pixel of an Output Array of phase() [closed]

asked 2016-09-22 09:58:14 -0600

Vintez gravatar image

updated 2016-09-23 02:02:36 -0600

I want to make an Matrix which holds the Orientation value of each pixel in a image. I need it for methods I want to use on the source image later on. The Code I have for this at the moment looks like this:

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

Mat src; Mat dst; Mat tmp;

void orientationMap(const cv::Mat& ori, double thresh = 1.0){

int i, j;
int** hist = 0;
hist = new int*[15];
for( i = 0; i < ori.rows; i++){
    hist[i] = new int[15];
    for( j = 0; j < ori.cols; j++){
        int pixelValue = (int)ori.at<uchar>(i,j);
        cout << pixelValue << endl;
    }
}

}

int main(int argc, const char * argv[]) {

String imgName("example.jpg");
src = imread(imgName,0);

Mat patch = src(Rect(30,30,15,15));

Mat Sx;
Sobel(patch, Sx, CV_32F, 1,0,3);

Mat Sy;
Sobel(patch, Sy, CV_32F, 0, 1, 3);

Mat mag, ori;
magnitude(Sx, Sy, mag);
phase(Sx, Sy, ori, true);

orientationMap(ori, 1.0);

return 0;
}

What I want to do know, is to access the Image (ori) and read out the Orientation Values and divid them by 10 to get a number between 0 and 36. And add that one in an array. The Method I use now just gives me the gray value of the Image.

Here is the Solution for others with the same problem:

int i,j;
int** hist = 0;
hist = new int*[15];
for(i = 0; i < ori.rows; i++){
    hist[i] = new int[15];
    for(j = 0; j < ori.cols; j++){
        float value = round(ori.at<float>(i,j) / 10);
        hist[i][j] = value;
    }
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Vintez
close date 2016-09-23 07:06:32.098010

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-22 11:42:56 -0600

Tetragramm gravatar image

The documentation is extremely helpful for simple questions like this.

For learning the basics like this, you should also take a look at the tutorials.

edit flag offensive delete link more

Comments

thanks for that advise. After looking a little bit more into the docu and debugging my code I found the solution

Vintez gravatar imageVintez ( 2016-09-23 02:01:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-22 09:58:14 -0600

Seen: 525 times

Last updated: Sep 23 '16