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

📄 interpolation.cpp

📁 matlab版图像数字处理这本书的配套代码
💻 CPP
字号:
#include"stdafx.h"
#include"interpolation.h"
#include<math.h>

unsigned char NeighborInterpolation(LPSTR lpDIBBits,LONG width,LONG height,float x,float y)
{
	unsigned char temp;
	LONG i,j;
	LONG LineBytes=(width*8+31)/32*4;
	if(x>height-1||y>width-1)
	{
		if(x>height-1)
			x=float(height-1);
		else
			y=float(width-1);
	}
	i=(LONG)x;
	j=(LONG)y;
	temp=*(lpDIBBits+LineBytes*(height-1-i)+j);
	return temp;	
}


unsigned char BiLinearInterpolation(LPSTR lpDIBBits,LONG width,LONG height,float x,float y)
{
	LONG i0,j0,i1,j1;
	unsigned char f1,f2,f3,f4;
	unsigned char tempy,tempx;
	LONG LineBytes;
	LineBytes=(width*8+31)/32*4;
	if((x>height-1)||(y>width-1))
	{
		if(x>height-1)
			x=float(height-1);
		else
			y=float(width-1);
	}
	i0=(LONG)x;
	j0=(LONG)y;
	i1=i0+1;
	j1=j0+1;
	if(fabs(x-(height-1))<0.01)
	{
		if(fabs(y-(width-1))<0.01)
		{
			f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
			return f1;
		}
		else
		{
			f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
			f2=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j1));
			tempy=(unsigned char)(f1+(y-j0)*(f2-f1));
			return tempy;
		}
	}
	else if(fabs(y-(width-1))<0.01)
	{
		f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
		f3=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i1)+j0));
		tempx=(unsigned char)(f1+(x-i0)*(f3-f1));
		return tempx;
	}
	else
	{
		f1=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j0));
		f2=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i0)+j1));	
		f3=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i1)+j0));
		f4=(unsigned char)(*(lpDIBBits+LineBytes*(height-1-i1)+j1));
		tempx=(unsigned char)(f3+(y-j0)*(f4-f3));
		tempy=(unsigned char)(f1+(y-j0)*(f2-f1));
		return ((unsigned char)(tempy+(x-i0)*(tempx-tempy)));
	}
}

⌨️ 快捷键说明

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