Skip to content

Katia median filter#9

Open
katiaohmacht wants to merge 9 commits into
mainfrom
Katia-Median-Filter
Open

Katia median filter#9
katiaohmacht wants to merge 9 commits into
mainfrom
Katia-Median-Filter

Conversation

@katiaohmacht
Copy link
Copy Markdown
Collaborator

works

Comment thread median_filter/rtl/bram.sv
@@ -0,0 +1,25 @@
module bram #(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to avoid nitpicks in the review but lmk if you want me to add them

localparam int ADDR_H = $clog2(IMAGE_HEIGHT);
localparam int PIXEL_W = 24;

function automatic logic [7:0] max4_u8(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way you find the min and max is inefficient.
Here, you evaluate a > b and a < b in the next function. For our purposes, !(a < b) = a > b. If you restructured your code, you could have saved 2 8-bit comparisons

input logic [7:0] a,
input logic [7:0] b,
input logic [7:0] c,
input logic [7:0] d
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only going to say this once, but no magic numbers

end
endfunction

function automatic pixel_t to_pixel_fn(input logic [23:0] a);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions don't depend on module parameters. You can move them to a package to clean them up

bram #(
.BRAM_ADDR_WIDTH (ADDR_W),
.BRAM_DATA_WIDTH (PIXEL_W)
) line_buffer_bram (
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of BRAM!

pixel_t input_pipe1_q;
pixel_t input_pipe2_d;
pixel_t input_pipe2_q;
logic input_pipe1_valid_d;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Don't use the same name over and over ie: input_pipe1_valid_q, input_pipe2_valid_q, input_pipe3_valid_q. If they are just the same signal, just one cycle delayed, make it a shift register.


// pack input pixel to BRAM data
logic [23:0] bram_input;
always_comb bram_input = from_pixel_fn(pixel_valid_if_i.pixel);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use an assign

green_total = d0.green + d1.green + d2.green + d3.green;
blue_total = d0.blue + d1.blue + d2.blue + d3.blue;

red_total = (red_total - max_red - min_red + 1) >> 1;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you add all the red pixels together, then subtract the min and the max. It would be easier to find the two median values and then add those together and take the average and it would be far less expensive

Copy link
Copy Markdown
Owner

@DonnyC123 DonnyC123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that you were missing your test bench code.

There are some optimizations/changes to the code that I would like to see if we were using this in our project, but overall, it looked good for a first version. It was also great to see that you used BRAM in your design. Your code is somewhat verbose, but it was reasonably easy to read. Overall, good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants