2011-10-22 113 views
2

我試圖增加加載圖像的亮度img,但是要循環使用更小的矩陣[我將用於稍後應用高斯模糊]的像素。這裏是我的功能:無法循環矩形圖像矩陣的所有像素

void Dobright(cv::Mat &in,IplImage * img) 
{ 
    uchar* temp_ptr ; 
    for(int row = 0; row < in.rows; row++) 
    { 
      for (int col = 0; col < in.cols; col++) 
      { 
       CvPoint pt = {row,col}; 
       temp_ptr = &((uchar*)(img->imageData + img->widthStep*pt.y))[pt.x*3]; 
       temp_ptr[0] += 100; 
       temp_ptr[1] += 100; 
       temp_ptr[2] += 100; 
      } 
    } 
} 

但是,如果原始圖像是:

enter image description here

我得到的亮形象:

enter image description here

正如你可以看到一些零部件比其他的更亮,因爲行和列不相同,因此整個圖像的像素不被訪問,如何解決這個問題?

+0

你知道有OpenCV函數用於應用高斯模糊以及縮放矩陣的函數嗎? (例如cv :: Mat :: convert()) – Unapiedra

+0

@Unapiedra - 我知道。 –

回答

1

從你的寬度和高度混合起來的外觀上來看,嘗試使用:
CvPoint pt = {col,row};

也與當前的算法,你會遇到問題時,你的像素原始值> 155(156 + 100 = 1),因爲四捨五入。嘗試使用

tmp_ptr[0] = (tmp_ptr > 155) ? 255 : tmp_ptr[0] + 100;

1

看起來你已經翻轉你的X和Y在這裏。您希望CvPoint爲{col,row}而不是{row,col}

想想這樣:第三行第五列是點(5,3),而不是點(3,5)。