## 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.

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

img_filt = cv2.medianBlur(cv2.imread('f.jpg',0), 5)
contours, hierarchy = cv2.findContours(img_th, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)


## Read, write, show images in OpenCV (Python)

>>> import numpy
>>> import cv2


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
cv2.imshow('image',img)
k = cv2.waitKey(0)
if k == 27:
cv2.imwrite('newImage.png',img)
cv2.destroyAllWindows()


## 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


## 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.

## 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.subplot(2,1,1)
plt.plot(t,x2,'yo-')
plt.title('input wave')
plt.xlabel('time')
plt.subplot(2,1,2)
plt.plot(range(200),y1,'yo-')
plt.title('filtered wave')
plt.xlabel('time')
plt.show()



| | 1 Comment

## Linear vector mapping (scaling) – Python

The mathematics behind the linear mapping is presented in the previous post.

The equivalent function in MATLAB is posted here.

The following function is provided to be used in python programs. (check and correct the indenting of the function before usage). The following function uses numpy module, check the example after the function to see the correct usage.

def linmap(vin,rout):
# function for linear mapping between two ranges
# inputs:
# vin: the input vector you want to map, range [min(vin),max(vin)]
# rout: the range of the resulting vector
# output:
# the resulting vector in range rout
# usage:
# >>> v1 = np.linspace(-2,9,100);
# >>> rin = np.array([-3,5])
# >>> v2 = linmap(v1,rin);
# *** (this function uses numpy module)
#
a = np.amin(vin);
b = np.amax(vin);
c = rout[0];
d = rout[1];
return ((c+d) + (d-c)*((2*vin - (a+b))/(b-a)))/2;


How to use this function? check the following example:

>>> import numpy as np
>>> v1 = np.linspace(-2,9,20)
>>> rin = np.array([-3,5])
>>> linmap(v1,rin)
array([-3. , -2.57894737, -2.15789474, -1.73684211, -1.31578947,
-0.89473684, -0.47368421, -0.05263158, 0.36842105, 0.78947368,
1.21052632, 1.63157895, 2.05263158, 2.47368421, 2.89473684,
3.31578947, 3.73684211, 4.15789474, 4.57894737, 5. ])