First time here? Check out the FAQ!

Ask Your Question
2

Replace subsection of Mat with another Mat.

asked Jun 6 '19

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?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
3

answered Jun 6 '19

Witek gravatar image
SmallImage.copyTo(BigImage(Rect(x, y, SmallImage.cols, SmallImage.rows)));
Preview: (hide)

Comments

Is this any more performant, or just more succinct?

GoldenBug gravatar imageGoldenBug (Jun 6 '19)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 (Jun 7 '19)edit

Interesting, Thank you!

GoldenBug gravatar imageGoldenBug (Jun 7 '19)edit

Question Tools

1 follower

Stats

Asked: Jun 6 '19

Seen: 2,111 times

Last updated: Jun 06 '19