图像的放缩与插值&图像归一化&直方图&图像卷积&高斯模糊

1.图像的放缩与插值

//图像的放缩与插值
void resize_demo()
{
	Mat zoomin,zoomout;
	int h = image.rows;
	int w = image.cols;
	resize(image, zoomin, Size(w/2,h/2), 0, 0,INTER_LINEAR);
	imshow("zoomin", zoomin);
	resize(image, zoomout, Size(w*1.5,h*1.5), 0, 0, INTER_LINEAR);
	imshow("zoomout", zoomout);
}

2.图像归一化

//图像归一化
void norm_demo(Mat &image)
{
	Mat dst;
	cout<<image.type()<<endl;
	image.convertTo(image,CV_32F);
	cout<<image.type()<<endl;
	normalize(image, dst, 1.0, 0 ,NORM_MINMAx);
	cout<<dst.type()<<endl;
	imshow("图像数据归一化",dst);
}

3.直方图&图像卷积

//直方图
void Histogram_demo(Mat &image)
{
	//三通道分离
	vector<Mat>bgr_plane;
	split(imag, bgr_plane);
	//定义参数变量
	const int channels[1]={0};
	const int bins[1] = {256};
	const float* ranges[1] = {hranges};
	Mat b_hist;
	Mat g_hist;
	Mat r_hist;
	//计算blue,green,red通道的直方图
	calcHist(&bgr_plane[0],0,Mat(),b_hist,1,bins,ranges);
	calcHist(&bgr_plane[1],0,Mat(),g_hist,1,bins,ranges);
	calcHist(&bgr_plane[2],0,Mat(),r_hist,1,bins,ranges);
	//显示直方图
	int hist_w = 512int hist_h = 400int bin_w = cvRound(double)hist_w/bins[0];
	Mat hisImage = Mat::zeros(hist_h,hist_w,CV_8UC3);
	//归一化直方图数据
	normalize(b_hist, b_hist,0, hisImage.rows, NORM_MINMAx,-1,Mat());
	normalize(g_hist, g_hist,0, hisImage.rows, NORM_MINMAx,-1,Mat());
	normalize(r_hist, r_hist,0, hisImage.rows, NORM_MINMAx,-1,Mat());
	//绘制直方图曲线
	for(int i=1;i<bins[0]; i++)
	{
		line(hisImage, Point(bin_w*(i-1), hist_h - cvRound(b_hist.at<float>(i-1))),Point(bin_w*(i),hist_h-cvRound(b_hist.at<float>(i))),Scalar(255,0,0),2,8,0);
		line(hisImage, Point(bin_w*(i-1), hist_h - cvRound(g_hist.at<float>(i-1))),Point(bin_w*(i),hist_h-cvRound(b_hist.at<float>(i))),Scalar(0,255,0),2,8,0);
		line(hisImage, Point(bin_w*(i-1), hist_h - cvRound(r_hist.at<float>(i-1))),Point(bin_w*(i),hist_h-cvRound(b_hist.at<float>(i))),Scalar(0,0,255),2,8,0);
	}
	//显示直方图
	nameWindow("Histogram demo", WINDOWS_AUTOSIZE);
	imshow("Histogram demo", hisImage);
}

4.图像卷积

//图像卷积操作
void blur_demo(Mat &image)
{
	Mat dst;
	blur(image, dst, Size(15,1), Point(-1,-1));
	imshow("图像模糊", dst);
}

5.高斯模糊

//高斯模糊
void gaussian_blur_demo(Mat &image)
{
	Mat dst;
	GaussianBlur(image, dst, Size(5,5),15);//第三个参数:卷积和的大小必须是奇数而且是正数
	imshow("高斯模糊",dst);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值