1 |
2 |
angelobacc |
library IEEE;
|
2 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
3 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
4 |
|
|
USE IEEE.NUMERIC_STD.ALL;
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
entity nmax_supp is
|
8 |
|
|
generic (
|
9 |
|
|
DATA_WIDTH : integer := 8;
|
10 |
|
|
GRAD_WIDTH : integer := 16
|
11 |
|
|
);
|
12 |
|
|
port (
|
13 |
|
|
clk : in std_logic;
|
14 |
|
|
fsync : in std_logic;
|
15 |
|
|
mData1 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
16 |
|
|
mData2 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
17 |
|
|
mData3 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
18 |
|
|
mData4 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
19 |
|
|
mData5 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
20 |
|
|
mData6 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
21 |
|
|
mData7 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
22 |
|
|
mData8 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
23 |
|
|
mData9 : in STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
24 |
|
|
dData : in STD_LOGIC_VECTOR(1 downto 0);
|
25 |
|
|
--fsync_o : out std_logic;
|
26 |
|
|
pdata_o : out std_logic_vector(DATA_WIDTH-1 downto 0)
|
27 |
|
|
);
|
28 |
|
|
end entity nmax_supp;
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
-- WARNING UNSIGNED STD_LOGIC_VECTOR in this KERNEL
|
32 |
|
|
|
33 |
|
|
architecture Behavioral of nmax_supp is
|
34 |
|
|
|
35 |
|
|
constant UP_THRES : integer := 50;
|
36 |
|
|
|
37 |
|
|
signal cdata1,cdata2,cdata3 : STD_LOGIC_VECTOR(GRAD_WIDTH-1 downto 0);
|
38 |
|
|
--signal fsync_ia : STD_LOGIC;
|
39 |
|
|
|
40 |
|
|
--constant LATENCY : integer := 1;
|
41 |
|
|
--signal fsync_store : std_logic; -- clock cycles delay to compensate for latency
|
42 |
|
|
|
43 |
|
|
begin
|
44 |
|
|
|
45 |
|
|
-- latency_comp: process (clk) -- for the frame sync signal
|
46 |
|
|
-- begin
|
47 |
|
|
-- if rising_edge(clk) then
|
48 |
|
|
-- fsync_store <= fsync_i;
|
49 |
|
|
-- fsync_o <= fsync_store;
|
50 |
|
|
-- end if;
|
51 |
|
|
-- end process latency_comp;
|
52 |
|
|
|
53 |
|
|
--1
|
54 |
|
|
--------------------------------------------------------
|
55 |
|
|
-- nonmax_supp: process (clk) -- nmaxsupp
|
56 |
|
|
-- begin
|
57 |
|
|
-- if rising_edge(clk) then
|
58 |
|
|
-- --fsync_o <= fsync_i;
|
59 |
|
|
-- --pdata_o <= mdata7(GRAD_WIDTH-1 downto GRAD_WIDTH-8); ------------DEBUG-------------
|
60 |
|
|
-- if dData = "00" then -- VERTICAL gradient
|
61 |
|
|
--
|
62 |
|
|
-- -- The gradient is from top to bottom. This means the edge is from left to right.
|
63 |
|
|
-- -- So you check gradient magnitudes against the pixels right above and below.
|
64 |
|
|
-- if mData5 >= mData2 AND mData5 > mData8 then
|
65 |
|
|
-- --pdata_o <= x"3F";
|
66 |
|
|
-- pdata_o <= mData5(GRAD_WIDTH-1 downto GRAD_WIDTH-8);
|
67 |
|
|
-- else
|
68 |
|
|
-- pdata_o <= (others => '0');
|
69 |
|
|
-- end if;
|
70 |
|
|
-- elsif dData = "01" then -- HORIZONTAL gradient
|
71 |
|
|
-- -- The gradient is horizontal. So the edge is vertical.
|
72 |
|
|
-- -- So you check the pixels to the left and right.
|
73 |
|
|
-- if mData5 >= mData4 AND mData5 > mData6 then
|
74 |
|
|
-- pdata_o <= mData5(GRAD_WIDTH-1 downto GRAD_WIDTH-8);
|
75 |
|
|
-- --pdata_o <= x"7E";--mData5;
|
76 |
|
|
-- else
|
77 |
|
|
-- pdata_o <= (others => '0');
|
78 |
|
|
-- end if;
|
79 |
|
|
-- elsif dData = "11" then -- 45R gradient
|
80 |
|
|
--
|
81 |
|
|
-- -- from the bottom left corner to the up right corner.
|
82 |
|
|
-- -- This means the edge lies from the bottom right corner to up left
|
83 |
|
|
-- if mData5 > mData3 AND mData5 >= mData7 then
|
84 |
|
|
-- pdata_o <= mData5(GRAD_WIDTH-1 downto GRAD_WIDTH-8);
|
85 |
|
|
-- --pdata_o <= x"BD";--mData5;
|
86 |
|
|
-- else
|
87 |
|
|
-- pdata_o <= (others => '0');
|
88 |
|
|
-- end if;
|
89 |
|
|
-- elsif dData = "10" then-- 45F gradient
|
90 |
|
|
--
|
91 |
|
|
-- -- from the top left corner to the down right corner.
|
92 |
|
|
-- -- This means the edge lies from the top right corner to down left
|
93 |
|
|
-- if mData5 >= mData1 AND mData5 > mData9 then
|
94 |
|
|
-- pdata_o <= mData5(GRAD_WIDTH-1 downto GRAD_WIDTH-8);
|
95 |
|
|
-- --pdata_o <= x"FF";--mData5;
|
96 |
|
|
-- else
|
97 |
|
|
-- pdata_o <= (others => '0');
|
98 |
|
|
-- end if;
|
99 |
|
|
-- end if;
|
100 |
|
|
-- end if;
|
101 |
|
|
-- end process nonmax_supp;
|
102 |
|
|
|
103 |
|
|
--1
|
104 |
|
|
--------------------------------------------------------
|
105 |
|
|
nonmax_supp1: process (clk) -- nmaxsupp
|
106 |
|
|
begin
|
107 |
|
|
if rising_edge(clk) then
|
108 |
|
|
if fsync ='1' then
|
109 |
|
|
--fsync_ia <= fsync_i;
|
110 |
|
|
cData2 <= mData5;
|
111 |
|
|
-- pdata_o <= mdata5; ------------DEBUG-------------
|
112 |
|
|
if dData = "00" then -- VERTICAL gradient
|
113 |
|
|
cData1 <= mData2;
|
114 |
|
|
cData3 <= mData8;
|
115 |
|
|
elsif dData = "01" then -- HORIZONTAL
|
116 |
|
|
cData1 <= mData4;
|
117 |
|
|
cData3 <= mData6;
|
118 |
|
|
elsif dData = "11" then -- 45R gradient
|
119 |
|
|
cData1 <= mData7;
|
120 |
|
|
cData3 <= mData3;
|
121 |
|
|
else -- 45F gradient
|
122 |
|
|
cData1 <= mData1;
|
123 |
|
|
cData3 <= mData9;
|
124 |
|
|
end if;
|
125 |
|
|
end if;
|
126 |
|
|
end if;
|
127 |
|
|
end process nonmax_supp1;
|
128 |
|
|
|
129 |
|
|
--2
|
130 |
|
|
--------------------------------------------------------
|
131 |
|
|
nonmax_supp2: process (clk) -- nmaxsupp
|
132 |
|
|
begin
|
133 |
|
|
if rising_edge(clk) then
|
134 |
|
|
if fsync ='1' then
|
135 |
|
|
-- pdata_o <= cData2(GRAD_WIDTH-1 downto 8); ---------DEBUG
|
136 |
|
|
if cData2 >= cData1 AND cData2 > cData3 then
|
137 |
|
|
if cData2(GRAD_WIDTH-1 downto 8) > x"000A" then -- THRESHOLD
|
138 |
|
|
pdata_o <= (others => '1');
|
139 |
|
|
else
|
140 |
|
|
pdata_o <= cData2(GRAD_WIDTH-1-2 downto 8-2); -- or set weak edges to 0 if preferred (others => '0');
|
141 |
|
|
end if;
|
142 |
|
|
else
|
143 |
|
|
pdata_o <= (others => '0');
|
144 |
|
|
end if;
|
145 |
|
|
end if;
|
146 |
|
|
end if;
|
147 |
|
|
end process nonmax_supp2;
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
end Behavioral;
|