Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Improving my code to skip pixels!

Status
Not open for further replies.

flote21

Advanced Member level 1
Joined
Jan 22, 2014
Messages
411
Helped
1
Reputation
2
Reaction score
3
Trophy points
1,298
Activity points
5,595
Hello buddys!

I am working with a image sensor which delivers 4 pixels (12 bits/pixel) every system clock.

The pixel output of the sensor is 6 Lines x 2112 pixels. And I want to throw away some pixels per line according to the parameter SHIFT_COL.

For example,
- if SHIFT_COL = 1, the 1st pixel of every line should be skipped resulting 2111 pixels.
- if SHIFT_COL = 2, the 2 first pixels of every line should be skipped resulting 2110 pixels
- and so on...

Here is the code that I have already programmed. But I think that it could be a better coding for this issue. Any suggestion?

Code:
		-- Valid Pixels Management:
      -- Receiving 4 pixels on every clock cycle and skip some of them
		-- according to the parameter SHIFT_COL
		SHIFT_DAV  <= '0';
		if VID_I_DAV = '1' then  -- New "4pixels" 	          			
		  VID_I_CNT <= VID_I_CNT + 4;		  
		  SHIFT_SEL    <= SHIFT_SEL + 1;
		  -- Binning 6x6 => Max. 10 pixels to shift!
		  if FPGA_MODE_l = "100" then                         							
				case SHIFT_COLr is
					when x"0000" => -- No shifting 
						if SHIFT_SEL = 0 then 
							SHIFT_DATA_REG <= VID_I_DATA;
							SHIFT_DAV  <= '1';
							SHIFT_SEL  <= (others=>'0');
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;			
					when x"0001" => -- Shifting 1 column
						if SHIFT_SEL = 0 then 							
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
						elsif SHIFT_SEL = 1 then 							
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
							SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 2 then
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
							SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"1";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;									 
					when x"0002" => -- Shifting 2 columns
						if SHIFT_SEL = 0 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
						elsif SHIFT_SEL = 1 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 2 then
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"1";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;									 					
					when x"0003" => -- Shifting 3 columns
						if SHIFT_SEL = 0 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
						elsif SHIFT_SEL = 1 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 2 then
							SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"1";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;
					--
					when x"0004" => -- Shifting 4 columns
						if SHIFT_SEL = 1 then 
							SHIFT_DATA_REG <= VID_I_DATA;
							SHIFT_DAV  <= '1';
							SHIFT_SEL  <= x"1";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;			
					when x"0005" => -- Shifting 5 columns
						if SHIFT_SEL = 1 then 							
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
						elsif SHIFT_SEL = 2 then 							
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
							SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 3 then
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
							SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"2";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;									 
					when x"0006" => -- Shifting 6 columns
						if SHIFT_SEL = 1 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
						elsif SHIFT_SEL = 2 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 3 then
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"2";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;									 					
					when x"0007" => -- Shifting 7 columns
						if SHIFT_SEL = 1 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
						elsif SHIFT_SEL = 2 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 3 then
							SHIFT_PIX_REG1 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(35 downto 0) & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"2";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;									 											
					--
					when x"0008" => -- Shifting 8 columns
						if SHIFT_SEL = 2 then 
							SHIFT_DATA_REG <= VID_I_DATA;
							SHIFT_DAV  <= '1';
							SHIFT_SEL   <= x"2";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;			
					when x"0009" => -- Shifting 9 column
						if SHIFT_SEL = 2 then 							
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
						elsif SHIFT_SEL = 3 then 							
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
							SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 4 then
							SHIFT_PIX_REG1  <= VID_I_DATA(23 downto 12);
							SHIFT_PIX_REG2  <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG3  <= VID_I_DATA(47 downto 36);														
							SHIFT_DATA_REG <= VID_I_DATA(11 downto 0) & SHIFT_PIX_REG3 & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"3";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;									 
					when x"000A" => -- Shifting 10 columns
						if SHIFT_SEL = 2 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
						elsif SHIFT_SEL = 3 then 
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';
							SHIFT_CNT <= SHIFT_CNT + 4;
						elsif SHIFT_SEL = 4 then
							SHIFT_PIX_REG1 <= VID_I_DATA(35 downto 24);
							SHIFT_PIX_REG2 <= VID_I_DATA(47 downto 36);
							SHIFT_DATA_REG <= VID_I_DATA(23 downto 0) & SHIFT_PIX_REG2 & SHIFT_PIX_REG1;
							SHIFT_DAV <= '1';						
							SHIFT_SEL   <= x"3";
							SHIFT_CNT <= SHIFT_CNT + 4;
						end if;									 					
					when others => null;
				end case;			  
		  end if;		
		end if;

Thanks anyway!
 

why not have a simple counter, that counters to 2112.
When count < SHIFT_COL, data_valid = '0', else it is '1'
 

Hi Thank you for your help!

I was wrong in the initial post. What I want to have is always 2112 pixels. So when for example, SHIFT_COL = 1 and the input of the sensor is so:
HTML:
           Input                                      Output
Pixel1 Pixel2 Pixel3 Pixel4           Pixel1   Pixel2   Pixel3   Pixel4
   0       1        2       3           1         2       3         4
   4       5        6       7           5         6       7         8
   8       9        10      11    =>    9         10      11        12
..                                     ..
..                                     ..
 2108   2109   2110  2111              2109     2110    2111    2112

As you can see the amount of pixels is always the same: 2112.

A lot of thanks




why not have a simple counter, that counters to 2112.
When count < SHIFT_COL, data_valid = '0', else it is '1'
 
Last edited:

This is just a simple delay of the valid. You would have a shift register and only enable the output 2 clocks later.
 

If I just make a delay of the valid I am skipping 4 pixels and I want to have a resolution of 1 pixel skipped.

This is just a simple delay of the valid. You would have a shift register and only enable the output 2 clocks later.
 

what is the incoming clock speed?
What is the input interface?
6x2112 is a very strange sensor size - why so odd?
why are pixel packed into 4 pels per word? where are they sourced from?

I think this problem has come up before - and you generally ignored my questions then. Maybe you'll answer this time

Basically, I cannot think of a simple elegent solution from the top of my head.
Have you got a good testbench to test your solution?
 

1) what is the incoming clock speed?
148.5 MHz.
2) What is the input interface?
4 channels LVDS
3)6x2112 is a very strange sensor size - why so odd?
It is a special CMOS sensor for industrial applications. The sensor window is 1110x2112. But I can set up a Region Of Interest (ROI) of 6x21112.
4)why are pixel packed into 4 pels per word? where are they sourced from?
Because the sensor interface is 4 LVDS channels and one pixel per channel is given in every sys_clk in PARALLEL. The sensor is working in that way and I can´t modify the pixel output of the sensor...

I think this problem has come up before - and you generally ignored my questions then. Maybe you'll answer this time

I am sorry, I thought that I have already clarified this issue. Anyway if you have more questions I will answer as far af I know.

Have you got a good testbench to test your solution?
Yes I have done a good test bench where I can simulate the output of the sensor. And the my code posted works perfectly. But I want to know if there is another solution more generic. Because my code is only able to skip 10 pixels maximum. I want to implement some kind of elegant algorithm to save resources and skip whatever amount of pixels...

what is the incoming clock speed?
What is the input interface?
6x2112 is a very strange sensor size - why so odd?
why are pixel packed into 4 pels per word? where are they sourced from?

I think this problem has come up before - and you generally ignored my questions then. Maybe you'll answer this time

Basically, I cannot think of a simple elegent solution from the top of my head.
Have you got a good testbench to test your solution?
 

This is a very custom set up, so its not very easy to give any improvements without the whole architecture.
But i could probably use a counter in there to get the base offset - then you can shift as much as you like.
 
Yes I was thinking to do something like that buffering the input pixels with a FIFO and using a cunter to throw away the pixels which are not useful...

Thanks dude!


This is a very custom set up, so its not very easy to give any improvements without the whole architecture.
But i could probably use a counter in there to get the base offset - then you can shift as much as you like.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top