Changing axes properties with the mouse

August 31, 2009 by Husam Aldahiyat · Leave a Comment
Filed under: GUI, Tutorials 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)

Today we’re going to learn how to change some axes properties with the mouse.

First, start a new m file function that will contain our work.

Husam1

Create the axes on which our work will be based on. Give the axes a handle (h) so we can change and obtain (set and get) its properties later.

Husam2

You’ll see that the handle variable h has an orange (warning) underline. This happens when your function contains an unused variable in it. We will use this handle soon in manipulating the axes.

To see the newly created axes, run the function.

Husam3

The first thing we will do with our axes is getting mouse click input. To do this, we first assign a buttondownfcn to our axes.

Husam4

Now whenever we click on the axes with the mouse, we go to the function press1 and perform whatever is instructed there.

We will at first put an acknowledgement of the mouse click. This is done by changing the title of the axes whenever we click on it with a small phrase. This phrase then disappears after half a second.

Husam5

Try it!

Next we will identify the coordinates of the mouse click. To do this, first delete the previous lines inside the press1 function. To get the mouse click coordinates, we will make use of an axes property called currentpoint.

So we take the currentpoint value in our axes and store the result in a variable, as follows.

Husam6

Of this new variable (which will be a 2 by 3 matrix), we are interested in the x and y coordinates, namely elements (1,1) and (1,2) of the matrix p.

Husam7

Now we have the x and y coordinates of the mouse click(s) stored in appropriate variable names. To show these values, we will change the title of the axes accordingly, as done before.

The x and y variables are numeric, while the title of the axes contains string values. For this reason, we will convert the numeric data into string data, and then put it as a title for the axes. For aesthetic reasons, we will also put a comma between the two values. This is shown in the following code snippet.

Husam8

Result:

Husam9

We can do more things with the mouse click coordinates. For example, the following code plots a star wherever you click the mouse on the axes. Since in MATLAB plotting a new plot replaces the old one, we will use the command hold on to make sure each star plotted stays on the axes.

Also, we set the axes limits beforehand so they stay the same and don’t change after every star plotted.

Husam10

Result:

Husam11

For our final example, we want to change the axes axis limits with mouse clicks. That is, when we click on the far right of the axes, the x-limit changes accordingly. The algorithm works as follows:

  • Get x and y coordinates for mouse click.
  • If x coordinate is in last 0.05 of the x-limit, shift x-limit right.
  • Similarly, if x coordinate is in first 0.05 of the x-limit, shift x-limit left.
  • Do the same for the axes y-limit.

The following is the code with comments.

Husam12

Thanks for tuning in J

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 16% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

Binary Dilation and Erosion

August 28, 2009 by Luigi Rosa · 2 Comments
Filed under: Image processing 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)

A faster implementation of binary dilation and erosion.

Our functions take advantage of MATLAB ’s decomposition of the structuring element but they may result much faster. Try to run example.m to see the speed improvement factor, changing the parameters.

Please contribute if you find this software useful.
Report any bug to luigi.rosa@tiscali.it

Luigi Rosa
Via Centrale 35
67042 Civita Di Bagno
L’Aquila — Italy

mobile +39 340 3463208
email luigi.rosa@tiscali.it

Download Now

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 21% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

ROC curve

August 25, 2009 by Giuseppe Cardillo · 2 Comments
Filed under: Statistics 
VN:F [1.8.1_1037]
Rating: +2 (from 2 votes)
VN:F [1.8.1_1037]
Rating: 7.5/10 (4 votes cast)

ROC – Receiver Operating Characteristics.

The ROC graphs are a useful technique for organizing classifiers and visualizing their performance. ROC graphs are commonly used in medical decision making.
The function computes and plots the classical ROC curve and the mirrored ROC curve (in my opinion, it is more useful).

An example of roc.m output plot

An example of roc.m output plot

The input is a Nx2 matrix: in the first column you must insert the test value and in the second you must insert 1 if the subject is a patient or 0 if he is healthy (or, more general, use 1 and 0 to discriminate the subsets of subjects).
I.E. X=[165 1; 140 1; .... 166 0; 176 0] (load rocdata) then call roc(X).

The function will return a table

ROC CURVE DATA
——————————————–
Cut-off point     Sensitivity     Specificity

131.0000          0.2414        0.9762
132.0000          0.2586        0.9762

151.0000          0.7500        0.8095
152.0000          0.8017        0.8095

218.0000          1.0000        0.0476
239.0000          1.0000        0.0238
——————————————————————————–

and the statistic results:

ROC CURVE ANALYSIS

——————————————————————————–
AUC        S.E.           95% C.I.          Comment
——————————————————————————–
0.87541    0.02713    0.82224    0.92858    Good test
——————————————————————————–
Standardized AUC       1-tail p-value
13.8375                0.000000            The area is statistically greater than 0.5

Cut-off point for best Sensitivity and Specificity (blu circle in plot)= 152.0000
In the ROC plot, the cut-off point is the closest to [0,1] point or, if you want, the closest to the green line

where AUC is Area under the curve and S.E. is Standard Error

If you have downloaded partest (http://www.advancedmcode.org/partest.html) the routine will compute several data on test performance.

If any problems occurs in execution, or if you found a bug, have a suggestion or question just contact me at:

giuseppe dot cardillo-edta at poste dot it

You can visit my homepage http://home.tele2.it/cardillo

My profile on XING http://www.xing.com/go/invita/13675097

My profile on LinkedIN http://it.linkedin.com/in/giuseppecardillo

Download Now

VN:F [1.8.1_1037]
Rating: 7.5/10 (4 votes cast)
VN:F [1.8.1_1037]
Rating: +2 (from 2 votes)

Popularity: 30% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

GLTree:Fast K-Nearest Neighbors Search

August 25, 2009 by Luigi Giaccari · 6 Comments
Filed under: Algorithms, Computational Geometry 
VN:F [1.8.1_1037]
Rating: +2 (from 2 votes)
VN:F [1.8.1_1037]
Rating: 10.0/10 (5 votes cast)

In this file you can find a simple but very effective algorithm for Nearest Neighbour Search which I megalomaniacly called the GLTree.

It has been designed for uniformly random data, where is the fastest I ever used, but works fine even on sparse ones. If points are too sparse, for example logspace data, search is still performed correctly but speed can degenerate to a brute search algorithm. In these cases a different data structure is needed but for lack of time I haven’t still coded. If query points are close to reference it is very efficient on sparse dataset too.

The tree can be build without running any search. The pointer passed to workspace can be used for the above routines. The tree costruction has linear time complexity and it is very fast, so it becomes advantageus against brute search even for a small number of points. I’d like to point that in GL-Tree searching has linear complexity (on uniform dataset) instead of n*log(n) like in kd-tree.
It is possible to choose if return the distances.

This release includes:

  • NNSearch

It only supports 2D points and 3D points.

It also possible to ask for personalized versions like:

  • different points data structure or class. To use the utility as C++ library.
  • Detections of sparse dataset. (sparse dataset are detected very soon so it is convenient to switch to a kd-tree data structure).
  • More efficient in terms of memory and speed costruction of the tree.
  • Personilzed functions, NNgraph, box search…
  • user’s suggestions
  • explanations on how the algorithm works

Some of this functions are brand new so please advise me if any error occurs.

Here is an example on 2D, find 1e6 neighbours in 1e6 reference:

N=1000000;
%random reference and query points
px=rand(N,1);%reference
py=rand(N,1);
qpx=rand(N,1);%query
qpy=rand(N,1);

tic
ptrtree=BuildGLTree2DFEX(px,py);
NNG=NNSearch2DFEX(px,py,qx,qy,ptrtree);
toc

Output:

1.46715 s


And here are the timings for 3D version:

  • N=100; elapsed time is: 0,001 seconds
  • N=1000; elapsed time is: 0,003 seconds
  • N=10000; elapsed time is: 0,029 seconds
  • N=100000; elapsed time is: 0,325 seconds
  • N=1000000; elapsed time is: 3,346 seconds

If any problems occurs in execution, or if you found a bug, have a suggestion or question just contact me at:

giaccariluigi@msn.com

This work is free thanks to users gratitude. If you find it usefull consider making a donation.

Downloads:

You want more? go to the Professional version of GLTree
VN:F [1.8.1_1037]
Rating: 10.0/10 (5 votes cast)
VN:F [1.8.1_1037]
Rating: +2 (from 2 votes)

Popularity: 43% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

Fast Convex Hull Algorithm

August 24, 2009 by Luigi Giaccari · 6 Comments
Filed under: Algorithms, Computational Geometry 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 10.0/10 (1 vote cast)

Even if totally m-coded, this routine is particularly fast in computing convex hull of 2D points. In many cases seems to be much faster than the matlab library routine. The main reason is that, differently from convhull, this algorithm jumps the call to unique function which can be very slow for large models .
Algorithm is very simple, it’s based on cross product.

It is brand new, so please let me know if something goes wrong!

Since I received comments about different timings this version includes a speed test to compare ConvHull2D to the native matlab convhull. There is also a graphical explanation on how the algorithm works.

ConvHull2D returns indices into the X and Y vectors of the points on the convex hull.

Example: (convex hull of 1000000 random points)

N=1000000;
x=rand(N,1);
y=rand(N,1);

tic
chull=ConvHull2D(x,y);%ConvHull2D
toc

tic
chull2=convhull(x,y);     %Matlab built-in routine
toc

Output:

Elapsed time is 0.104134 seconds.(ConvHull2D)
Elapsed time is 1.207817 seconds.(Matlab built in)

For any problem, bug, information or suggestion just contact me at:

giaccariluigi@msn.com


Download Now

VN:F [1.8.1_1037]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 32% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

Next Page »