diff --git a/pixel.cpp b/pixel.cpp
index 1b30ca34bb14ed19d9604b05089369a62cb7a479..3f61c96d1a3c29f22eb8343f116bb0da9b894e41 100644
--- a/pixel.cpp
+++ b/pixel.cpp
@@ -25,13 +25,13 @@ void pixel(
 	#pragma HLS INTERFACE axis port=dout
 
 	pkt_t pkt=din.read();
-	count_streams++;
 
 	
 	if((position1+3*count_streams*w) < position2 || (position2-3*count_streams*w) > position1){
 		pkt.data -= 1;
 	}
-
+	
+	count_streams++;
 
 	if (count_streams == w*h*3){
 		count_streams = 0;