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

📄 color_interpolation.v

📁 该系统是一个实现图像数据采集以及对图像数据的插值处理
💻 V
字号:
//  Module Declaration
`timescale  100ps/10ps  //设置时间单位和时间精度
module color_interpolation
(
//// 接口列表
	interClk, interData, XMax, YMax, x, y, Blue, Green, Red, strClk, olineValid, 
	oframeValid
);
	parameter pixSize = "32";//声明常量确定象素的最大可输入列数和行数
	input interClk;           //本模块的工作时钟
	input [7:0] interData;   //数据的输入
	input [4:0] XMax,YMax,x,y;//最大行、列数,象素坐标的输入
	output [7:0] Blue,Green,Red;//程序输出的三色数据
	output strClk,olineValid,oframeValid;//程序输出的象素时钟、行和列有效

	reg  [7:0] Blue,Green,Red;
	wire strClk;
	reg  olineValid,oframeValid;
	reg  [9:0] tempR,tempG,tempB;    //临时存储三色,用来完成移位代替除法操作
	reg [7:0] buffer [0:pixSize*4];  //临时缓冲区
	//声明9个临时缓冲数据,用来存储当前处于滤波器中的三个数据
	reg [7:0] tempbuf00,tempbuf01,tempbuf02,tempbuf10;
	reg [7:0] tempbuf11,tempbuf12,tempbuf20,tempbuf21,tempbuf22;
	//存储当前坐标,用来完成求余和求商的操作
	reg [6:0] tempPosy0,tempPosy1,tempPosy2;
	//输出时钟
	assign strClk=interClk;
	always @(negedge interClk)
	begin
		if(x>0&&y>0)
		begin //计算当前坐标所对应的临时缓冲区的位置
			tempPosy0=y-1;
			//移位五位之后完成对4求余和乘pixSize的操作
			tempPosy0=tempPosy0<<5;
			//向缓冲区内存进数据
			buffer[tempPosy0+x-1]=interData;
			//计算行坐标在缓冲区的位置
			tempPosy1=y-2;
			tempPosy1=tempPosy1<<5;
			tempPosy2=y-3;
			tempPosy2=tempPosy2<<5;
		end
		if(y==3)//帧信号使能
			oframeValid=1;
		if(x==3)//行信号使能
			olineValid=1;

		if(y>2&&x==2)//初始化滤波器
		begin
			tempbuf21=buffer[tempPosy0+0]; 
			tempbuf22=buffer[tempPosy0+1];
			tempbuf11=buffer[tempPosy1+0]; 
			tempbuf12=buffer[tempPosy1+1];
			tempbuf01=buffer[tempPosy2+0]; 
			tempbuf02=buffer[tempPosy2+1];
		end
		//开始对图像进行插值,并抛弃边界象素
		if (y>2 && x>2)
		begin//移动滤波器的相对位置
			tempbuf20=tempbuf21; 
			tempbuf21=tempbuf22;
			tempbuf22=buffer[tempPosy0+x-1];
			tempbuf10=tempbuf11; 
			tempbuf11=tempbuf12;
			tempbuf12=buffer[tempPosy1+x-1];
			tempbuf00=tempbuf01; 
			tempbuf01=tempbuf02;
			tempbuf02=buffer[tempPosy2+x-1];
			//计算各个象素的三色值
			//共分四种情况
			if ((x+y)%2==0 && y%2==1)
			begin
				tempR=(tempbuf10+tempbuf12);
				tempR[7:0]=tempR[8:1];
				tempG=tempbuf11;
				tempB=(tempbuf21+tempbuf01);
				tempB[7:0]=tempB[8:1];
			end
			if ((x+y)%2==0 && y%2==0)
			begin
				tempR=(tempbuf21+tempbuf01);
				tempR[7:0]=tempR[8:1];//除2操作
				tempG=tempbuf11;
				tempB=(tempbuf10+tempbuf12);
				tempB[7:0]=tempB[8:1];
			end
			if ((x+y)%2==1 && x%2==1)
			begin
				tempR=tempbuf00+tempbuf20+tempbuf02+tempbuf22;
				tempR[7:0]=tempR[9:2];
				tempG=tempbuf01+tempbuf21+tempbuf10+tempbuf12;
				tempG[7:0]=tempG[9:2];
				tempB=tempbuf11;
			end
			if ((x+y)%2==1 && x%2==0)
			begin
				tempR=tempbuf11;
				tempG=tempbuf01+tempbuf21+tempbuf10+tempbuf12;
				tempG[7:0]=tempG[9:2];//除四操作
				tempB=tempbuf00+tempbuf20+tempbuf02+tempbuf22;
				tempB[7:0]=tempB[9:2];
			end
			//将最终结果赋值给输出值
			Red=tempR[7:0];
			Green=tempG[7:0];
			Blue=tempB[7:0];
		end		

		if (y==YMax)//结束本帧输出
			oframeValid=0;//将帧信号置为无效
		if(x==0&&XMax!=0)//结束本行输出
			olineValid=0;//将行信号置为无效

	end

endmodule

⌨️ 快捷键说明

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