FPGA实现图像处理之【直方图均衡-寄存器版】

FPGA实现直方图统计

一、图像直方图统计原理

直方图的全称为灰度直方图,是对图像每一灰度间隔内像素个数的统计。即对一张图片中每隔二灰度值的像素数量做统计,然后以直方图的形式展现出来。图下的亮暗分布在直方图中就可以一目了然,直方图在图像前端和后端处理中都有广泛的应用,比如图像的直方图均衡、图像自动曝光控制和图像特征提取等。

image-20240428214846205

二、基于寄存器(逻辑资源)的直方图统计系统框图

图片大小640x480,需要20bit的位宽来计像素的个数。i_img_vld为高时,输入图片数据i_img_data[7:0]有效,“256级灰度灰度值的像素计数”模块统计0~255中灰度级数的个数,“输入有效像素个数计数”模块用于计算i_mg_data已经输入了几个,“256级直方图统计结果分时输出”模块是输入256个灰度级的统计结果,需要256个时钟周期,每个周期输出一级灰度级的结果。

image-20240428220751855

三、代码实现

这个代码简单而且暴力,主要是易于理解,占用较多的逻辑资源。因为这种统计方法,对于i_image_data来说有256个扇出,所以系统时钟频率不会跑的很高,时序很难收敛


`timescale 1ns/1ps

module m_histogram_reg#(
	parameter P_IMAGE_WIDTH=640,
	parameter P_IMAGE_HIGHT=480

)(
	input i_clk,
	input i_rst_n,
	input i_image_vld,
	input [7:0] i_image_data,
	output reg o_result_rdy,
	output reg [19:0] o_result_data
    );
	
localparam P_IMAGE_SIZE = P_IMAGE_HIGHT*P_IMAGE_WIDTH;
reg [19:0] r_hist_cnt[255:0];//每个灰度值统计的计数器

//256个灰度值的直方图统计
always@(posedge i_clk)begin
	if(!i_rst_n)begin
		r_hist_cnt[0] <= 20'd0;
		r_hist_cnt[1] <= 20'd0;
		r_hist_cnt[2] <= 20'd0;
		r_hist_cnt[3] <= 20'd0;
		r_hist_cnt[4] <= 20'd0;
		r_hist_cnt[5] <= 20'd0;
		r_hist_cnt[6] <= 20'd0;
		r_hist_cnt[7] <= 20'd0;
		r_hist_cnt[8] <= 20'd0;
		r_hist_cnt[9] <= 20'd0;
		r_hist_cnt[10] <= 20'd0;
		r_hist_cnt[11] <= 20'd0;
		r_hist_cnt[12] <= 20'd0;
		r_hist_cnt[13] <= 20'd0;
		r_hist_cnt[14] <= 20'd0;
		r_hist_cnt[15] <= 20'd0;
		r_hist_cnt[16] <= 20'd0;
		r_hist_cnt[17] <= 20'd0;
		r_hist_cnt[18] <= 20'd0;
		r_hist_cnt[19] <= 20'd0;
		r_hist_cnt[20] <= 20'd0;
		r_hist_cnt[21] <= 20'd0;
		r_hist_cnt[22] <= 20'd0;
		r_hist_cnt[23] <= 20'd0;
		r_hist_cnt[24] <= 20'd0;
		r_hist_cnt[25] <= 20'd0;
		r_hist_cnt[26] <= 20'd0;
		r_hist_cnt[27] <= 20'd0;
		r_hist_cnt[28] <= 20'd0;
		r_hist_cnt[29] <= 20'd0;
		r_hist_cnt[30] <= 20'd0;
		r_hist_cnt[31] <= 20'd0;
		r_hist_cnt[32] <= 20'd0;
		r_hist_cnt[33] <= 20'd0;
		r_hist_cnt[34] <= 20'd0;
		r_hist_cnt[35] <= 20'd0;
		r_hist_cnt[36] <= 20'd0;
		r_hist_cnt[37] <= 20'd0;
		r_hist_cnt[38] <= 20'd0;
		r_hist_cnt[39] <= 20'd0;
		r_hist_cnt[40] <= 20'd0;
		r_hist_cnt[41] <= 20'd0;
		r_hist_cnt[42] <= 20'd0;
		r_hist_cnt[43] <= 20'd0;
		r_hist_cnt[44] <= 20'd0;
		r_hist_cnt[45] <= 20'd0;
		r_hist_cnt[46] <= 20'd0;
		r_hist_cnt[47] <= 20'd0;
		r_hist_cnt[48] <= 20'd0;
		r_hist_cnt[49] <= 20'd0;
		r_hist_cnt[50] <= 20'd0;
		r_hist_cnt[51] <= 20'd0;
		r_hist_cnt[52] <= 20'd0;
		r_hist_cnt[53] <= 20'd0;
		r_hist_cnt[54] <= 20'd0;
		r_hist_cnt[55] <= 20'd0;
		r_hist_cnt[56] <= 20'd0;
		r_hist_cnt[57] <= 20'd0;
		r_hist_cnt[58] <= 20'd0;
		r_hist_cnt[59] <= 20'd0;
		r_hist_cnt[60] <= 20'd0;
		r_hist_cnt[61] <= 20'd0;
		r_hist_cnt[62] <= 20'd0;
		r_hist_cnt[63] <= 20'd0;
		r_hist_cnt[64] <= 20'd0;
		r_hist_cnt[65] <= 20'd0;
		r_hist_cnt[66] <= 20'd0;
		r_hist_cnt[67] <= 20'd0;
		r_hist_cnt[68] <= 20'd0;
		r_hist_cnt[69] <= 20'd0;
		r_hist_cnt[70] <= 20'd0;
		r_hist_cnt[71] <= 20'd0;
		r_hist_cnt[72] <= 20'd0;
		r_hist_cnt[73] <= 20'd0;
		r_hist_cnt[74] <= 20'd0;
		r_hist_cnt[75] <= 20'd0;
		r_hist_cnt[76] <= 20'd0;
		r_hist_cnt[77] <= 20'd0;
		r_hist_cnt[78] <= 20'd0;
		r_hist_cnt[79] <= 20'd0;
		r_hist_cnt[80] <= 20'd0;
		r_hist_cnt[81] <= 20'd0;
		r_hist_cnt[82] <= 20'd0;
		r_hist_cnt[83] <= 20'd0;
		r_hist_cnt[84] <= 20'd0;
		r_hist_cnt[85] <= 20'd0;
		r_hist_cnt[86] <= 20'd0;
		r_hist_cnt[87] <= 20'd0;
		r_hist_cnt[88] <= 20'd0;
		r_hist_cnt[89] <= 20'd0;
		r_hist_cnt[90] <= 20'd0;
		r_hist_cnt[91] <= 20'd0;
		r_hist_cnt[92] <= 20'd0;
		r_hist_cnt[93] <= 20'd0;
		r_hist_cnt[94] <= 20'd0;
		r_hist_cnt[95] <= 20'd0;
		r_hist_cnt[96] <= 20'd0;
		r_hist_cnt[97] <= 20'd0;
		r_hist_cnt[98] <= 20'd0;
		r_hist_cnt[99] <= 20'd0;
		r_hist_cnt[100] <= 20'd0;
		r_hist_cnt[101] <= 20'd0;
		r_hist_cnt[102] <= 20'd0;
		r_hist_cnt[103] <= 20'd0;
		r_hist_cnt[104] <= 20'd0;
		r_hist_cnt[105] <= 20'd0;
		r_hist_cnt[106] <= 20'd0;
		r_hist_cnt[107] <= 20'd0;
		r_hist_cnt[108] <= 20'd0;
		r_hist_cnt[109] <= 20'd0;
		r_hist_cnt[110] <= 20'd0;
		r_hist_cnt[111] <= 20'd0;
		r_hist_cnt[112] <= 20'd0;
		r_hist_cnt[113] <= 20'd0;
		r_hist_cnt[114] <= 20'd0;
		r_hist_cnt[115] <= 20'd0;
		r_hist_cnt[116] <= 20'd0;
		r_hist_cnt[117] <= 20'd0;
		r_hist_cnt[118] <= 20'd0;
		r_hist_cnt[119] <= 20'd0;
		r_hist_cnt[120] <= 20'd0;
		r_hist_cnt[121] <= 20'd0;
		r_hist_cnt[122] <= 20'd0;
		r_hist_cnt[123] <= 20'd0;
		r_hist_cnt[124] <= 20'd0;
		r_hist_cnt[125] <= 20'd0;
		r_hist_cnt[126] <= 20'd0;
		r_hist_cnt[127] <= 20'd0;
		r_hist_cnt[128] <= 20'd0;
		r_hist_cnt[129] <= 20'd0;
		r_hist_cnt[130] <= 20'd0;
		r_hist_cnt[131] <= 20'd0;
		r_hist_cnt[132] <= 20'd0;
		r_hist_cnt[133] <= 20'd0;
		r_hist_cnt[134] <= 20'd0;
		r_hist_cnt[135] <= 20'd0;
		r_hist_cnt[136] <= 20'd0;
		r_hist_cnt[137] <= 20'd0;
		r_hist_cnt[138] <= 20'd0;
		r_hist_cnt[139] <= 20'd0;
		r_hist_cnt[140] <= 20'd0;
		r_hist_cnt[141] <= 20'd0;
		r_hist_cnt[142] <= 20'd0;
		r_hist_cnt[143] <= 20'd0;
		r_hist_cnt[144] <= 20'd0;
		r_hist_cnt[145] <= 20'd0;
		r_hist_cnt[146] <= 20'd0;
		r_hist_cnt[147] <= 20'd0;
		r_hist_cnt[148] <= 20'd0;
		r_hist_cnt[149] <= 20'd0;
		r_hist_cnt[150] <= 20'd0;
		r_hist_cnt[151] <= 20'd0;
		r_hist_cnt[152] <= 20'd0;
		r_hist_cnt[153] <= 20'd0;
		r_hist_cnt[154] <= 20'd0;
		r_hist_cnt[155] <= 20'd0;
		r_hist_cnt[156] <= 20'd0;
		r_hist_cnt[157] <= 20'd0;
		r_hist_cnt[158] <= 20'd0;
		r_hist_cnt[159] <= 20'd0;
		r_hist_cnt[160] <= 20'd0;
		r_hist_cnt[161] <= 20'd0;
		r_hist_cnt[162] <= 20'd0;
		r_hist_cnt[163] <= 20'd0;
		r_hist_cnt[164] <= 20'd0;
		r_hist_cnt[165] <= 20'd0;
		r_hist_cnt[166] <= 20'd0;
		r_hist_cnt[167] <= 20'd0;
		r_hist_cnt[168] <= 20'd0;
		r_hist_cnt[169] <= 20'd0;
		r_hist_cnt[170] <= 20'd0;
		r_hist_cnt[171] <= 20'd0;
		r_hist_cnt[172] <= 20'd0;
		r_hist_cnt[173] <= 20'd0;
		r_hist_cnt[174] <= 20'd0;
		r_hist_cnt[175] <= 20'd0;
		r_hist_cnt[176] <= 20'd0;
		r_hist_cnt[177] <= 20'd0;
		r_hist_cnt[178] <= 20'd0;
		r_hist_cnt[179] <= 20'd0;
		r_hist_cnt[180] <= 20'd0;
		r_hist_cnt[181] <= 20'd0;
		r_hist_cnt[182] <= 20'd0;
		r_hist_cnt[183] <= 20'd0;
		r_hist_cnt[184] <= 20'd0;
		r_hist_cnt[185] <= 20'd0;
		r_hist_cnt[186] <= 20'd0;
		r_hist_cnt[187] <= 20'd0;
		r_hist_cnt[188] <= 20'd0;
		r_hist_cnt[189] <= 20'd0;
		r_hist_cnt[190] <= 20'd0;
		r_hist_cnt[191] <= 20'd0;
		r_hist_cnt[192] <= 20'd0;
		r_hist_cnt[193] <= 20'd0;
		r_hist_cnt[194] <= 20'd0;
		r_hist_cnt[195] <= 20'd0;
		r_hist_cnt[196] <= 20'd0;
		r_hist_cnt[197] <= 20'd0;
		r_hist_cnt[198] <= 20'd0;
		r_hist_cnt[199] <= 20'd0;
		r_hist_cnt[200] <= 20'd0;
		r_hist_cnt[201] <= 20'd0;
		r_hist_cnt[202] <= 20'd0;
		r_hist_cnt[203] <= 20'd0;
		r_hist_cnt[204] <= 20'd0;
		r_hist_cnt[205] <= 20'd0;
		r_hist_cnt[206] <= 20'd0;
		r_hist_cnt[207] <= 20'd0;
		r_hist_cnt[208] <= 20'd0;
		r_hist_cnt[209] <= 20'd0;
		r_hist_cnt[210] <= 20'd0;
		r_hist_cnt[211] <= 20'd0;
		r_hist_cnt[212] <= 20'd0;
		r_hist_cnt[213] <= 20'd0;
		r_hist_cnt[214] <= 20'd0;
		r_hist_cnt[215] <= 20'd0;
		r_hist_cnt[216] <= 20'd0;
		r_hist_cnt[217] <= 20'd0;
		r_hist_cnt[218] <= 20'd0;
		r_hist_cnt[219] <= 20'd0;
		r_hist_cnt[220] <= 20'd0;
		r_hist_cnt[221] <= 20'd0;
		r_hist_cnt[222] <= 20'd0;
		r_hist_cnt[223] <= 20'd0;
		r_hist_cnt[224] <= 20'd0;
		r_hist_cnt[225] <= 20'd0;
		r_hist_cnt[226] <= 20'd0;
		r_hist_cnt[227] <= 20'd0;
		r_hist_cnt[228] <= 20'd0;
		r_hist_cnt[229] <= 20'd0;
		r_hist_cnt[230] <= 20'd0;
		r_hist_cnt[231] <= 20'd0;
		r_hist_cnt[232] <= 20'd0;
		r_hist_cnt[233] <= 20'd0;
		r_hist_cnt[234] <= 20'd0;
		r_hist_cnt[235] <= 20'd0;
		r_hist_cnt[236] <= 20'd0;
		r_hist_cnt[237] <= 20'd0;
		r_hist_cnt[238] <= 20'd0;
		r_hist_cnt[239] <= 20'd0;
		r_hist_cnt[240] <= 20'd0;
		r_hist_cnt[241] <= 20'd0;
		r_hist_cnt[242] <= 20'd0;
		r_hist_cnt[243] <= 20'd0;
		r_hist_cnt[244] <= 20'd0;
		r_hist_cnt[245] <= 20'd0;
		r_hist_cnt[246] <= 20'd0;
		r_hist_cnt[247] <= 20'd0;
		r_hist_cnt[248] <= 20'd0;
		r_hist_cnt[249] <= 20'd0;
		r_hist_cnt[250] <= 20'd0;
		r_hist_cnt[251] <= 20'd0;
		r_hist_cnt[252] <= 20'd0;
		r_hist_cnt[253] <= 20'd0;
		r_hist_cnt[254] <= 20'd0;
		r_hist_cnt[255] <= 20'd0;
	end 
	else if(i_image_vld)begin
		case(i_image_data)
			8'd0:r_hist_cnt[0] <=r_hist_cnt[0] + 1;
			8'd1:r_hist_cnt[1] <=r_hist_cnt[1] + 1;
			8'd2:r_hist_cnt[2] <=r_hist_cnt[2] + 1;
			8'd3:r_hist_cnt[3] <=r_hist_cnt[3] + 1;
			8'd4:r_hist_cnt[4] <=r_hist_cnt[4] + 1;
			8'd5:r_hist_cnt[5] <=r_hist_cnt[5] + 1;
			8'd6:r_hist_cnt[6] <=r_hist_cnt[6] + 1;
			8'd7:r_hist_cnt[7] <=r_hist_cnt[7] + 1;
			8'd8:r_hist_cnt[8] <=r_hist_cnt[8] + 1;
			8'd9:r_hist_cnt[9] <=r_hist_cnt[9] + 1;
			8'd10:r_hist_cnt[10] <=r_hist_cnt[10] + 1;
			8'd11:r_hist_cnt[11] <=r_hist_cnt[11] + 1;
			8'd12:r_hist_cnt[12] <=r_hist_cnt[12] + 1;
			8'd13:r_hist_cnt[13] <=r_hist_cnt[13] + 1;
			8'd14:r_hist_cnt[14] <=r_hist_cnt[14] + 1;
			8'd15:r_hist_cnt[15] <=r_hist_cnt[15] + 1;
			8'd16:r_hist_cnt[16] <=r_hist_cnt[16] + 1;
			8'd17:r_hist_cnt[17] <=r_hist_cnt[17] + 1;
			8'd18:r_hist_cnt[18] <=r_hist_cnt[18] + 1;
			8'd19:r_hist_cnt[19] <=r_hist_cnt[19] + 1;
			8'd20:r_hist_cnt[20] <=r_hist_cnt[20] + 1;
			8'd21:r_hist_cnt[21] <=r_hist_cnt[21] + 1;
			8'd22:r_hist_cnt[22] <=r_hist_cnt[22] + 1;
			8'd23:r_hist_cnt[23] <=r_hist_cnt[23] + 1;
			8'd24:r_hist_cnt[24] <=r_hist_cnt[24] + 1;
			8'd25:r_hist_cnt[25] <=r_hist_cnt[25] + 1;
			8'd26:r_hist_cnt[26] <=r_hist_cnt[26] + 1;
			8'd27:r_hist_cnt[27] <=r_hist_cnt[27] + 1;
			8'd28:r_hist_cnt[28] <=r_hist_cnt[28] + 1;
			8'd29:r_hist_cnt[29] <=r_hist_cnt[29] + 1;
			8'd30:r_hist_cnt[30] <=r_hist_cnt[30] + 1;
			8'd31:r_hist_cnt[31] <=r_hist_cnt[31] + 1;
			8'd32:r_hist_cnt[32] <=r_hist_cnt[32] + 1;
			8'd33:r_hist_cnt[33] <=r_hist_cnt[33] + 1;
			8'd34:r_hist_cnt[34] <=r_hist_cnt[34] + 1;
			8'd35:r_hist_cnt[35] <=r_hist_cnt[35] + 1;
			8'd36:r_hist_cnt[36] <=r_hist_cnt[36] + 1;
			8'd37:r_hist_cnt[37] <=r_hist_cnt[37] + 1;
			8'd38:r_hist_cnt[38] <=r_hist_cnt[38] + 1;
			8'd39:r_hist_cnt[39] <=r_hist_cnt[39] + 1;
			8'd40:r_hist_cnt[40] <=r_hist_cnt[40] + 1;
			8'd41:r_hist_cnt[41] <=r_hist_cnt[41] + 1;
			8'd42:r_hist_cnt[42] <=r_hist_cnt[42] + 1;
			8'd43:r_hist_cnt[43] <=r_hist_cnt[43] + 1;
			8'd44:r_hist_cnt[44] <=r_hist_cnt[44] + 1;
			8'd45:r_hist_cnt[45] <=r_hist_cnt[45] + 1;
			8'd46:r_hist_cnt[46] <=r_hist_cnt[46] + 1;
			8'd47:r_hist_cnt[47] <=r_hist_cnt[47] + 1;
			8'd48:r_hist_cnt[48] <=r_hist_cnt[48] + 1;
			8'd49:r_hist_cnt[49] <=r_hist_cnt[49] + 1;
			8'd50:r_hist_cnt[50] <=r_hist_cnt[50] + 1;
			8'd51:r_hist_cnt[51] <=r_hist_cnt[51] + 1;
			8'd52:r_hist_cnt[52] <=r_hist_cnt[52] + 1;
			8'd53:r_hist_cnt[53] <=r_hist_cnt[53] + 1;
			8'd54:r_hist_cnt[54] <=r_hist_cnt[54] + 1;
			8'd55:r_hist_cnt[55] <=r_hist_cnt[55] + 1;
			8'd56:r_hist_cnt[56] <=r_hist_cnt[56] + 1;
			8'd57:r_hist_cnt[57] <=r_hist_cnt[57] + 1;
			8'd58:r_hist_cnt[58] <=r_hist_cnt[58] + 1;
			8'd59:r_hist_cnt[59] <=r_hist_cnt[59] + 1;
			8'd60:r_hist_cnt[60] <=r_hist_cnt[60] + 1;
			8'd61:r_hist_cnt[61] <=r_hist_cnt[61] + 1;
			8'd62:r_hist_cnt[62] <=r_hist_cnt[62] + 1;
			8'd63:r_hist_cnt[63] <=r_hist_cnt[63] + 1;
			8'd64:r_hist_cnt[64] <=r_hist_cnt[64] + 1;
			8'd65:r_hist_cnt[65] <=r_hist_cnt[65] + 1;
			8'd66:r_hist_cnt[66] <=r_hist_cnt[66] + 1;
			8'd67:r_hist_cnt[67] <=r_hist_cnt[67] + 1;
			8'd68:r_hist_cnt[68] <=r_hist_cnt[68] + 1;
			8'd69:r_hist_cnt[69] <=r_hist_cnt[69] + 1;
			8'd70:r_hist_cnt[70] <=r_hist_cnt[70] + 1;
			8'd71:r_hist_cnt[71] <=r_hist_cnt[71] + 1;
			8'd72:r_hist_cnt[72] <=r_hist_cnt[72] + 1;
			8'd73:r_hist_cnt[73] <=r_hist_cnt[73] + 1;
			8'd74:r_hist_cnt[74] <=r_hist_cnt[74] + 1;
			8'd75:r_hist_cnt[75] <=r_hist_cnt[75] + 1;
			8'd76:r_hist_cnt[76] <=r_hist_cnt[76] + 1;
			8'd77:r_hist_cnt[77] <=r_hist_cnt[77] + 1;
			8'd78:r_hist_cnt[78] <=r_hist_cnt[78] + 1;
			8'd79:r_hist_cnt[79] <=r_hist_cnt[79] + 1;
			8'd80:r_hist_cnt[80] <=r_hist_cnt[80] + 1;
			8'd81:r_hist_cnt[81] <=r_hist_cnt[81] + 1;
			8'd82:r_hist_cnt[82] <=r_hist_cnt[82] + 1;
			8'd83:r_hist_cnt[83] <=r_hist_cnt[83] + 1;
			8'd84:r_hist_cnt[84] <=r_hist_cnt[84] + 1;
			8'd85:r_hist_cnt[85] <=r_hist_cnt[85] + 1;
			8'd86:r_hist_cnt[86] <=r_hist_cnt[86] + 1;
			8'd87:r_hist_cnt[87] <=r_hist_cnt[87] + 1;
			8'd88:r_hist_cnt[88] <=r_hist_cnt[88] + 1;
			8'd89:r_hist_cnt[89] <=r_hist_cnt[89] + 1;
			8'd90:r_hist_cnt[90] <=r_hist_cnt[90] + 1;
			8'd91:r_hist_cnt[91] <=r_hist_cnt[91] + 1;
			8'd92:r_hist_cnt[92] <=r_hist_cnt[92] + 1;
			8'd93:r_hist_cnt[93] <=r_hist_cnt[93] + 1;
			8'd94:r_hist_cnt[94] <=r_hist_cnt[94] + 1;
			8'd95:r_hist_cnt[95] <=r_hist_cnt[95] + 1;
			8'd96:r_hist_cnt[96] <=r_hist_cnt[96] + 1;
			8'd97:r_hist_cnt[97] <=r_hist_cnt[97] + 1;
			8'd98:r_hist_cnt[98] <=r_hist_cnt[98] + 1;
			8'd99:r_hist_cnt[99] <=r_hist_cnt[99] + 1;
			8'd100:r_hist_cnt[100] <=r_hist_cnt[100] + 1;
			8'd101:r_hist_cnt[101] <=r_hist_cnt[101] + 1;
			8'd102:r_hist_cnt[102] <=r_hist_cnt[102] + 1;
			8'd103:r_hist_cnt[103] <=r_hist_cnt[103] + 1;
			8'd104:r_hist_cnt[104] <=r_hist_cnt[104] + 1;
			8'd105:r_hist_cnt[105] <=r_hist_cnt[105] + 1;
			8'd106:r_hist_cnt[106] <=r_hist_cnt[106] + 1;
			8'd107:r_hist_cnt[107] <=r_hist_cnt[107] + 1;
			8'd108:r_hist_cnt[108] <=r_hist_cnt[108] + 1;
			8'd109:r_hist_cnt[109] <=r_hist_cnt[109] + 1;
			8'd110:r_hist_cnt[110] <=r_hist_cnt[110] + 1;
			8'd111:r_hist_cnt[111] <=r_hist_cnt[111] + 1;
			8'd112:r_hist_cnt[112] <=r_hist_cnt[112] + 1;
			8'd113:r_hist_cnt[113] <=r_hist_cnt[113] + 1;
			8'd114:r_hist_cnt[114] <=r_hist_cnt[114] + 1;
			8'd115:r_hist_cnt[115] <=r_hist_cnt[115] + 1;
			8'd116:r_hist_cnt[116] <=r_hist_cnt[116] + 1;
			8'd117:r_hist_cnt[117] <=r_hist_cnt[117] + 1;
			8'd118:r_hist_cnt[118] <=r_hist_cnt[118] + 1;
			8'd119:r_hist_cnt[119] <=r_hist_cnt[119] + 1;
			8'd120:r_hist_cnt[120] <=r_hist_cnt[120] + 1;
			8'd121:r_hist_cnt[121] <=r_hist_cnt[121] + 1;
			8'd122:r_hist_cnt[122] <=r_hist_cnt[122] + 1;
			8'd123:r_hist_cnt[123] <=r_hist_cnt[123] + 1;
			8'd124:r_hist_cnt[124] <=r_hist_cnt[124] + 1;
			8'd125:r_hist_cnt[125] <=r_hist_cnt[125] + 1;
			8'd126:r_hist_cnt[126] <=r_hist_cnt[126] + 1;
			8'd127:r_hist_cnt[127] <=r_hist_cnt[127] + 1;
			8'd128:r_hist_cnt[128] <=r_hist_cnt[128] + 1;
			8'd129:r_hist_cnt[129] <=r_hist_cnt[129] + 1;
			8'd130:r_hist_cnt[130] <=r_hist_cnt[130] + 1;
			8'd131:r_hist_cnt[131] <=r_hist_cnt[131] + 1;
			8'd132:r_hist_cnt[132] <=r_hist_cnt[132] + 1;
			8'd133:r_hist_cnt[133] <=r_hist_cnt[133] + 1;
			8'd134:r_hist_cnt[134] <=r_hist_cnt[134] + 1;
			8'd135:r_hist_cnt[135] <=r_hist_cnt[135] + 1;
			8'd136:r_hist_cnt[136] <=r_hist_cnt[136] + 1;
			8'd137:r_hist_cnt[137] <=r_hist_cnt[137] + 1;
			8'd138:r_hist_cnt[138] <=r_hist_cnt[138] + 1;
			8'd139:r_hist_cnt[139] <=r_hist_cnt[139] + 1;
			8'd140:r_hist_cnt[140] <=r_hist_cnt[140] + 1;
			8'd141:r_hist_cnt[141] <=r_hist_cnt[141] + 1;
			8'd142:r_hist_cnt[142] <=r_hist_cnt[142] + 1;
			8'd143:r_hist_cnt[143] <=r_hist_cnt[143] + 1;
			8'd144:r_hist_cnt[144] <=r_hist_cnt[144] + 1;
			8'd145:r_hist_cnt[145] <=r_hist_cnt[145] + 1;
			8'd146:r_hist_cnt[146] <=r_hist_cnt[146] + 1;
			8'd147:r_hist_cnt[147] <=r_hist_cnt[147] + 1;
			8'd148:r_hist_cnt[148] <=r_hist_cnt[148] + 1;
			8'd149:r_hist_cnt[149] <=r_hist_cnt[149] + 1;
			8'd150:r_hist_cnt[150] <=r_hist_cnt[150] + 1;
			8'd151:r_hist_cnt[151] <=r_hist_cnt[151] + 1;
			8'd152:r_hist_cnt[152] <=r_hist_cnt[152] + 1;
			8'd153:r_hist_cnt[153] <=r_hist_cnt[153] + 1;
			8'd154:r_hist_cnt[154] <=r_hist_cnt[154] + 1;
			8'd155:r_hist_cnt[155] <=r_hist_cnt[155] + 1;
			8'd156:r_hist_cnt[156] <=r_hist_cnt[156] + 1;
			8'd157:r_hist_cnt[157] <=r_hist_cnt[157] + 1;
			8'd158:r_hist_cnt[158] <=r_hist_cnt[158] + 1;
			8'd159:r_hist_cnt[159] <=r_hist_cnt[159] + 1;
			8'd160:r_hist_cnt[160] <=r_hist_cnt[160] + 1;
			8'd161:r_hist_cnt[161] <=r_hist_cnt[161] + 1;
			8'd162:r_hist_cnt[162] <=r_hist_cnt[162] + 1;
			8'd163:r_hist_cnt[163] <=r_hist_cnt[163] + 1;
			8'd164:r_hist_cnt[164] <=r_hist_cnt[164] + 1;
			8'd165:r_hist_cnt[165] <=r_hist_cnt[165] + 1;
			8'd166:r_hist_cnt[166] <=r_hist_cnt[166] + 1;
			8'd167:r_hist_cnt[167] <=r_hist_cnt[167] + 1;
			8'd168:r_hist_cnt[168] <=r_hist_cnt[168] + 1;
			8'd169:r_hist_cnt[169] <=r_hist_cnt[169] + 1;
			8'd170:r_hist_cnt[170] <=r_hist_cnt[170] + 1;
			8'd171:r_hist_cnt[171] <=r_hist_cnt[171] + 1;
			8'd172:r_hist_cnt[172] <=r_hist_cnt[172] + 1;
			8'd173:r_hist_cnt[173] <=r_hist_cnt[173] + 1;
			8'd174:r_hist_cnt[174] <=r_hist_cnt[174] + 1;
			8'd175:r_hist_cnt[175] <=r_hist_cnt[175] + 1;
			8'd176:r_hist_cnt[176] <=r_hist_cnt[176] + 1;
			8'd177:r_hist_cnt[177] <=r_hist_cnt[177] + 1;
			8'd178:r_hist_cnt[178] <=r_hist_cnt[178] + 1;
			8'd179:r_hist_cnt[179] <=r_hist_cnt[179] + 1;
			8'd180:r_hist_cnt[180] <=r_hist_cnt[180] + 1;
			8'd181:r_hist_cnt[181] <=r_hist_cnt[181] + 1;
			8'd182:r_hist_cnt[182] <=r_hist_cnt[182] + 1;
			8'd183:r_hist_cnt[183] <=r_hist_cnt[183] + 1;
			8'd184:r_hist_cnt[184] <=r_hist_cnt[184] + 1;
			8'd185:r_hist_cnt[185] <=r_hist_cnt[185] + 1;
			8'd186:r_hist_cnt[186] <=r_hist_cnt[186] + 1;
			8'd187:r_hist_cnt[187] <=r_hist_cnt[187] + 1;
			8'd188:r_hist_cnt[188] <=r_hist_cnt[188] + 1;
			8'd189:r_hist_cnt[189] <=r_hist_cnt[189] + 1;
			8'd190:r_hist_cnt[190] <=r_hist_cnt[190] + 1;
			8'd191:r_hist_cnt[191] <=r_hist_cnt[191] + 1;
			8'd192:r_hist_cnt[192] <=r_hist_cnt[192] + 1;
			8'd193:r_hist_cnt[193] <=r_hist_cnt[193] + 1;
			8'd194:r_hist_cnt[194] <=r_hist_cnt[194] + 1;
			8'd195:r_hist_cnt[195] <=r_hist_cnt[195] + 1;
			8'd196:r_hist_cnt[196] <=r_hist_cnt[196] + 1;
			8'd197:r_hist_cnt[197] <=r_hist_cnt[197] + 1;
			8'd198:r_hist_cnt[198] <=r_hist_cnt[198] + 1;
			8'd199:r_hist_cnt[199] <=r_hist_cnt[199] + 1;
			8'd200:r_hist_cnt[200] <=r_hist_cnt[200] + 1;
			8'd201:r_hist_cnt[201] <=r_hist_cnt[201] + 1;
			8'd202:r_hist_cnt[202] <=r_hist_cnt[202] + 1;
			8'd203:r_hist_cnt[203] <=r_hist_cnt[203] + 1;
			8'd204:r_hist_cnt[204] <=r_hist_cnt[204] + 1;
			8'd205:r_hist_cnt[205] <=r_hist_cnt[205] + 1;
			8'd206:r_hist_cnt[206] <=r_hist_cnt[206] + 1;
			8'd207:r_hist_cnt[207] <=r_hist_cnt[207] + 1;
			8'd208:r_hist_cnt[208] <=r_hist_cnt[208] + 1;
			8'd209:r_hist_cnt[209] <=r_hist_cnt[209] + 1;
			8'd210:r_hist_cnt[210] <=r_hist_cnt[210] + 1;
			8'd211:r_hist_cnt[211] <=r_hist_cnt[211] + 1;
			8'd212:r_hist_cnt[212] <=r_hist_cnt[212] + 1;
			8'd213:r_hist_cnt[213] <=r_hist_cnt[213] + 1;
			8'd214:r_hist_cnt[214] <=r_hist_cnt[214] + 1;
			8'd215:r_hist_cnt[215] <=r_hist_cnt[215] + 1;
			8'd216:r_hist_cnt[216] <=r_hist_cnt[216] + 1;
			8'd217:r_hist_cnt[217] <=r_hist_cnt[217] + 1;
			8'd218:r_hist_cnt[218] <=r_hist_cnt[218] + 1;
			8'd219:r_hist_cnt[219] <=r_hist_cnt[219] + 1;
			8'd220:r_hist_cnt[220] <=r_hist_cnt[220] + 1;
			8'd221:r_hist_cnt[221] <=r_hist_cnt[221] + 1;
			8'd222:r_hist_cnt[222] <=r_hist_cnt[222] + 1;
			8'd223:r_hist_cnt[223] <=r_hist_cnt[223] + 1;
			8'd224:r_hist_cnt[224] <=r_hist_cnt[224] + 1;
			8'd225:r_hist_cnt[225] <=r_hist_cnt[225] + 1;
			8'd226:r_hist_cnt[226] <=r_hist_cnt[226] + 1;
			8'd227:r_hist_cnt[227] <=r_hist_cnt[227] + 1;
			8'd228:r_hist_cnt[228] <=r_hist_cnt[228] + 1;
			8'd229:r_hist_cnt[229] <=r_hist_cnt[229] + 1;
			8'd230:r_hist_cnt[230] <=r_hist_cnt[230] + 1;
			8'd231:r_hist_cnt[231] <=r_hist_cnt[231] + 1;
			8'd232:r_hist_cnt[232] <=r_hist_cnt[232] + 1;
			8'd233:r_hist_cnt[233] <=r_hist_cnt[233] + 1;
			8'd234:r_hist_cnt[234] <=r_hist_cnt[234] + 1;
			8'd235:r_hist_cnt[235] <=r_hist_cnt[235] + 1;
			8'd236:r_hist_cnt[236] <=r_hist_cnt[236] + 1;
			8'd237:r_hist_cnt[237] <=r_hist_cnt[237] + 1;
			8'd238:r_hist_cnt[238] <=r_hist_cnt[238] + 1;
			8'd239:r_hist_cnt[239] <=r_hist_cnt[239] + 1;
			8'd240:r_hist_cnt[240] <=r_hist_cnt[240] + 1;
			8'd241:r_hist_cnt[241] <=r_hist_cnt[241] + 1;
			8'd242:r_hist_cnt[242] <=r_hist_cnt[242] + 1;
			8'd243:r_hist_cnt[243] <=r_hist_cnt[243] + 1;
			8'd244:r_hist_cnt[244] <=r_hist_cnt[244] + 1;
			8'd245:r_hist_cnt[245] <=r_hist_cnt[245] + 1;
			8'd246:r_hist_cnt[246] <=r_hist_cnt[246] + 1;
			8'd247:r_hist_cnt[247] <=r_hist_cnt[247] + 1;
			8'd248:r_hist_cnt[248] <=r_hist_cnt[248] + 1;
			8'd249:r_hist_cnt[249] <=r_hist_cnt[249] + 1;
			8'd250:r_hist_cnt[250] <=r_hist_cnt[250] + 1;
			8'd251:r_hist_cnt[251] <=r_hist_cnt[251] + 1;
			8'd252:r_hist_cnt[252] <=r_hist_cnt[252] + 1;
			8'd253:r_hist_cnt[253] <=r_hist_cnt[253] + 1;
			8'd254:r_hist_cnt[254] <=r_hist_cnt[254] + 1;
			8'd255:r_hist_cnt[255] <=r_hist_cnt[255] + 1;
			default:;
		endcase
	end 
	
	else;
	
end 	

//输入像素计数器,一张图片已经输入了多少个像素
reg[19:0] r_pix_cnt;
wire w_one_frame_done;//一帧图像处理完成标志
always@(posedge i_clk) begin
	if(!i_rst_n)
		r_pix_cnt <= 20'd0;
	else if(w_one_frame_done)//计满一帧图像是,计数器清零。
		r_pix_cnt <=0;
	else if(i_image_vld)
		r_pix_cnt <= r_pix_cnt + 1;
	else;
end 

assign w_one_frame_done = (r_pix_cnt==P_IMAGE_SIZE)?1:0;

//直方图统计结果输出计数

reg [8:0] r_result_cnt;

always@(posedge i_clk) begin
	if(!i_rst_n)
		r_result_cnt<=9'd0;
	else if(w_one_frame_done)
		r_result_cnt <= 9'd1;
	else if( (r_result_cnt>9'd0) && (r_result_cnt<9'd256)) 
		r_result_cnt <= r_result_cnt +1;
	else
		r_result_cnt<=9'd0;
end 

//直方图统计结果的输出
//output reg o_result_rdy,
//output reg [19:0] o_result_data
always@(posedge i_clk) begin
	if(!i_rst_n)
		o_result_rdy <= 0;
	else if(r_result_cnt !=9'd0)
		o_result_rdy <= 1;
	else
		o_result_rdy <=0;
end 	

always@(posedge i_clk) begin
	o_result_data <= r_hist_cnt[r_result_cnt-1];
end 	

endmodule


直方图滤波的Matalb实现可以参考我另一篇博客,里面详细介绍了直方图滤波的原理:
MATLAB图像处理之【直方图均衡】传送门

--晓凡  2024428日于武汉书

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/582130.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【数据结构与算法】力扣 225. 用队列实现栈

题目描述 请你仅使用两个队列实现一个后入先出&#xff08;LIFO&#xff09;的栈&#xff0c;并支持普通栈的全部四种操作&#xff08;push、top、pop 和 empty&#xff09;。 实现 MyStack 类&#xff1a; void push(int x) 将元素 x 压入栈顶。int pop() 移除并返回栈顶元…

AI项目二十:基于YOLOv8实例分割的DeepSORT多目标跟踪

若该文为原创文章&#xff0c;转载请注明原文出处。 前面提及目标跟踪使用的方法有很多&#xff0c;更多的是Deepsort方法。 本篇博客记录YOLOv8的实例分割deepsort视觉跟踪算法。结合YOLOv8的目标检测分割和deepsort的特征跟踪&#xff0c;该算法在复杂环境下确保了目标的准…

R语言的基本图形

一&#xff0c;条形图 安装包 install.packages("vcd") 绘制简单的条形图 barplot(c(1,2,4,5,6,3)) 水平条形图 barplot(c(1,2,4,5,6,3),horiz TRUE) 堆砌条形图 > d1<-c("Placebo","Treated") > d2<-c("None",&qu…

linux运行python怎么结束

假如你已经进入到【>>>】&#xff0c;那么输入【quit&#xff08;&#xff09;】&#xff0c;然后按一下回车键即可退出了。 如果是想要关闭窗口的&#xff0c;那么直接在这个窗口上按【ctrld】。

vue2集成ElementUI编写登录页面

目录 1. 整理目录文件&#xff1a; a. app.vue文件如下&#xff1a; b. Login.vue文件如下&#xff1a; c. router/index.js文件如下&#xff1a; d. 删除components中的文件&#xff1a; e. 最终项目目录整理如下&#xff1a; 2. 集成ElementUI编写登录页面 a. 安装El…

Vue3 v3.4之前如何实现组件中多个值的双向绑定?

文章目录 基础代码1. watch2. computed&#xff08;推荐&#xff09; 官方给的例子是关于el-input的&#xff0c;如下。但是input不是所有组件标签都有的属性啊&#xff0c;有没有一种通用的办法呢&#xff1f; <script setup> defineProps({firstName: String,lastName…

Docker容器:搭建LNMP架构

目录 前言 1、任务要求 2、Nginx 镜像创建 2.1 建立工作目录并上传相关安装包 2.2 编写 Nginx Dockerfile 脚本 2.3 准备 nginx.conf 配置文件 2.4 生成镜像 2.5 创建 Nginx 镜像的容器 2.6 验证nginx 3、Mysql 镜像创建 3.1 建立工作目录并上传相关安装包 3.2 编写…

FANUC机器人SOCKET断开KAREL程序编写

一、添加一个.KL文件创建编辑断开指令 添加一个KL文件用来创建karel程序中socket断开指令 二、断开连接程序karel代码 PROGRAM SOC_DIS %COMMENT SOCKET断开 %INCLUDE klevccdf VAR str_input,str_val : STRING[20] status,data_type,int_val : INTEGER rel_val : REALBEGING…

【Linux】文件打包解压_tar_zip

文章目录 &#x1f4d1;引言&#xff1a;一、文件打包压缩1.1 什么是文件打包压缩&#xff1f;1.2 为什么需要文件打包压缩&#xff1f; 二、打包解压2.1 zip2.2 unzip2.3 tar指令 &#x1f324;️全篇小结&#xff1a; &#x1f4d1;引言&#xff1a; 在Linux操作系统中&#…

简单易懂的下载学浪视频教程- 小浪助手

接下来我就教大家如何通过小浪助手&#xff0c;轻松下载你想要下载的学浪app视频 首先准备好小浪助手 工具我已经打包好了&#xff0c;有需要的自己取一下 学浪下载器链接&#xff1a;https://pan.baidu.com/s/1djUmmnsfLEt_oD2V7loO-g?pwd1234 提取码&#xff1a;1234 -…

LLaMA3(Meta)微调SFT实战Meta-Llama-3-8B-Instruct

LlaMA3-SFT LlaMA3-SFT, Meta-Llama-3-8B/Meta-Llama-3-8B-Instruct微调(transformers)/LORA(peft)/推理 项目地址 https://github.com/yongzhuo/LLaMA3-SFT默认数据类型为bfloat6 备注 1. 非常重要: weights要用bfloat16/fp32/tf32(第二版大模型基本共识), 不要用fp16, f…

Llama 3 基于知识库应用实践(一)

一、概述 Llama 3 是Meta最新推出的开源大语言模型&#xff0c;其8B和13B参数的模型的性能与之前的Llama 2相比实现了质的飞跃。以下是官方给出的模型性能评测对比结果&#xff08;引自&#xff1a;https://ai.meta.com/blog/meta-llama-3/&#xff09;&#xff0c;如Llama 3 …

后端学习记录~~JavaSE篇(Module08-异常 上 )

总览&#xff1a; Java概述&#xff1a; 思维导图文件在本人个人主页上-----资源模块 资源详情&#xff08;免费下载&#xff09;&#xff1a;Java学习思维导图异常篇资源-CSDN文库https://download.csdn.net/download/m0_61589682/89238330 整体展示&#xff1a;

文件上传安全以及防止无限制文件上传

文件上传安全以及防止无限制文件上传 在网络应用中&#xff0c;文件上传是一项常见功能&#xff0c;用户可以通过它上传图片、文档或其他媒体文件。然而&#xff0c;如果没有适当的安全措施&#xff0c;文件上传功能可能成为安全漏洞的源头。本文将探讨文件上传过程中的安全风…

小米汽车充电枪继电器信号

继电器型号&#xff1a; 参考链接 小米SU7&#xff0c;便捷充放电枪拆解 (qq.com)https://mp.weixin.qq.com/s?__bizMzU5ODA2NDg4OQ&mid2247486086&idx1&sn0dd4e7c9f7c72d10ea1c9f506faabfcc&chksmfe48a110c93f2806f6e000f6dc6b67569f6e504220bec14654ccce7d…

秋招后端开发面试题 - JVM底层原理

目录 JVM底层原理前言面试题Java 对象的创建过程&#xff1f;什么是指针碰撞&#xff1f;什么是空闲列表&#xff1f;/ 内存分配的两种方式&#xff1f;JVM 里 new 对象时&#xff0c;堆会发生抢占吗&#xff1f;JVM 是怎么设计来保证线程安全的&#xff1f;/ 内存分配并发问题…

语音识别的基本概念

语音识别的基本概念​​​​​​​ ​​​​​​​ 言语是一种复杂的现象。人们很少了解它是如何产生和感知的。天真的想法常常是语音是由单词构成的&#xff0c;而每个单词又由音素组成。不幸的是&#xff0c;现实却大不相同。语音是一个动态过程&#xff0c;没有明确区分的…

Spring AI聊天功能开发

一、引入依赖 继承父版本的springboot依赖&#xff0c;最好是比较新的依赖。 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.4</version><relativePat…

JS实现对用户名、密码进行正则表达式判断,按钮绑定多个事件,网页跳转

目标&#xff1a;使用JS实现对用户名和密码进行正则表达式判断&#xff0c;用户名和密码正确时&#xff0c;进行网页跳转。 用户名、密码的正则表达式检验 HTML代码&#xff1a; <button type"submit" id"login-btn" /*onclick"login();alidate…

Spring Boot | Spring Boot 实现 “Redis缓存管理“

目录 : Spring Boot 实现 "Redis缓存管理" :一、Spring Boot 支持的 "缓存组件" &#xff08; 如果 “没有” 明确指定使用自定义的 "cacheManager "或 "cacheResolver" &#xff0c;此时 SpringBoot会按照“预先定义的顺序” 启动一个…