改變RGB值
回答
如果變化你的意思取代,那麼你可以使用圖像ROI(感興趣區域)功能直接用原始圖像的矩形區域替換您的原始圖像的矩形區域非常有效。
假設您的原始圖像存儲在A
中,並且想要使用圖像中的像素B
更改它的一部分(矩形區域)。
UPDATE:這裏在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
我不明白這是什麼做的 你能解釋 – eomer 2009-10-19 09:47:00
cvGet2D返回它代表了一個CvScalar對象像素。如果你說:s = cvGet2D(original_cvimage,0,0),它會返回像素(0,0)的RGB值。 s [0] =藍色值,s [1] =綠色,s [2] =紅色。但這不是你的擔心。所有你需要知道的是,在你調用s = cvGet2D(original_cvimage,x,y)之後; ,s將保持原始圖像的1個像素的像素值。通過調用cvSet2D(new_cvimage,x,y,s);您要在新圖像中加載原始圖像中的1個像素。所以你需要添加一個嵌套循環來遍歷圖像中的所有像素。 – anyone 2009-10-19 10:48:53
這將**非常緩慢**。 – Jacob 2009-10-19 14:13:44
- 1. 改變RGB顏色
- 2. 改變LSB的圖像RGB值給予
- 3. rgb值作爲變量
- 4. 更改rgb顏色值以表示值
- 5. 值到RGB值
- 6. Swift 3 - 保存圖像更改RGB值
- 7. 如何更改C++中的RGB值
- 8. 如何根據某些變量更改RGB值? (值映射顏色)
- 9. rgb值的Argb值
- 10. RenderedImage - > RGB值
- 11. HBRUSH到RGB值
- 12. 減去RGB值
- 13. rgb值向量QImage
- 14. 插值RGB顏色
- 15. MagiC++ RGB顏色值
- 16. MATLAB RGB值兩難
- 17. 不能在pygtk中使用cairo改變使用rgb值的行顏色
- 18. 將原始負rgb整數值轉換回3號rgb值
- 19. 自己計算的RGB值與實際的RGB值不匹配
- 20. 改變價值
- 21. radio_button_tag值改變
- 22. bogoMIPS值改變
- 23. 更改rgb位的alpha
- 24. EXCEL VBA改變背景顏色 - RGB不起作用
- 25. Java - 改變指針改變值?
- 26. 變量不會改變值
- 27. 將RGB值轉換爲HSV
- 28. 轉換特定的rgb值
- 29. UITableViewCell的RGB值SelectionStyle藍色
- 30. UITableViewCellSelectionStyleGray的RGB值是多少?
嗯,謝謝,但你能寫一個C代碼我不擅長C++ 我知道cvSetImageROI複製指定的矩形到另一個圖像我第一次聽到ROI函數本身。正如我承諾和你的意見,它將只是做我所尋找的 – eomer 2009-10-20 06:10:29
好吧,C代碼是 – Jacob 2009-10-20 14:44:19
謝謝雅各布工程完美 – eomer 2009-10-21 09:09:32