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

news2024/11/26 23:54:07

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日于武汉书

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

分布式系统事务一致性解决方案(基于事务消息)

参考&#xff1a;https://rocketmq.apache.org/zh/docs/featureBehavior/04transactionmessage/ 文章目录 概要错误的方案方案一&#xff1a;业务方自己实现方案二&#xff1a;RocketMQ 事务消息什么是事务消息事务消息处理流程事务消息生命周期使用限制使用示例使用建议 概要 …

WPF —— MVVM 指令执行不同的任务实例

标签页 设置两个按钮&#xff0c; <Button Content"修改状态" Width"100" Height"40" Background"red"Click"Button_Click"></Button><Button Content"测试"Width"100"Height"40&…

java案例-读取xml文件

需求 导入依赖 <dependencies><!-- dom4j --><dependency><groupId>dom4j</groupId><artifactId>dom4j</artifactId><version>1.6.1</version></dependency> </dependencies>代码 SAXReader saxReade…

BERT一个蛋白质-季军-英特尔创新大师杯冷冻电镜蛋白质结构建模大赛-paipai

关联比赛: “创新大师杯”冷冻电镜蛋白质结构建模大赛 解决方案 团队介绍 paipai队、取自 PAIN AI&#xff0c;核心成员如我本人IvanaXu(IvanaXu GitHub)&#xff0c;从事于金融科技业&#xff0c;面向银行信用贷款的风控、运营场景。但我们团队先后打过很多比赛&#xf…

Vue后台系统demo小计

创建项目 1.报错 Error: command failed: npm install --loglevel error --legacy-peer-deps 措施1&#xff1a;node.js文件夹属性 》高级 》选择第一个允许 Users(XXX\Users) &#xff08;对我无用&#xff09; 措施2&#xff1a;PowerShell(以管理员身份运行) 》 cd 想存…

C++ | Leetcode C++题解之第55题跳跃游戏

题目&#xff1a; 题解&#xff1a; class Solution { public:bool canJump(vector<int>& nums) {int n nums.size();int rightmost 0;for (int i 0; i < n; i) {if (i < rightmost) {rightmost max(rightmost, i nums[i]);if (rightmost > n - 1) {r…

【Leetcode每日一题】 动态规划 - 简单多状态 dp 问题 - 打家劫舍 II(难度⭐⭐)(67)

1. 题目解析 题目链接&#xff1a;213. 打家劫舍 II 这个问题的理解其实相当简单&#xff0c;只需看一下示例&#xff0c;基本就能明白其含义了。 2.算法原理 这个问题是经典的“打家劫舍”问题的变种&#xff0c;原问题是在单排房屋中进行偷窃&#xff0c;而这个问题则是在…

利用Triple U.Net结构对冷冻切片HE染色组织学图像进行核实例分割

利用Triple U.Net结构对冷冻切片H&E染色组织学图像进行核实例分割 摘要IntroductionRelated WorksDatasetProposed MethodologyDataset PreparationSegmentation BranchLoss FunctionWatershed Algorithm Nuclei Instance Segmentation of Cryosectioned H&E Stained H…

JavaScript全套检验系统(LIS)源码C# + MVC + SQLserver + Redis 云LIS系统源码 区域医疗云LIS系统源码

JavaScript全套检验系统&#xff08;LIS&#xff09;源码C# MVC SQLserver Redis 云LIS系统源码 区域医疗云LIS系统源码 实验室信息系统&#xff08;Laboratory Information System&#xff0c;缩写LIS&#xff09;是一类用来处理实验室过程信息的软件。这套系统通常与其他信…

ArcGIS基础:便捷分享图层包和地图包

1、分享图层包&#xff1a; 首先&#xff0c;选中要分享的数据&#xff0c;右键创建图层包&#xff0c;修改保存路径。 找到项目描述那一栏&#xff0c;将摘要、标签、描述都填写分享图层包的相关内容。 一切设置好之后&#xff0c;点击右上角的【分析】按钮。 点击分析之后…

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…

MCU自动测量单元:自动化数据采集的未来

随着科技的飞速发展&#xff0c;自动化技术在各个领域中的应用日益广泛。其中&#xff0c;MCU(微控制器)自动测量单元以其高效、精准的特性&#xff0c;成为自动化数据采集领域的佼佼者&#xff0c;引领着未来数据采集技术的革新。本文将深入探讨MCU自动测量单元的原理、优势以…

详解进程控制

目录 一、进程创建 fork() 写时拷贝 fork的应用场景 二、进程退出 什么是进程退出码&#xff1f; 退出码的含义 进程退出方法 三、进程等待 进程等待的必要性 进程等待的方法 wait waitpid status 阻塞与非阻塞 四、进程替换 替换原理 替换函数 命名理解 简…

大数据005-hadoop003-了解MR及Java的简单实现

了解MapReduce MapReduce过程分为两个阶段&#xff1a;map阶段、reduce阶段。每个阶段搜键-值对作为输入和输出。 要执行一个MR任务&#xff0c;需要完成map、reduce函数的代码开发。 Hellow World 【Hadoop权威指南】中的以分析气象数据为例&#xff0c;找到每年的最高气温。…

【论文笔记】Language Models are Few-Shot Learners B部分

Language Models are Few-Shot Learners B 部分 回顾一下第一代 GPT-1 &#xff1a; 设计思路是 “海量无标记文本进行无监督预训练少量有标签文本有监督微调” 范式&#xff1b;模型架构是基于 Transformer 的叠加解码器&#xff08;掩码自注意力机制、残差、Layernorm&#…

Spark核心名词解释与编程

Spark核心概念 名词解释 1)ClusterManager&#xff1a;在Standalone(上述安装的模式&#xff0c;也就是依托于spark集群本身)模式中即为Master&#xff08;主节点&#xff09;&#xff0c;控制整个集群&#xff0c;监控Worker。在YARN模式中为资源管理器ResourceManager(国内…

STM32定时器的OC比较和PWM

系列文章目录 STM32单片机系列专栏 C语言术语和结构总结专栏 文章目录 1. 输出比较(OC) 2. PWM 3. PWM的输出 3.1 高级定时器 3.2 通用定时器 4. PWM的输出结构 5. 代码示例 5.1 PWM.c 5.2 PWM.h 5.3 main.c 这篇文章解释了TIM定时器的内部时钟和外部时钟的使用&a…

AI图书推荐:ChatGPT写论文的流程与策略

论文一直是任何学术学位的顶峰。它展示了学生在研究领域的兴趣和专业知识。撰写论文也是一个学习经验&#xff0c;为学术工作以及专业研究角色做好准备。但是&#xff0c;论文工作总是艰苦的&#xff0c;通常是充满乐趣和创造性的&#xff0c;但有时也是乏味和无聊的。生成式人…

【kettle005】kettle访问Oracle数据库并处理数据至execl文件(已更新)

1.一直以来想写下基于kettle的系列文章&#xff0c;作为较火的数据ETL工具&#xff0c;也是日常项目开发中常用的一款工具&#xff0c;最近刚好挤时间梳理、总结下这块儿的知识体系。 2.熟悉、梳理、总结下Oracle数据库相关知识体系 3.欢迎批评指正&#xff0c;跪谢一键三连&am…

IT廉连看——UniApp——样式绑定

IT廉连看——UniApp——样式绑定 一、样式绑定 两种添加样式的方法&#xff1a; 1、第一种写法 写一个class属性&#xff0c;然后将css样式写在style中。 2、第二种写法 直接把style写在class后面 添加一些效果&#xff1a;字体大小 查看效果 证明这样添加样式是没有问题的…