画像の一部を別の画像に変更しようとしていますが、マージ機能が見つからなかったので、他の画像と変更したい部分のrgb値を変更できます。RGB値は可能ですか。
提案をありがとう
画像の一部を別の画像に変更しようとしていますが、マージ機能が見つからなかったので、他の画像と変更したい部分のrgb値を変更できます。RGB値は可能ですか。
提案をありがとう
変更によって置換を意味する場合は、画像の ROI (関心領域) 関数を使用して、元の画像の四角形の領域を別の画像の四角形の領域で非常に効率的に直接置き換えることができます。
元の画像が に保存されA
ていて、画像のピクセルを使用してその一部 (長方形の領域) を変更したいとしますB
。
更新: 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);
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);
次のようなことを試すことができます:
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