Ask Your Question
2

How can I specify row alignment reading an image or creating Mat object?

asked 2012-10-17 03:31:08 -0500

Valentina Kustikova gravatar image

Hello, I need to specify row alignment reading an image. I can do it by hands computing new width in accordance with particullar stride (source code you can find below).

Mat srcImg, alignedImg, roiImg;
Size size;
// read initial image
srcImg = imread(argv[1]);
// compute new width (aligment with the stride = 32)
size.width = ((srcImg.size().width - 1) & -32) + 32;
size.height = srcImg.size().height;
// create new image
alignedImg.create(size, srcImg.type());
// adjust ROI
roiImg = alignedImg.adjustROI(0, 0, 0, srcImg.size().width - size.width);
// copy initial image into ROI
srcImg.copyTo(roiImg);

// release memory
srcImg.release();
alignedImg.release();

Is there a way to set row alignment reading an image or creating Mat object automatically without additional memory allocation and copying data?

Thanks!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2012-10-17 05:24:30 -0500

Daniil Osokin gravatar image

Hi, Valentina! As I know, Mat doesn't support data align.

edit flag offensive delete link more

Comments

1

Thanks, Daniil! Actually, I have another question connected with those subject. I wanted to create Mat object using create(...) method with particular stride (or step if to talk in terms of constructor parameters). Is there a way to create such object without calling Mat constructor with parameters? It looks like strange when we have constructor but we don't have simular method create(...).

Valentina Kustikova gravatar imageValentina Kustikova ( 2012-10-17 06:25:38 -0500 )edit
0

answered 2013-10-18 06:35:48 -0500

Antonio gravatar image

You can replace

roiImg = alignedImg.adjustROI(0, 0, 0, srcImg.size().width - size.width);

with

roiImg = alignedImg.colRange(0,srcImg.cols);

(Note for colRange from the documentation: Start and end column of the extracted submatrix. The upper boundary is not included)

To have the image loaded directly as you desire, you would have to go one level down to the imdecode method, and test if giving the roiImg created as you did would work as expected, loading the image aligned. Of course, you need to know the image size in advance, otherwise you will have to write your own version of imdecode.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-10-17 03:31:08 -0500

Seen: 2,005 times

Last updated: Oct 18 '13