Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bgrtohsv(){
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- Mat src = imread(fname);
- Mat hsv;
- Mat channels[3];
- int height = src.rows;
- int width = src.cols;
- Mat dstH = Mat(height, width, CV_8UC1);
- Mat dstS = Mat(height, width, CV_8UC1);
- Mat dstV = Mat(height, width, CV_8UC1);
- cvtColor(src, hsv, CV_BGR2HSV);
- split(hsv, channels);
- dstH = channels[0] * (510/360);
- dstS = channels[1];
- dstV = channels[2];
- imshow("h", dstH);
- imshow("v", dstV);
- imshow("s", dstS);
- imshow("hsv", hsv);
- //waitKey();
- int HistH[256] = { 0 };
- for (int i = 0; i < dstH.rows; i++){
- for (int j = 0; j < dstH.cols; j++){
- uchar u = dstH.at<uchar>(i, j);
- HistH[u]++;
- }
- }
- int HistS[256] = { 0 };
- for (int i = 0; i < dstS.rows; i++){
- for (int j = 0; j < dstS.cols; j++){
- uchar u = dstS.at<uchar>(i, j);
- HistS[u]++;
- }
- }
- int HistV[256] = { 0 };
- for (int i = 0; i < dstV.rows; i++){
- for (int j = 0; j < dstV.cols; j++){
- uchar u = dstV.at<uchar>(i, j);
- HistV[u]++;
- }
- }
- showHistogram("histh", HistH, 256, 256, true);
- showHistogram("hists", HistS, 256, 256, true);
- showHistogram("histv", HistV, 256, 256, true);
- Mat binarizare= dstH.clone();
- for (int i = 0; i < dstH.rows; i++){
- for (int j = 0; j < dstH.cols; j++){
- float t = channels[0].at<uchar>(i,j);
- if (t < 30)
- binarizare.at<uchar>(i, j) = 255;
- else
- binarizare.at<uchar>(i, j) = 0;
- }
- }
- imshow("imgbinarizata", binarizare);
- waitKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement