Ask Your Question

Replace subsection of Mat with another Mat.

asked 2019-06-06 12:16:25 -0500

GoldenBug gravatar image

I have an image stored in a Mat object (BigImage). I also have a smaller Mat image that fits inside the bounds of first mat object (SmallImage).

Currently I'm replacing a section of BigImage with SmallImage. I'm doing this by iterating and doing a pixel by pixel assignment from SmallImage to BigImage.

Is there a faster way of doing thing?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-06-06 16:29:55 -0500

Witek gravatar image
SmallImage.copyTo(BigImage(Rect(x, y, SmallImage.cols, SmallImage.rows)));
edit flag offensive delete link more


Is this any more performant, or just more succinct?

GoldenBug gravatar imageGoldenBug ( 2019-06-06 16:38:35 -0500 )edit

Both. This uses some known guarantees about the Mat memory structure to be much faster than a pixel-by-pixel method.

Tetragramm gravatar imageTetragramm ( 2019-06-06 19:05:42 -0500 )edit

Interesting, Thank you!

GoldenBug gravatar imageGoldenBug ( 2019-06-06 19:08:14 -0500 )edit

Question Tools

1 follower


Asked: 2019-06-06 12:16:10 -0500

Seen: 222 times

Last updated: Jun 06 '19