Pregunta

I have to translate from Matlab to C this function:

 impadded = padarray(impadded, padSzVec, 'replicate', 'both');

Really it pads the array copying the last elements of the object impadded of every row and column(obtening a bigger object).

What I did is: (img is the original image)

Mat padded;
padded.create(img.rows + padSize, img.cols + padSize,img.type());
padded.setTo(cv::Scalar::all(0));
padded(Rect(padSize,padSize,img.rows,img.cols);
img.copyTo(padded);

I suppose I m padding but inserting 0 to have a bigger object. Someone cal help me to improve the code.

¿Fue útil?

Solución

(Since it solves the problem of OP, I am making my comment an answer)

You can use copyMakeBorder() function in OpenCV to pad elements in whatever directions you like and it supports several types of padding. See the docs : http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=makeborder#copymakeborder

BORDER_CONSTANT will add a constant value.

BORDER_REPLICATE will copy the border elements as such, and I think that is what you need in your problem.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top