图像处理之几个效果

#include "cv.h"
#include "highgui.h"

using namespace cv;

#define PI 3.1415926

int main()
{
	//读取图像
	Mat image;
	image=imread("line.png",CV_LOAD_IMAGE_GRAYSCALE);

	int M=image.rows;
	int N=image.cols;

	//浮雕效果 与左上角像素差值
	/*for(int i=M-1;i>0;i--)
	{
		uchar* p1=image.ptr<uchar>(i-1);
		uchar* p=image.ptr<uchar>(i);

		for(int j=N-1;j>0;j--)
		{
			int buf=p[j]-p1[j-1]+128;
			if(buf>255) buf=255;
			else if(buf<0) buf=0;

			p[j]=buf;
		}
	}*/

	//雕刻图像 与右下角像素差值
	/*for(int i=0;i<M-1;i++)
	{
		uchar* p=image.ptr<uchar>(i);
		uchar* p1=image.ptr<uchar>(i+1);

		for(int j=0;j<N-1;j++)
		{
			int buf=p[j]-p1[j+1]+128;
			if(buf>255) buf=255;
			else if(buf<0) buf=0;

			p[j]=buf;
		}
	}*/

	/*Mat temp=image.clone();

	for(int i=0;i<M;i++)
	{
		uchar* p=image.ptr<uchar>(i);

		for(int j=0;j<N;j++)
			p[j]=0;
	}

	//图像旋转
	int angle=90;
	int xcenter=(M+1)/2,ycenter=(N+1)/2;
	for(int i=0;i<M;i++)
	{
		uchar* p=temp.ptr<uchar>(i);
		for(int j=0;j<N;j++)
		{
			int newx=(int)((i-xcenter)*cos(PI*angle/180)-(j-ycenter)*sin(PI*angle/180)+xcenter);
			int newy=(int)((i-xcenter)*sin(PI*angle/180)+(j-ycenter)*cos(PI*angle/180)+ycenter);

			if(newx>=0&&newx<M&&newy>0&&newy<N)
			{
				uchar* p1=image.ptr<uchar>(newx);
				p1[newy]=p[j];
			}
		}
	}*/

	//抖动效果
	/*for(int i=M-1;i>1;i--)
	{
		uchar* p=image.ptr<uchar>(i);
		uchar* p1=image.ptr<uchar>(i-2);

		for(int j=N-1;j>1;j--)
		{
			int buf=(p[j]+p1[j-2])/2;
			p[j]=buf;
		}
	}*/


	cvNamedWindow("test",CV_WINDOW_AUTOSIZE);
	imshow("test",image);

	waitKey(0);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值