Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cv.h>
- #include <highgui.h>
- using namespace std;
- using namespace cv;
- int main()
- {
- Mat image1;
- image1 = imread("Lenna.png");
- int i, j;
- Mat imgOut(image1.rows, image1.cols, CV_8UC1, Scalar(0, 0, 0));
- Mat imgOutNew(image1.rows, image1.cols, CV_8UC1, Scalar(0, 0, 0));
- for(int i=0; i<image1.rows; i++){
- for(int j=0; j<image1.cols; j++){
- //membaca setiap piksel
- Vec3b intensity = image1.at<Vec3b>(i, j);
- uchar blue = intensity.val[0];
- uchar green = intensity.val[1];
- uchar red = intensity.val[2];
- //mengubah RGB menjadi grayscale
- uchar imGray = (red * 0.299 + green * 0.587 + blue * 0.114);
- imgOut.at<uchar>(i, j) = imGray;
- if(imgOut.at<uchar>(i,j)>100)
- imgOutNew.at<uchar>(i,j)=100;
- else
- imgOutNew.at<uchar>(i,j)= imgOut.at<uchar>(i,j);
- }
- }
- imshow("tresh_binary_manual.jpg",imgOutNew);
- cvWaitKey(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement