1

I created a 3D matrix as cv::mat which contain on each axis (X, Y and Z) avalue from 0 to 255, as follow:

int sizes[] = { 100, 100, 100 };
Mat *matrix;
matrix = new Mat(3,sizes, CV_32FC1, cv::Scalar(0));
for(int i=0;i<100;i++)
    for(int j=0;j<100;j++)
        for(int k=0;k<100;k++){
            //some values are 255
            matrix->at<float>(i,j,k) = 0;
            // and some of them are 255 : (TODO) 

        }

And now I want smooth the whole 3D matrix, how I can do that with opencv lib?

Any help will be appreciated,

ksolid
  • 151
  • 1
  • 2
  • 5
  • 2
    Have you read [this](http://stackoverflow.com/q/19168573/2065121) and [this](http://stackoverflow.com/q/9814187/2065121) and maybe [this](http://stackoverflow.com/q/18020438/2065121)? Perhaps you can do so and then edit your question to make it specific where you're having trouble. It seems to me that a lot of this is already answered here. – Roger Rowland May 11 '14 at 15:14
  • the first example it works, thanks, – ksolid May 11 '14 at 18:07
  • still having troubles with smoothing ! – ksolid May 11 '14 at 18:20
  • You should edit your anwer and give us more information/describe your problem better. You could for example provide a minimal example with your problem. – Sebastian Schmitz May 12 '14 at 08:06
  • Hi Sebastian Schmitz, I update the question above, hope now it is clear :) – ksolid May 12 '14 at 18:09
  • Is my answer acceptable to you? If so please tick it as correct :) – Yonatan Simson Feb 02 '20 at 07:30

1 Answers1

1

I would not use new Mat() to initialize an OpenCV Mat. There is no need for this. You also run the risk of forgeting to free your Matrix once finished with it.

Simply use:

Mat matrix(3,sizes, CV_32FC1, cv::Scalar(0));

As for creating a 3D Matrix you can find a good example here

If you wish to filter the 3D Matrix with a Gaussian filter you will find a simple example here

Community
  • 1
  • 1
Yonatan Simson
  • 2,395
  • 1
  • 24
  • 35