如何将图像转换为黑白(0或1)? [英] How I can transform image to black and white (0 or 1) ?

查看:651
本文介绍了如何将图像转换为黑白(0或1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用visual studio 2010并打开CV库,用C语言

我的问题是如何将图像pgm转换为pbm例如放入like * file并仅在二进制0中读取图像或1?

thnk u



我尝试过:



将图像转换为灰度

#includeopencv2 / core / core.hpp

#includeopencv2 / highgui / highgui.hpp

#includeopencv2 / imgproc / imgproc.hpp

#includeiostream



使用namespace cv;

using namespace std;



int main()

{



Mat图像;

image = imread(lena.jpg,CV_LOAD_IMAGE_COLOR);



if(!image.data)

{

cout<< 无法打开或找到图像<< std :: endl;

返回-1;

}



//创建一个新矩阵来保存灰色图像

Mat灰色;



//将RGB图像转换为灰色

cvtColor(图像,灰色) ,CV_BGR2GRAY);



namedWindow(显示窗口,CV_WINDOW_AUTOSIZE);

imshow(显示窗口,图片);



namedWindow(结果窗口,CV_WINDOW_AUTOSIZE);

imshow(结果窗口,灰色);



waitKey(0);

返回0;

}

I using visual studio 2010 and open CV library , in C language
my question is how I ca transform image pgm to pbm for example after put like *file and read the image only in binary 0 or 1 ?
thnk u

What I have tried:

this to convert image to greyscale
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"

using namespace cv;
using namespace std;

int main( )
{

Mat image;
image = imread("lena.jpg", CV_LOAD_IMAGE_COLOR);

if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}

// Create a new matrix to hold the gray image
Mat gray;

// convert RGB image to gray
cvtColor(image, gray, CV_BGR2GRAY);

namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
imshow( "Display window", image );

namedWindow( "Result window", CV_WINDOW_AUTOSIZE );
imshow( "Result window", gray );

waitKey(0);
return 0;
}

推荐答案

如果你搜索一下,你会找到这样的答案:< br $> b $ b

c ++ - 转换RGB到黑& amp; amp; OpenCV中的白色 - 堆栈溢出 [ ^ ]
If you search a little you will find answers like this:

c++ - Convert RGB to Black &amp; White in OpenCV - Stack Overflow[^]


这篇关于如何将图像转换为黑白(0或1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆