cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
amitlwaghmare
Contributor
Contributor
1,075 Views
Registered: ‎08-13-2017

problem with abs function output

Jump to solution

hello everyone,

I am trying to find the absolute of image, using following code 

#include <hls_video.h>
#include <stdint.h>
#include<math.h>
void conv(uint8_t image_in[512*512],uint8_t image_out[512*512]){

	*image_out = hls::abs(*image_in);
}

 

test bench is 

#include <hls_opencv.h>
#include <stdint.h>
#include <stdio.h>
using namespace cv;
void conv(uint8_t * image_in, uint8_t * image_out);
int main(){
   Mat im = imread("D:/amit/New_design_hls_tmp/lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
   uint8_t image_in[512*512];
   uint8_t image_out[512*512];
   memcpy(image_in,im.data,sizeof(uint8_t)*512*512);

  conv(image_in,image_out);

   Mat out = Mat(512,512,CV_8UC1,image_out);

   namedWindow("text1");

   imshow("text1",im);

   namedWindow("text");

   imshow("text",out);
//   imwrite("out_img",out);
   waitKey(0);

 return 0;
}

the result is like this below : 

image_abs_result.JPG 

why the output image is like above "text" image ?

please help me on this ,

 

 

thanks and regards ,

amit

0 Kudos
1 Solution

Accepted Solutions
baltam
Contributor
Contributor
1,016 Views
Registered: ‎03-13-2017

You're applying the abs() function only to the first pixel of the image.
Try instead

 

#include <hls_video.h>
#include <stdint.h>
#include<math.h>
void conv(uint8_t image_in[512*512],uint8_t image_out[512*512]){

//*image_out = hls::abs(*image_in);
for (int y=0; y<512*512; y++)
image_out[y] = hls::abs(image_in[y]);
}

 

For synthesys, the directive PIPELINE to the loop would limit the latency to ~512*512=256K cycles

View solution in original post

1 Reply
baltam
Contributor
Contributor
1,017 Views
Registered: ‎03-13-2017

You're applying the abs() function only to the first pixel of the image.
Try instead

 

#include <hls_video.h>
#include <stdint.h>
#include<math.h>
void conv(uint8_t image_in[512*512],uint8_t image_out[512*512]){

//*image_out = hls::abs(*image_in);
for (int y=0; y<512*512; y++)
image_out[y] = hls::abs(image_in[y]);
}

 

For synthesys, the directive PIPELINE to the loop would limit the latency to ~512*512=256K cycles

View solution in original post