cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor
Visitor
994 Views
Registered: ‎01-23-2019

Implementation of math fucntions on a matrix

Jump to solution

Iam trying to implement abs function on a matrix in the top function. i need to create an IP of it. abs function is working fine on a complex number but cannot be implemented on a matrix. 

This is a snippet of my top function:

void sos(unit8_t image_in[300*200], unit8_t image_out[300*200])

{

     hls::Mat<200,300,HLS_8UC1> src;

     hls::AXIM2Mat<300,uint8_t,200,300,HLS_8UC1>(image_in,src);

     hls::Mat<200,300,HLS_8UC1> abs(src);

     hls::Mat2AXIM<300,uint8_t,200,300,HLS_8UC1>(src,image_out);

}

Can anyone please tell if this code can be implement as shown above or if i need to define a stream for the matrices or convert the matrix to array to implement math functions on them.

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Voyager
Voyager
958 Views
Registered: ‎03-28-2016

Re: Implementation of math fucntions on a matrix

Jump to solution

You likely need to use the openCV fucntion absDiff.  Create a MAT full of zeros for one of the inputs.  Check UG1233 (Xilinx OpenCV User Guide).

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com

View solution in original post

0 Kudos
6 Replies
Highlighted
Voyager
Voyager
959 Views
Registered: ‎03-28-2016

Re: Implementation of math fucntions on a matrix

Jump to solution

You likely need to use the openCV fucntion absDiff.  Create a MAT full of zeros for one of the inputs.  Check UG1233 (Xilinx OpenCV User Guide).

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com

View solution in original post

0 Kudos
Highlighted
Visitor
Visitor
939 Views
Registered: ‎01-23-2019

Re: Implementation of math fucntions on a matrix

Jump to solution

Thank you sir for your response.

I considered your advice and used absDiff by creating a matrix of zeros. But on the application of absDiff on two different images and the application of absDiff on an image and a zero matrix, the outputs seems to be contradictory.

On applying absDiff as adviced, the output image must be the same as input, since the input image is a matrix of real numbers. But contradictory to this fact, the output obtained by me is a image with distorted dots distributed around as shown in the image attached below.

This was how i implemented the function, it would be very helpful if you could say where am I going wrong.


hls::AbsDiff(src1,src2,dst);


where src1-input image matrix, src2-zero matrix and dst-output matrix.

 

Regards 

Manisha Riyana






abs_results.jpg
0 Kudos
Highlighted
Voyager
Voyager
927 Views
Registered: ‎03-28-2016

Re: Implementation of math fucntions on a matrix

Jump to solution

Off hand, I'm not sure why the output would look like that.  The output MAT may need to be pre-allocated before the absDiff is performed.  I'd have to see the code to get a better idea.

 

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com
0 Kudos
Highlighted
Visitor
Visitor
873 Views
Registered: ‎01-23-2019

Re: Implementation of math fucntions on a matrix

Jump to solution

AbsDiff function works perfectly fine while using a blank image. but when i try to generaate a blank matrix using

void Zero(hls::Mat<200,300,HLS_8UC1>&src);

I cannot apply AbsDiff on this matrix and the image i had taken as input.

0 Kudos
Highlighted
Visitor
Visitor
814 Views
Registered: ‎01-23-2019

Re: Implementation of math fucntions on a matrix

Jump to solution

I have found the solution to my problem by myself.

To implement the math functions on top function, we need to first convert the matrix into a single dimensional array and then apply the mat function on individual elements of the array.

Here's the code snippet of implementing abs function on an image:

void conv(uint8_t image_in[64*64],uint8_t image_out[64*64])
{
hls::Mat<64,64,HLS_8UC1> src;
hls::Mat<64,64,HLS_8UC1> dst;
hls::AXIM2Mat<64,uint8_t,64,64,HLS_8UC1>(image_in,src);
uint16_t hmap2_array[64*64];
uint16_t Ar[64*64];
hls::Mat2Array<64>(src,hmap2_array);
for(int i=0;i<4096;i++)
{
Ar[i]=abs(hmap2_array[i]);
}
hls::Array2Mat<64>(Ar, dst);
hls::Mat2AXIM<64,uint8_t,64,64,HLS_8UC1>(dst,image_out);
}

IMG-20190131-WA0009.jpg
0 Kudos
Highlighted
380 Views
Registered: ‎07-15-2019

Re: Implementation of math fucntions on a matrix

Jump to solution

Thanks a lot. I got the required info. Also integation is useful to get more information about math functions.