# How to obtain partial derivatives of R,G,B

Hi!!! I'm trying to do an edge detector but how I do to each color band to obtain partial derivatives rx,ry, gx, gy, bx, by (for red,green,blue). With these color derivatives I must create a S matrix, where S matrix is

rx^2 + gx^2 +bx^2, rxry + gxgy + bxby, rxry + gxgy + bxby, ry^2 + gy^2 +by^2

could you tell me what size have derivatives ? Ok, now , from S, I must calcolate the trace, the eigenvalues and the crrisponding eigenvectors. How I can do all ? thanks you for our time and for answer me

edit retag close merge delete

(0,0) = rx^2 + gx^2 +bx^2 (0,1) = rxry + gxgy + bxby (1,0) = rxry + gxgy + bxby (1,1) = ry^2 + gy^2 +by^2

( 2015-12-04 03:25:04 -0500 )edit

Sort by » oldest newest most voted

The solution is quite straightforward. You should first split the channels, then calculate Sobel filtering in X and Y direction.

Sample code for OpenCV 3:

Mat input = imread("/path/to/image.png", IMREAD_COLOR);
vector<Mat> channels;
split(input, channels);
Mat SobelBx, SobelBy, SobelGx, SobelGy, SobelRx, SobelRy;
// Blue channel edges
Sobel(channels[0], SobelBx, CV_8U, 1, 0);
Sobel(channels[0], SobelBy, CV_8U, 0, 1);
// Green channel edges
Sobel(channels[1], SobelGx, CV_8U, 1, 0);
Sobel(channels[1], SobelGy, CV_8U, 0, 1);
// Red channel edges
Sobel(channels[2], SobelRx, CV_8U, 1, 0);
Sobel(channels[2], SobelRy, CV_8U, 0, 1);


Then you can simply apply operations on the result matrices, keeping in mind that if you are multiplying matrices with ^2, that you should change the data format at least to 16 bit integers because else you will have an overflow. Same goes for trace, eigenvalues, ... for which OpenCV has specific functions.

more

Perfect! But my specific problem is create the matrix S. The S matrix is a 2x2 size. But each element of the matrix is another matrix wich size is 40x40. How I create correctly S matrix? Thanks you so much

( 2015-12-04 05:31:02 -0500 )edit

That is not possible. You cannot obtain a 2x2 matrix multiplicating and adding 40x40 matrices, that is mathematical impossible...

( 2015-12-04 07:32:08 -0500 )edit
1

Are you saying that

     / A  |  B \
S = | --------- |
\ C  |  D /


And each of the A, B, C and D are matrix of 40x40? So S is 80x80?

( 2015-12-04 08:02:12 -0500 )edit
1

exactly! performing multiplications and additions of square matrix get a square matrix of equal size. The sobel operator provides me a derivaties in matrix format wich size is 40x40. So A,B,C,D will be matrix of 40x40. With A,B,C,D I must generate S matrix. I suppose that S matrix will be 80x80 but I dont very sure. thanks you soo much :)

( 2015-12-04 08:11:02 -0500 )edit
1

If you create S as in my post then S should be 80x80! But if I see no code, I cannot say it is true. By adding A+B, you will not obtain a matrix of 40x80. What you can do is creating S as zeros of 80x80 and add A in the cv::Rect tlRoi(0, 0, 40, 40);, B in trRoi(0, 40, 40, 40) C in blRoi(40, 0, 40, 40), and D in brRoi(40, 40, 40, 40). But what is the link of 40x40 and 80x80 and RGB derivatives?

( 2015-12-04 08:34:47 -0500 )edit

Thanks you for the suggestion

( 2015-12-05 04:23:01 -0500 )edit

Official site

GitHub

Wiki

Documentation