Don't know how to plot array of points on a figure

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

Don't know how to plot array of points on a figure

Postby huahongquan2007 » Sun May 04, 2014 9:25 am

Hi,
I want to use arrayfire for my thesis but I have a problem on visualize the array. I have an image and an array of points [ 76 x 2 ]. Each row contains x and y coordinates of a point in 2D space. I have attached the result that I want ("Ket Qua.png").
I don't know how to plot the array on the image. It is easy in Matlab with the plot function.
Please help me. Thank you very much
Attachments
Ket Qua.png
Ket Qua.png (269.15 KiB) Viewed 13447 times
huahongquan2007
 
Posts: 10
Joined: Fri May 02, 2014 1:56 pm

Re: Don't know how to plot array of points on a figure

Postby shehzan » Mon May 05, 2014 11:29 am

Hi

You could do something like this:
Code: Select all
array p_temp = points(span, 0) + points(span, 1) * img.dims(0);
img(p_temp) = color_value;
//display
image(img);


Let me know if you need any further help.
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: Don't know how to plot array of points on a figure

Postby shehzan » Mon May 05, 2014 11:29 am

Hi

You could do something like this:
Code: Select all
array p_temp = points(span, 0) + points(span, 1) * img.dims(0);
img(p_temp) = color_value;
//display
image(img);


Let me know if you need any further help.
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: Don't know how to plot array of points on a figure

Postby huahongquan2007 » Tue May 06, 2014 6:46 am

Thank you very much. It's worked.
However, I have another problem.
I want to plot the points without the image. So I need to create an 2D image using constant(0, row, col). The "row" and "col" parameter is the max value of the points array.
Code: Select all
array maxArr = max(points, 0);

But I don't know how to convert the maxArr(0) and maxArr(1) into int as the constant 3rd and 4th parameters.
In summary, I don't know how to convert an array element into integer.
I am look forward to hearing you.
Thank you.

P/s:
I found the following code to convert max value into int.
Code: Select all
   cout << max<float>(points(span,0)) << endl;

Is there any other way to convert any elements into int? For example, using template<T>
For example:
Code: Select all
 int a = some_function<int>(points(10,1))
huahongquan2007
 
Posts: 10
Joined: Fri May 02, 2014 1:56 pm

Re: Don't know how to plot array of points on a figure

Postby shehzan » Tue May 06, 2014 11:04 am

Hi

You can use the following:
Code: Select all
// Replace int with datatype of array below
array max_xy = max(points, 0);
// since points is N x 2, max_xy will be 1 x 2.
// Now you can copy these values to host
int* max_sizes = max_xy.host<int>();  // Copies data to host
array out = constant(0, max_sizes[0], max_sizes[1]);


Regarding your postscripts,
There is a function available
Code: Select all
ty val = max<ty>(array);
that will return a max to the host. But since we need the max of each dimension, we will have to run this function twice (once for 0 and once for 1) which will result in 2 kernels and 2 memcpys. So if we run the code above, we get 1 kernel and 1 memcpy.
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: Don't know how to plot array of points on a figure

Postby huahongquan2007 » Wed May 07, 2014 11:16 am

Thank you very much for your fast response.
I think that you should include the "host function" in the getting started documentation. It 's really helpful.
huahongquan2007
 
Posts: 10
Joined: Fri May 02, 2014 1:56 pm

Re: Don't know how to plot array of points on a figure

Postby shehzan » Wed May 07, 2014 11:19 am

Great.
Getting host and device pointers is shown in the getting started page (just above the Matrix Manipulation section).
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm


Return to [archive-commercial] Programming & Development with ArrayFire

cron