roi setting

David8·2022년 9월 14일
0

컴퓨터비전

목록 보기
7/17
post-custom-banner

정의

  1. roi: region of interest
int main() {

  Mat image = imread("lena.png"); 
  Rect rect(100, 30, 250, 300); // Rect(x, y, width, height), x: x coordinate of left-top corner
  Mat rect_roi = image(rect); 
  imshow("rectROI", rect_roi);
  
  waitKey(0); 
}

mat addition, subtraction

void add (Mat src1, Mat src2, Mat dst, Mat mask= noArray(), int dtype = -1)
dst(I) = saturate(src1(I)+src2(I)) if mask(I) != 0

  1. saturate 함수
    1. 합 255 초과 --> 255로 설정
    2. 합 0 미만 --> 0으로 설정
int main() {

  Mat img1 = imread("lena.png"); 
  Mat img2 = imread("lena.png"); Mat dst;
  add(img1, img2, dst); 
  imshow("dst", dst);
  
  waitKey(0);
}
  1. function
    1. void scaleAdd(Mat src1, double scale, Mat src2, Mat dst)
      1. dst(I) = scale * src1(I) + src2(I)
    2. void absdiff(Mat src1, Mat src2, Mat dst)
      1. dst(I) = saturate( | src1(I)-src2(I) | )
    3. void subtract(Mat src1, Mat src2, Mat dst, Mat mask=noArray(), int dtype = -1)
      1. dst(I) = saturate( src1(I) – src2(I) ) if mask(I) != 0

blur_GaussianBlur, Sharpening, medianBlur

  1. averaging filter
int main() {

  Mat image, AvgImg, GaussianImg; 
  image = imread("lena.png");
  
  // Blurs an image using the normalized box filter
  // image: input image, AvgImg: output image, Size(5, 5): blurring kernel size 
  blur(image, AvgImg, Size(5, 5));
  
  // Blurs an image using a Gaussian filter
  // image: input image, GaussianImg: output image, Size(5, 5): Gaussian kernel size // 1.5: Gaussian kernel standard deviation in X direction
  GaussianBlur(image, GaussianImg, Size(5, 5), 1.5); // 중앙에 집중, 1.5는 가우스 기본값
  
  imshow("Input image", image);
  imshow("Average image", AvgImg); 
  imshow("Gaussian blurred image", GaussianImg);
  
  waitKey(0);
  return 0; 
}
  1. Sharpening using second derivative
int main() {

  Mat image, laplacian, abs_laplacian, sharpening; 
  image = imread(“Moon.png", 0);
  
  GaussianBlur(image, image, Size(3, 3), 0, 0, BORDER_DEFAULT); 
  // calculates the Laplacian of an image
  // image: src, laplacian: dst, CV_16S: desire depth of dst,
  // 1: aperture size used to compute second-derivative (optional) 
  // 1: optional scale factor for the computed Laplacian values
  // 0: optional delta value that is added to the result Laplacian(image, laplacian, CV_16S, 1, 1, 0); 
  convertScaleAbs(laplacian, abs_laplacian); // bit 전환(16s->8u)
  sharpening = abs_laplacian + image;
  
  imshow("Input image", image); 
  imshow("Laplacian", laplacian); 
  imshow("abs_Laplacian", abs_laplacian); 
  imshow("Sharpening", sharpening);
  
  waitKey(0); 
  
}
  1. median filter
int main() {
  Mat image = imread("saltnpepper.png", 0);
  imshow("SaltAndPepper", image);
  Mat mf1, mf2;
  // Blurs an image using the median filter
  // image: src, mf1: dst, 3: aperture size(must be odd and greater than 1) 
  medianBlur(image, mf1, 3);
  imshow("MedianFiltered1", mf1);
  
  medianBlur(image, mf2, 9); 
  imshow("MedianFiltered2", mf2);
  
  waitKey(0);
  return 0; 
}
post-custom-banner

0개의 댓글