Sunday, November 2, 2014

Processing for android - installation

We will install processing for android. Since Processing uses Java, we first install the JDK.
Follow this link to download the JDK Standard Edition.
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Install the JDK. Now, we need to add the path of JDK to our system path. Go to the bin folder of the Java installation. It will be located in the following folder.

Copy this path to clipboard. Right click on your computer and select properties.

Select Advanced System Properties.

Select Environment Variables.

Search for the System Variables called Path, select it and click Edit...

Paste the path copied into the clipboard in this location (add a semi colon before it) and click OK.

Now, the underlying system knows where JDK is. We proceed to install Processing.
Go to the following link:
https://www.processing.org/download/?processing

Download the version appropriate for your OS. The latest stable release at this time is 2.2.1 (released on 19 May 2014).
It downloads as a zipped package. Extract the package and copy that into any convenient location. I use my desktop to store the unzipped package.

Next, we need to install the android SDK. This installation has already been briefed in my previous post, except for one minor correction. We don't need to download the entire ADT with Eclipse. Since, we will be using the Processing IDE, we will download the android SDK for an existing IDE.

Use the android SDK manager to install the required API files and related google documentation for your devices's android version. Procedure for installing the API files are given in my blog post as below.
Link to my previous post on setting up ADT.
http://presentingthefuture.blogspot.com/2014/01/android-app-development-what-lured-me.html

Now, we need to copy the Android mode template for Processing software. Click on the below link and save the zip package on your desktop.
https://dl.dropboxusercontent.com/u/5898761/AndroidMode.zip

Unzip the package to Documents/Processing/modes folder.

Next, open Processing software and click on the drop down menu that reads "Java" and select "Android".

Processing asks for the path where android SDK is installed. Select the path to your "android-sdk" folder in the android SDK installation path.


We have successfully installed Processing for android. Type the following snippet and run in emulator to check if the installation works correctly.
Warning: Emulator may take a lot of time to open depending on the configuration of your computer; people with less patience are requested to take a long walk after selecting this option.

Further information on how to run this snippet on a real device or a virtual device can be found on my post as below.

Processing for android - introduction

I'm a big fan of Processing software! The next series of posts are meant to provide comprehensive information about Processing for android.

Processing is a programming language and an integrated development environment (IDE). In fact, Processing was the first open source programming language that was meant for non-programmers to create visual artworks. It was started as a project at MIT by Casey Reas and Ben Fry, under the supervision of John Maeda. It provides tools for developing sketches for android, online applications and desktop applications for major operating systems.
Processing itself is a Java application and runs on the JVM. Because of this fact, it can run as a HTML code on any HTML supported browser or on a local machine such as JVM installed on a desktop or a mobile device running android OS.
Initially created to serve as a software sketchbook and to teach computer programming fundamentals within a visual context, Processing evolved into a development tool for professionals. Today, there are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production.

Striking features that made Processing popular are:
·        Free to download and open source
·        Interactive programs with 2D, 3D or PDF output
·        OpenGL integration for accelerated 3D
·        For GNU/Linux, Mac OS X, and Windows
·        Over 100 libraries extend the core software
·        Well documented, with many books available

References:
1.     Programming Interactivity, 2nd Edition, by Joshua Noble




Friday, July 11, 2014

Forex Travel Card for students travelling to The USA from India

Its July already! In a few days time, we can see flocks of young Indian brains taking off to the land of opportunities. We are all in a shopping spree now; shopping, learning to cook, collecting documents, getting loans approved, buying bags, packing, visiting friends and relatives and what not? Amidst such power packed weeks, one thing which constantly baffles our minds is that one question : "How are we going to manage our expenses there?".

Thinking of carrying traveler's cheques? - Welcome to the era of 1990s :p
Grow up, people! Come on, we have completed one tenth of the 21st century already! E-Commerce is the buzz word now. Don't you want to manage the deposits and spendings online? Well, then opt for the "Traveler's Forex Card". Here's a TOI report on the Traveler's Card (different banks call it by different names).
And this one is for the loyal "The Hindu" fans:

Now that we are on the same page, lets dig more into what this card is all about. This card is yet another debit card, but with a striking difference. You cannot use it within India (this includes Indian E-Commerce sites like flipkart, snapdeal, etc.). Yes, you heard it right! You can't use it here. Then what do you use it for? You deposit the INR equivalent of $1000 (for eg. $1000 = Rs. 61360 as on 11/07/2014) into this card's account in India and you spend $1000 using this card at the US. As simple as that. Fluctuations in currency won't affect the balance in your account. But what makes this attractive is the fact that you don't pay any extra charges on the goods purchased in merchant establishments (that accept VISA or Mastercard). And there's more, there are no extra charges on the goods purchased online, via the E-Commerce websites like ebay and Amazon too! ONE THING TO NOTE IS, TO OWN A CARD YOU DON'T NEED TO HAVE AN ACCOUNT IN THE BANK FROM WHICH YOU WISH TO BUY THE CARD. Despite, having an account can help you to request the bank to transfer money from that account to the card's account; this is important because RBI regulations don't allow you to pay the bank via cash. However, if you(or your representative) hold an account in another bank, you(or your representative) may consider giving a cheque.

I was curious to know more about this and went on a hunt to seek the best deals available on these cards. Based on my research, I've listed below some of the major players only. There do exist other banks and establishments offering similar services (like Thomas Cook). But we do need the one's that are omnipresent and easily accessible, don't we?

Here's a list of observations, that are general to all the banks offering these cards.

  • Charges for getting the card (one time payment) - Rs. 100 to Rs. 450 (varies with bank)
  • Charges for loading cash into the card's account - Rs. 75 to Rs. 250 (varies with bank)
  • Charges for withdrawing money from ATM using this card (only in the US) - $1.5 to $2 (varies with bank)
  • Charges for checking the balance using an ATM - $0 to $0.55 (varies with bank)
  • Charges for "swiping" card at merchant outlets (only in the US) - Free!!!
  • Charges for online purchases (only in the US) - Free!!!
  • Hidden charges - Damn! There is service tax (varies with bank) for every thing task you do (except of-course for looking at it) 
Here is a comprehensive list of the charges for each bank. As you can guess, my favorite one's top my list. 

Sl.NO
TRAVEL CARD
SETUP
RELOAD
WITHDRAWAL
BALANCE CHECK
1
Rs. 125
Rs. 75
$2
$0.50
2
Rs. 150
Rs. 100
$1.50
$0.50
3
Rs. 150
Rs. 100
$2
$0.50
4
Rs. 125
Rs. 75
$2
$0.50
5
$1
$1
$2
$0.50
6
$3
$2
$1.50
$0.55
7
Rs. 125
Rs. 100
$2
$0.50
8
Rs. 100
Rs. 100
$1.50
$0.50
9
Rs. 250
Rs. 100
$1.50
$0.50
10
$7
$4
$1.75
Nil
I hope this information helps you. All the best graduates!

Monday, June 30, 2014

Fundamentals of Digital Image and Video Processing - Week 12 Solutions

Hi Coursera people,

This is a follower submitted code. Thanks to Mokam for this code.

Solution to question 8 of Week 12.

b = [-2,-6,-9,1,8,10,1,-9,-4,-3]';
S = 3;
for i = 1:10
for j = 1:10
A(i,j) = sin(i+j);
if (i==j)
A(i,j) = A(i,j) +1;
end
end
end
for i = 1: 10
Anorm(:,i) = A(:,i)/norm(A(:,i));
end
A = Anorm;
x = zeros(10,1);
r = b;
omg = [];
A_omg = [];
while nnz(x)<3 nbsp="" p="">i = 0;
maxnorm = 0;
for j=1:10
if(any(j==omg))
else
x_j = norm(transpose(A(:,j)) * r);
if(maxnormmaxnorm = x_j;
i = j;
end
end
end
omg = [omg, i];
A_omg = [A_omg, A(:,i)];
z_omega_star = pinv(A_omg' * A_omg) * A_omg' * b;
r = b - A_omg * z_omega_star;


x = zeros(10,1);
for j=1:length(omg)
index = omg(1,j);
x(index,1) = z_omega_star(j,1);
end
end

Answer is the matrix omg, in ascending order.

-Cheers,
Vijay.

Monday, June 16, 2014

Fundamentals of Digital Image and Video Processing - Week 11 Solutions

Hi Coursera people,

Week 11 was not very mathematically intensive, except for the fact that I couldn't grasp the equations. I have to admit that I did understand all of the concepts of segmentation that were spoken about in the class. I was very keen to try the quiz, as this week's material was pretty challenging! The question on programming was so skillfully worded that it could baffle and deter a normal soul! And that feeling when you see a full 11 point score on the first attempt is so intriguing; you just can't express through words :)

Here is the question number 9 of week 11 :

In this problem, you will use Accumulative Difference Image (ADI) to calculate the motion of an object. The object is a bright rectangle moving with a constant speed in a dark background. Your task is to find out the speed of the object in the horizontal direction (x direction) and in the vertical direction (y direction), as well as the total space this object occupied while moving. The total space is defined as the total number of pixels that this object occupies at least once during its movement. Download the MATLAB code "motion_ADI.m" from here. The code has detailed comments regarding each functioning part. Basically, the code generates the reference frame and 10 consecutive frames containing the moving object. All you need to do is to decide on the appropriate threshold T in line 23 in the code and implement the three equations for ADI in the video lectures regarding motion-based segmentation. Starting your code flowing line 37 and finish it before the end of the for-loop. The rest of the code will calculate the speed of the moving object and the total space it occupies for you. Enter the values of speed_X_Direction, speed_Y_Direction, and total_space_occupied in the box below.

Here is my attempt at the code : (thanks to the discussions in the forums by fellow learners)

clear all
close all


A = zeros(256,256); % initialize a 256*256 image

% initialize absolute ADI, positive ADI and Negative ADI
% all initialized to zero
% Note that all ADIs are of the same size with the image
% DO NOT change the name of the ADIs as they will be used later
ADI_abs = zeros(256,256);
ADI_pos = zeros(256,256);
ADI_neg = zeros(256,256);

% initialize the starting position of the moving object
% the moving object is a rectangle similar to the example in the lecture
% slides
start1 = 100;
start2 = 150;
start3 = 40;
start4 = 110;

%threshold T as in euations in the lecture slides regarding ADI
T = 0.1;

%initialize the reference frame R
A(start1:start2, start3:start4) = 1;

%visualize the object and in the reference frame R
figure,imshow(A,[], 'border','tight');

j = 0;
for i = 5: 5 :50
        j = j + 12;
        A2 = zeros(256,256);
        A2(start1 + i: start2 + i, start3 + j: start4 + j) = 1;
        ADI_abs(abs(A-A2) > T) = ADI_abs(abs(A-A2) > T) +1;
        ADI_pos((A-A2) > T) = ADI_pos((A-A2) > T) +1;
        ADI_neg((A-A2) < -T) = ADI_neg((A-A2) < -T) +1;
     
        % You need to code up the follwing part that calculate the ADIs
        % Namely, the absolute ADI, the positive ADI and the negative ADI
        % Equations can be found in lecture slides regarding ADIs
        % You need to decide on the appropriate threshold T for this case
        % at line 23
end

% The following part will calculate the moving speed
% and the total space(in pixel number) occupied by the moving object
[row, col] = find(ADI_neg > 0);
speed_X_Direction = (max(col) - start4) / 10
speed_Y_Direction = (max(row) - start2) / 10
total_space_occupied = sum(sum(ADI_abs > 0))

% The following part helps you to visualize the ADIs you compute
% compare them with the example shown in lecture
% You should be getting someting very similar
figure,imshow(ADI_abs,[], 'border','tight');
figure,imshow(ADI_pos,[], 'border','tight');
figure,imshow(ADI_neg,[], 'border','tight');

-Cheers,
Vijay.



Saturday, June 14, 2014

Fundamentals of Digital Image and Video Processing - Week 10 Solutions

Hi Coursera people,

Well, for a pretty lecture intensive week, the solution to the problem posted was rather simple!

Just run the code without changing any parameters, and it should work fine!

PS : Remember to change the path of the images in the downloaded program!

-Cheers,
Vijay.

Tuesday, June 3, 2014

Fundamentals of Digital Image and Video Processing - Week 9 Solutions

Hi Coursera people,

I have to admit that the initial part of this week was very highly mathematical and I couldn't understand the videos. I was expecting the assignment to be equally tough. But to my surprise, the assignment was a straightforward implementation of a built-in Matlab function!

Here goes the Question number 7 of Week 9 :

In this problem you will get hands-on experience in JPEG image compression. Follow the instructions below to complete this problem. (1) Download the original 8-bit grayscale image here, and load it into a MATLAB array. (2) Perform JPEG compression by using the MATLAB function "imwrite". For the purpose of this problem, you need to specify 5 input arguments. The first argument is the MATLAB array containing the input image; the second argument is a string specifying the output file name; the third argument is 'jpg' (including the single quotes); the fourth argument is the string 'quality' (including the single quotes); and the last argument is a number that specifies the quality level used for compression. The quality level is an integer between 0 and 100. For this step, set the quality level to be 75 (the defaut value). After the function "imwrite" is invoked, a new JPEG image will be created in the location that was specified by you. (3) Load
the newly created JPEG image into a MATLAB array. Compute the PSNR between the JPEG compressed image and the original image. Note that the image loaded into MATLAB is of type 'uint8' (i.e., 8-bit integer). In order to compute the PSNR, you need to convert these arrays into 'double'. (4) Repeat steps (2) and (3) with the quality level set at 10. Enter the PSNR values corresponding to the JPEG images at quality level 75 and 10, respectively. Enter the numbers to 2 decimal points.

Here is my attempt at the code :

Original = imread('D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\Cameraman256.bmp');
Original_double = im2double(Original);
imwrite(Original,'D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\Converted.jpg','jpg','quality',75);
Converted = imread('D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\Converted.jpg');
Converted_double = im2double(Converted);
MSE1= mean(mean((Original_double - Converted_double).^2,2));
MaxI=1;
PSNR1=10*log10((MaxI^2)/MSE1);
imwrite(Original,'D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\ConvertedLowQual.jpg','jpg','quality',10);
ConvertedLowQual = imread('D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\ConvertedLowQual.jpg');
ConvertedLowQual_double = im2double(ConvertedLowQual);
MSE2 = mean(mean((Original_double - ConvertedLowQual_double).^2,2)); % get the MSE
PSNR2=10*log10((MaxI^2)/MSE2);
PSNR1
PSNR2

-Cheers,
Vijay.