Ask Your Question
0

How to obtain partial derivatives of R,G,B

asked 2015-12-04 03:23:06 -0600

baro gravatar image

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 flag offensive close merge delete

Comments

(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

baro gravatar imagebaro ( 2015-12-04 03:25:04 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-12-04 04:30:01 -0600

updated 2015-12-05 09:16:36 -0600

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.

edit flag offensive delete link more

Comments

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

baro gravatar imagebaro ( 2015-12-04 05:31:02 -0600 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-04 07:32:08 -0600 )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?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-12-04 08:02:12 -0600 )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 :)

baro gravatar imagebaro ( 2015-12-04 08:11:02 -0600 )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?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-12-04 08:34:47 -0600 )edit

Thanks you for the suggestion

baro gravatar imagebaro ( 2015-12-05 04:23:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-04 03:23:06 -0600

Seen: 339 times

Last updated: Dec 05 '15