Extract numeric data from MATLAB figures

In order to extract numeric data from a MATLAB figure you can do the following steps:

1- open the fig file

2- execute the following lines of code

h=get(gca,'Children'); %get the handle of the object
xData=get(h,'XData'); %get the x data
yData=get(h,'YData'); %get the y data

3- if the extracted xData and yData vectors/Matrices are cells then you can easily convert them as follows:

xDataNum = cell2mat(xData);
yDataNum = cell2mat(yData);
Posted in Linux, MATLAB, programming, SIMULINK, Software, Ubuntu | Tagged , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Kashi (Kashani) the Mathematician

Al-Kashi was one of the best mathematicians in the Islamic world. He was born in 1380, in Kashan, in central Iran.

In order to determine sin 1°, al-Kashi discovered the following formula often attributed to François Viète in the 16th century.

sin(3\theta) = 3sin(\theta) - 4sin^3(\theta)

This is just one of his amazing mathematical discoveries.

A method algebraically equivalent to Newton’s method was known to his predecessor Sharaf al-Dīn al-Tūsī. Al-Kāshī improved on this by using a form of Newton’s method to solve x^P - N = 0 to find roots of N. In western Europe, a similar method was later described by Henry Biggs in his Trigonometria Britannica, published in 1633.

Posted in Thoughts | Tagged , , , , , , , | Leave a comment

Simple Object Detection in 3 lines of Code (OpenCV/Python)

img_filt = cv2.medianBlur(cv2.imread('f.jpg',0), 5)
img_th = cv2.adaptiveThreshold(img_filt,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
contours, hierarchy = cv2.findContours(img_th, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)


Posted in Linux, Machine Learning, OpenCV, programming, Python, Robotics, Software, Ubuntu | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Read, write, show images in OpenCV (Python)

In order to load or read an image you can use imread function.

>>> import numpy
>>> import cv2
>>> img = cv2.imread('filename.jpg',0)

In order to display an image you can use imshow function.

>>> cv2.imshow('image',img)
>>> cv2.waitkey(0)
>>> cv2.destroyAllWindows()

After you applied some changes to an Image you can write it into the disk. In order to write an image you can use imwrite function.

>>> imwrite('newfilename.png',img)

Finally you can do all above in the following snippet:

import numpy as np
import cv2
img = cv2.imread('myImage.jpg',0)
k = cv2.waitKey(0)
if k == 27:





Posted in Linux, Machine Learning, OpenCV, programming, Python, Robotics, Software, Ubuntu | Tagged , , , , , , , , , , , , , , , , , , , | Leave a comment

Installing OpenCV for Python (windows)

The good thing about OpenCV is that you can use it in Python ;)

Here I give you some hints for installing it.

0- If you haven’t installed python first you have to do that. So download (python 2.7.x) and install it. The installation is straight forward also you can find good hints here and here.
1- You have to download and install the following packages before installing and using OpenCV: Numpy, MatPlotLib.
2- Open a terminal (cmd.exe) and check if the numpy module has been installed correctly:

>>> import numpy
>>> import matplotlib

3- You shouldn’t see and error or warning, and that means that everything is Ok.
4- Download the OpenCV package from here. And extract it somewhere on hard disk (e.g. c:\).
5- Go to ‘c:\opencv\build\python\2.7′ and copy ‘cv2.pyd’ (ctrl+c)
6- Go to ‘c:\python27\Lib\site-packages’ and paste the file (ctrl+v). Hint: I assume that you have installed your python in ‘c:\python27‘, if not, you have to replace the correct path.
7- If you perform all the steps correctly, you can open a terminal and load the module to see if it has been installed correctly.

>>> import cv2





Posted in Machine Learning, programming, Python, Software | Tagged , , , , , , , , , , , , , , , , | Leave a comment

6 habbits you have to change when using TOR

You need to change some of your habits, as some things won’t work exactly as you are used to.

  1. Use the Tor BrowserTor does not protect all of your computer’s Internet traffic when you run it. Tor only protects your applications that are properly configured to send their Internet traffic through Tor.
  2. Don’t torrent over TorTorrent file-sharing applications have been observed to ignore proxy settings and make direct connections even when they are told to use Tor. Even if your torrent application connects only through Tor, you will often send out your real IP address in the tracker GET request, because that’s how torrents work.
  3. Don’t enable or install browser pluginsThe Tor Browser will block browser plugins such as Flash, RealPlayer, Quicktime, and others: they can be manipulated into revealing your IP address.
  4. Use HTTPS versions of websitesTo help ensure private encryption to websites, the Tor Browser includes HTTPS Everywhere to force the use of HTTPS encryption with major websites that support it.
  5. Don’t open documents downloaded through Tor while onlineYou should be very careful when downloading documents via Tor (especially DOC and PDF files) as these documents can contain Internet resources that will be downloaded outside of Tor by the application that opens them. This will reveal your non-Tor IP address.
  6. Use bridges and/or find companyBy default, it does not prevent somebody watching your Internet traffic from learning that you’re using Tor. If this matters to you, you can reduce this risk by configuring Tor to use a Tor bridge relay rather than connecting directly to the public Tor network.

Read more about it here!

Posted in Software, Thoughts | Tagged , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Signal Processing – Apply Median Filters (Python)

The median filter is a nonlinear digital filtering technique, often used to remove noise. Such noise reduction is a typical pre-processing step to improve the results of later processing (for example, edge detection on an image). Read more about the median filter here.

Here we want to implement a simple median filter in python. You need to install numpy, scipy, and matplotlib modules to replicate the code below. The filter has two inputs, first the input signal and a windows size (kernel size). Notice, the kernel size have to be an odd number.

import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
from scipy import signal

t = np.linspace(0,10,200) # create a time signal
x1 = np.sin(t) # create a simple sine wave
x2 = x1 + np.random.rand(200) # add noise to the signal
y1 = sp.signal.medfilt(x2,21) # add noise to the signal
# plot the results
plt.title('input wave')
plt.title('filtered wave')


Posted in Linux, Machine Learning, Optimization, programming, Python, Robotics, Software, Ubuntu | Tagged , , , , , , , , , , , , , , , , , , , , , , , , | 1 Comment