In this submission RGB_Gray Color converted has been implemented using HDL coder.
SUMEET (2020). FPGA implementation of RGB to Gray Color conversion using HDL coder. (https://www.mathworks.com/matlabcentral/fileexchange/45798-fpga-implementation-of-rgb-to-gray-color-conversion-using-hdl-coder), MATLAB Central File Exchange. Retrieved .
Thank you for your sample code.
I try using this one by the HDL coder.
I realized that maybe your code is unsynchronized between y_out/x_out with gray.
So I fixed your code like below.
function [x_out, y_out,gray] = rgb_gray(x_in, y_in, r_in, g_in, b_in)
persistent RGB_Reg RGB
persistent x1 x2 y1 y2
RGB_Reg = zeros(3,1);
RGB = zeros(3,1);
D = [.299 .587 .144];
gray = D*RGB_Reg;
RGB_Reg = RGB;
RGB = [r_in; g_in; b_in];
x_out = x2;
x2 = x1;
x1 = x_in;
y_out = y2;
y2 = y1;
y1 = y_in;