⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jingmianlingjin.cpp

📁 用邻近算法实现的图像放大用来作图像处理
💻 CPP
字号:
#include <math.h>
#include <stdlib.h>
#include "cv.h"
#include "highgui.h"
#include"stdio.h"
//#define xsize 16
void jingmian( IplImage* plmg3,IplImage* plmg4)
{  
	int i,j,m,n,d,height,width,step,step1;  	uchar array[512][512],array1[512][512];
   
	uchar *data,*data1;
	float x,y,p,q;
     int xs=512/2;
     int ys=512/2;
   
	//double gray1,gray2,gray3;
	
	if(!plmg3)
   
	printf("can not open");
   
	height = plmg3->height;    
   
	width = plmg3->width;  
   
    step = plmg3->widthStep;  
   
	//channels  = plmg3->nChannels; 
   
	data = (uchar *)plmg3->imageData; 
	data1 = (uchar *)plmg4->imageData;
     step1 = plmg4->widthStep;  

//printf("Processing a %dx%d image with %d step\n",height,width,step);   
  
  for(i=0;i<height;i++)
    for(j=0;j<width;j++) 
		// for(k=0;k<channels;k++) 
		 //{for(m=0;m<512;m++)
		   // for(n=0 ;m<512;n++)
    array[i][j]=data[i*step+j];
	//printf("%d",array[i][j]);}
	 for(i=-ys;i<ys;i++)
	 { for(j=-xs;j<xs;j++) {
		 if(i>0)m=(int)(i/2+0.5);
	   //{ y=i/2;
	      // x=j/2;
	//if(y>0) 
		//	m=(int)y;
	  else m=(int)(i/2-0.5);
	  if(j>0)
		n=(int)(j/2+0.5);
	 else n=(int)(j/2-0.5);
		//q=y-m;
		//p=x-n;
	    //i//f(q==1){q=0;m=m+1;}
		//if(p==1){p=0;n=n+1;}
		
	   if((m>-ys)&&(m<ys)&&(n>-xs)&&(n<xs))
		  //d=(int)((1.0-q)*((1.0-p)*array[m+ys][n+ys]
					    //+p*array[m+ys+1][n+xs])
					//	+q*((1.0-p)*array[m+ys][n+xs+1]
						//+p*array[m+1+ys][n+1+xs]));
	     array1[i+ys][j+xs]=array[m+ys][n+xs]; 
			 //else  if((m==-ys)||(m==ys)||(n==-xs)||(n==xs));
			//d=array[i+xs][j+ys];
		 else array1[i+ys][j+xs]=0;
	      //if(d<0) d=0;
		  //if(d>255) d=255;
	//	array[i+xs][j+ys]=d;
	}}

		for(i=0;i<height;i++)
		  for(j=0;j<width;j++)
			//array1[j][i]=array[i][j];
	//for(i=0;i<height;i++)
       //for(j=0;j<width;j++) 
		  data1[i*step1+j]=array1[i][j];
		
	 //{ data1[i][j]=data[i][j];
	// printf("%d",data1[i][j]);}
  
 
	 //{if( [i*step+j*channels+k]>90)
			 // data[i*step+j*channels+k]=0;
	// else  data[i*step+j*channels+k]=255;
	 //data1[i*step1+j]=data[i*step+j*channels+k];
    }
 
void main()
{ 
	IplImage* plmg1=0, *plmg2;

      
    plmg1=cvLoadImage("D:\\visual c++\\MSDev98\\MyProjects\\e2\\lena.jpg",0);
	cvNamedWindow("mainWin",1);   
    
	cvShowImage("mainWin", plmg1); 
		 
cvWaitKey(0); 
	
  
	
	
    plmg2=cvCreateImage(cvSize(plmg1->width,plmg1->height),IPL_DEPTH_8U,1);
    
	
    
 jingmian(plmg1,plmg2);
//printf("Processing a %dx%d image with %d channels\n",pim->nChannels);  
    
	cvNamedWindow("mainWin1",1);   
    
	cvShowImage("mainWin1", plmg2); 
		 
	cvWaitKey(0); 
	
  
 
    cvReleaseImage(&plmg2);
	cvReleaseImage(&plmg1);
  

  
		 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -