Ask Your Question
2

Replace subsection of Mat with another Mat.

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

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
3

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

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

Comments

Is this any more performant, or just more succinct?

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

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 -0600 )edit

Interesting, Thank you!

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

Question Tools

1 follower

Stats

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

Seen: 1,440 times

Last updated: Jun 06 '19