掩码操作增强对比度



void  Shapen(const cv::Mat &S , cv::Mat &T){
	  CV_Assert(S.depth() == CV_8U) ;

	  T.create(S.size() , S.type()) ; 
	  const int nChannel = S.channels()  ;

	  for(int i = 1 ; i < S.rows - 1 ; i++){
		   const uchar *pre =  S.ptr<uchar>(i-1) ;
		   const uchar *now =  S.ptr<uchar>(i) ;
		   const uchar *next = S.ptr<uchar>(i+1) ;
		   uchar * output = T.ptr<uchar>(i) ;
		   for(int j = nChannel ; j < (S.cols-1)*nChannel ; j++)
		        *output++ = cv::saturate_cast<uchar>(5*now[j] - pre[j] - next[j] - now[j-nChannel] - now[j+nChannel]) ;
	  }

	  T.row(0).setTo(cv::Scalar(0)) ;
	  T.row(T.rows-1).setTo(cv::Scalar(0)) ;
	  T.col(0).setTo(cv::Scalar(0)) ;
	  T.col(T.cols-1).setTo(cv::Scalar(0)) ;
}


int main(){
	cv::Mat s = cv::imread("1001.jpg") ;
	cv::namedWindow("1")  ;
	cv::imshow("1" , s ) ;
	cv::waitKey(0) ; 

	cv::Mat t ;
	Shapen(s , t) ;

	cv::namedWindow("2") ;
	cv::imshow("2" , t) ;
	cv::waitKey(0) ; 
	return 0;
}






你可能感兴趣的:(掩码操作增强对比度)