简体   繁体   English

更改RGB值

[英]Changing RGB values

I am trying to change a part of an image with another image I couldn't find the merging function so I just occur that can I change the rgb values of the part I want to change with the other images RGB values is it possible 我正在尝试用另一个图像来更改图像的一部分,而我找不到融合功能,所以我只是想可以将要更改的部分的rgb值更改为其他图像的RGB值?

Thanks for suggestions 感谢您的建议

If by change you mean replace , then you can use the image ROI (region of interest) functions to directly replace a rectangular region of your original image with a rectangular region from another image very efficiently . 如果通过更改来表示替换 ,则可以使用图像ROI(感兴趣区域)功能非常有效地将原始图像的矩形区域直接替换为另一图像的矩形区域。

Suppose your original image was stored in A and you want to change a part of it (a rectangular region) using pixels from an image B . 假设原始图像存储在A并且您想使用图像B像素更改它的一部分(矩形区域)。

UPDATE: Here's the code in C 更新:这是C语言中的代码

/**** C ****/

// Acquire Image A and B (here as an example, I'm reading from disk)
IplImage* A = cvLoadImage("image_A.jpg");
IplImage* B = cvLoadImage("image_B.jpg");

// Set the region-of-interest (ROI) for the two images
// such that only the ROI of A and B will be handled
cvSetImageROI(A,cvRect(200,200,128,128));
cvSetImageROI(B,cvRect(0,0,128,128));

// Copy the ROI in B to the ROI in A
cvCopy(B,A);

// Reset the ROI (now the entire image will be handled)
cvResetImageROI(A);
cvResetImageROI(B); 

// Display A
cvNamedWindow("Modified A");
cvShowImage("Modified A",A);
cvWaitKey();

// Release the images
cvReleaseImage(&A);
cvReleaseImage(&B);

Using OpenCV 2.0: 使用OpenCV 2.0:

// C++ //

// Images A and B have already been loaded .....

// Region in image A starting from (100,100) of width 200 and height 200
Rect RegionA(100,100,200,200);
// Region in image B starting from (50,50) of width 200 and height 200
Rect RegionB(50,50,200,200);

// No copying, just a reference to the ROI of the image
Mat A_ROI(A,RegionA);
Mar B_ROI(B,RegionB);
// Copy all the pixels in RegionB in B to RegionA to A
B.copyTo(A);

You could try something like this: 您可以尝试这样的事情:

CvScalar s = cvGet2D(original_cvimage, x, y); // get the (x,y) pixel value
cvSet2D(new_cvimage, x, y, s); // set the (x,y) pixel value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM