Esempio n. 1
0
File: Dip3.cpp Progetto: kziel1/dip
/*
in       input image
type     integer defining how convolution for smoothing operation is done
         0 <==> spatial domain; 1 <==> frequency domain
size     size of used smoothing kernel
thresh   minimal intensity difference to perform operation
scale    scaling of edge enhancement
return   enhanced image
*/
Mat Dip3::usm(Mat& in, int type, int size, double thresh, double scale){

   // some temporary images 
   Mat tmp(in.rows, in.cols, CV_32FC1);
   
   // calculate edge enhancement

   // 1: smooth original image
   //    save result in tmp for subsequent usage
   switch(type){
      case 0:
         tmp = mySmooth(in, size, true);
         break;
      case 1:
         tmp = mySmooth(in, size, false);
         break;
      default:
         GaussianBlur(in, tmp, Size(floor(size/2)*2+1, floor(size/2)*2+1), size/5., size/5.);
   }

   subtract(in, tmp, tmp);

   for (int x = 0; x < in.rows; x++) for (int y = 0; y < in.cols; y++) {
      if (tmp.at<float>(x, y) > thresh) {
        in.at<float>(x, y) = in.at<float>(x, y) + tmp.at<float>(x, y) * scale;
      }
   }


   return in;

}
Esempio n. 2
0
File: dip3.cpp Progetto: hoijui/DIP
/*
Performs UnSharp Masking to enhance fine image structures
in		input image
type		integer defining how convolution for smoothing operation is done
		0 <==> spatial domain; 1 <==> frequency domain
size		size of used smoothing kernel
thresh		minimal intensity difference to perform operation
scale		scaling of edge enhancement
return		enhanced image
*/
Mat usm(Mat& in, int type, int size, double thresh, double scale) {

	const bool spatial = (type == 0);
	Mat diff = mySmooth(in, size, spatial);
	diff -= in;
	diff *= scale;
	Mat res = in + diff;

	int ltt = 0;
	int htt = 0;
	const int w = in.rows;
	const int h = in.cols;
	for (int x = 0; x < w; ++x) { // image.x
		for (int y = 0; y < h; ++y) { // image.y
			// reset to input if the difference is below the threshold
			float newVal;
			if (diff.at<float>(x, y) < thresh) {
				newVal = in.at<float>(x, y);
				ltt++;
			} else {
				newVal = res.at<float>(x, y);
				htt++;
			}
			res.at<float>(x, y) = newVal;
		}
	}
//	cout << "higher then threshold: " << htt << "  /  lower: " << ltt << endl;

	return res;
}
Esempio n. 3
0
/*
in       input image
type     integer defining how convolution for smoothing operation is done
         0 <==> spatial domain; 1 <==> frequency domain
size     size of used smoothing kernel
thresh   minimal intensity difference to perform operation
scale    scaling of edge enhancement
return   enhanced image
*/
Mat Dip3::usm(Mat& in, int type, int size, double thresh, double scale){

   // some temporary images 
   Mat tmp(in.rows, in.cols, CV_32FC1);
   
   // calculate edge enhancement

   // 1: smooth original image
   //    save result in tmp for subsequent usage
   switch(type){
      case 0:
         tmp = mySmooth(in, size, true);
         break;
      case 1:
         tmp = mySmooth(in, size, false);
         break;
      default:
         GaussianBlur(in, tmp, Size(floor(size/2)*2+1, floor(size/2)*2+1), size/5., size/5.);
   }

   // TO DO !!!
   //2. subtract smoothed image
   Mat subtractedImage = in.clone();
   subtractedImage -= tmp;
   //subtract(in, tmp, subtractedImage);

   //3. Thresholding
   Mat scaledImage = Mat::zeros(in.size(), CV_32FC1);

   threshold(subtractedImage, scaledImage, thresh, 255, THRESH_TOZERO);
   scaledImage *= scale;
   ////for (int i = 0; i < in.rows; i++){
	  //// for (int j = 0; j < in.cols; j++){
		 ////  if (subtractedImage.at<float>(i, j)>thresh){
			////   scaledImage.at<float>(i, j) = scale*subtractedImage.at<float>(i, j);
		 ////  }
	  //// }
   ////}

   Mat enhancedImage = in.clone();
   enhancedImage += scaledImage;
   //add()
   return enhancedImage;
//   return in;

}