Ask Your Question
1

Pixel tensors as matrix of matrices

asked 2014-09-19 08:54:15 -0600

burk gravatar image

Hello!

I want to calculate the structure tensor of an image, so I need to store one 2-by-2 matrix for each pixel of the image, and I am wondering what is the best way to do this. Optimally, I would like to be able to do tensors(3,4) to get a Mat(2,2) object containing the tensor at position (3,4) in the image. I tried variants of

Mat_<Mat_<int> > tt(10, 10);
tt(0,3).create(2, 2);

But it fails with a segmentation fault when trying to create the 2-by-2 tensor

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7abf5b9 in cv::Mat::create(int, int const*, int) ()
   from /usr/lib/libopencv_core.so.2.4
(gdb) bt
#0  0x00007ffff7abf5b9 in cv::Mat::create(int, int const*, int) ()
   from /usr/lib/libopencv_core.so.2.4
#1  0x0000000000403576 in cv::Mat::create (this=0x654870, _rows=2, _cols=2, 
    _type=4) at /usr/include/opencv2/core/mat.hpp:353
#2  0x0000000000403937 in cv::Mat_<int>::create (this=0x654870, _rows=2, 
    _cols=2) at /usr/include/opencv2/core/mat.hpp:910
#3  0x0000000000402e7a in main (argc=5, argv=0x7fffffffe408)
    at /home/burk/dev/image-restoration/sobel.cpp:100

I'm sure I'm just missing something trivial in one of the constructors, but I feel like I have tried everything!

edit retag flag offensive close merge delete

Comments

I guess I could also just have four different Mat objects in an array, one for each of the elements in the tensor.

burk gravatar imageburk ( 2014-09-19 09:02:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-19 09:10:25 -0600

berak gravatar image

updated 2014-09-19 09:23:10 -0600

you could use Matx<float,2,2> for your 'tensor'

    typedef Matx<float,2,2> tensor;
    Mat_<tensor> mt = Mat_<tensor>::zeros(4,4);
    mt(2,2) = tensor(1,2,3,4);
    cerr << mt << endl;

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0;
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

but again, all with a grain of salt. you'll probably find a lot of unhandled operators.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-09-19 08:54:15 -0600

Seen: 586 times

Last updated: Sep 19 '14