Advertisement
Guest User

usa

a guest
Feb 26th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cv.h>
  3. #include <highgui.h>
  4. using namespace std;
  5. using namespace cv;
  6. int main()
  7. {
  8. Mat image1;
  9. image1 = imread("Lenna.png");
  10. int i, j;
  11. Mat imgOut(image1.rows, image1.cols, CV_8UC1, Scalar(0, 0, 0));
  12. Mat imgOutNew(image1.rows, image1.cols, CV_8UC1, Scalar(0, 0, 0));
  13.  
  14. for(int i=0; i<image1.rows; i++){
  15. for(int j=0; j<image1.cols; j++){
  16. //membaca setiap piksel
  17. Vec3b intensity = image1.at<Vec3b>(i, j);
  18. uchar blue = intensity.val[0];
  19. uchar green = intensity.val[1];
  20. uchar red = intensity.val[2];
  21.  
  22. //mengubah RGB menjadi grayscale
  23. uchar imGray = (red * 0.299 + green * 0.587 + blue * 0.114);
  24. imgOut.at<uchar>(i, j) = imGray;
  25.  
  26. if(imgOut.at<uchar>(i,j)>100)
  27. imgOutNew.at<uchar>(i,j)=100;
  28. else
  29. imgOutNew.at<uchar>(i,j)= imgOut.at<uchar>(i,j);
  30. }
  31. }
  32. imshow("tresh_binary_manual.jpg",imgOutNew);
  33. cvWaitKey(0);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement