首页 > 其他 > 详细

图像像素值的反转

时间:2015-06-19 15:20:09      阅读:335      评论:0      收藏:0      [点我收藏+]
图像反转:灰度图像范围为[0,L-1]的图像反转,表达式s=L-1-r;用这种方式倒转图像的强度,可产生图像反转的对等图像。
# include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "cv.h"
#include "highgui.h"

#pragma comment(lib, "cv.lib")  
#pragma comment(lib, "cxcore.lib")  
#pragma comment(lib, "highgui.lib") 

int main()
{
  int length,width,step,channel;
  uchar * data;
  int i,j,k;
  IplImage* img;
  img=cvLoadImage("1.jpg",0);

  cvNamedWindow("source",0);
  cvShowImage("source",img);

  if(!img)
  printf("could not find the image\n");
  length=img->height;
  width=img->width;
  step=img->widthStep;
  channel=img->nChannels;  
  data=(uchar*)img->imageData;
  for(i=0;i<=length-1;i++)
	{
		 for(j=0;j<=width-1;j++)
		 {
			  for(k=0;k<=channel-1;k++)
			  {
			   data[i*step+j*channel+k]=255-data[i*step+j*channel+k];
			  }
		 }
	}
  cvNamedWindow("convert",0);
  cvShowImage("convert",img);
  cvWaitKey(0);
  cvReleaseImage(&img);
  return 0;
}

图像像素值的反转

原文:http://blog.csdn.net/lihuajie1003/article/details/46561023

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!