#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;
}
图像处理之几个效果
最新推荐文章于 2023-06-14 17:36:55 发布