How to change the boot loader

Hi, today I’m going to introduce an important windows software . The reason to talk about this software was an personal experience of me. Recently I had to install Win 7 on my Laptop to work with Photoshop CS5 for designing some graphics. So after I install the Win 7 suddenly I realise then my Ubuntu is no more functioning. That means Master Boot Record was changed. In that case , I used Easy BCD software to correct that boot records.

DOWNLOAD Easy BCD here!

Installing Win7 after Linux always happens this. So you have to change boot records after installing (only if you don’t see the boot menu).

To change the boot records with the dual boot system. Open Easy BCD

Then click Add New Entry . Then you will see a window like this.

Then click Linux BSD tab, change under type: as GRUB(Legacy)

Then reboot the computer, you will see your boot menu. That’s all 😀

In this post I would like to mention and say thanks to my friend Buddika for introducing EasyBCD to me.

Thanks

Gihan De Silva @ gihansblog.com

How to install Apache Tomcat server on Ubuntu 11.04

Hi, Today I’m going to tell you how to install Apache tomcat server on your Ubuntu (Linux) computer. You can install and use it as a portable installation on your pen drive too.Apache tomcat server is used to run .jsp file (Java Server Pages). So first you need to download Apache Tomcat 7.0 from Apache site.

DOWNLOAD Apache tomcat here!..

Ok let’s do it. Now extract the downloaded apache-tomcat-7.0.19.tar.gz file into desktop or to your pen drive.

Then rename it as tomcat (only for our convenience)

Open Terminal window (Ctrl+Alt+T)

Then go to this folder using this command : cd Desktop/tomcat/bin ( assuming you extracted on your Desktop )

Then run this command(run startup.sh shell script) : ./startup.sh

Now open firefox go to this URL : http://localhost:8080/ . Then you should see it like this!

Now try a jsp script to test the installation.

If you want to, copy this code and save it into tomcat–>webapps–>ROOT as hello.jsp  Then run it http://localhost:8080/hello.jsp  😀

<html>
<head>
<title>JSP Test page.</title>
</head>
<body>
<p align=”center”><font color=”#009900″ size=”7″><%=”gihansblog.com”%></font></p>
<p align=”center”><font color=”#FF0000″ size=”6″><%=”Hello JSP World!”%> </font></p>
<p><%= new java.util.Date()%></p>
</body>
</html>

To shut-down the Tomcat server use this command(run shutdown.sh shell script) : ./shutdown.sh

Thanks

Gihan

Moving to a new domain name… gihansblog.com

Hi, A little Announcement for all the readers of Gihan’s Blog. That is gihansblog.wordpress.com moving to gihansblog.com :D. Now it’s been around two months that I’ve started this blog. There are lot of people who give me strength to carry on this blog by commenting, discussing and saying ‘Hi’.And I appreciate all those things.

I got this domian name form GoDaddy.com. And I forwarded it into my old wordpress domain name through their forwarding facilities.  And anyone interesting on more info about getting a domain, masking ,forwarding or anything regarding this , I’d like to share my experience. 😀

Now you can find my Blog on http://gihansblog.com/ . 😀

Thank you

Gihan Malan De Silva @ gihansblog.com/

Java 7 Released… (watch the video)

Good and very Important News for all. That is Java 7 had released on 7th July 2011. Ceremony speech was given by Adam Messinger, vice president of development Fusion Middleware. According to dream team of Java , in the new version of Java has a big different comparing than the other versions of Java. And this is the first release of Java with Oracle company.And they has made it as MOVING JAVA FORWARD!

With Oracle, Java’s future  has goes with  the  new technology, the community, the Java Community Process (JCP), and the entire ecosystem focused on moving Java forward.

And they has categorised new Technical Breakout of Java 7

  1. Making Heads and Tails of Project Coin, Small Language Changes in JDK 7
  2. Divide and Conquer Parallelism with the Fork/Join Framework
  3. The New File System API in JDK 7
  4. A Renaissance VM: One Platform, Many Languages

Java 7 Released… from Gihan on Vimeo.

Just watch it. It’s worth to watch…

Thanks

Gihan Malan De Silva

Rotate an image with java Buffered image class..

Hi, today I’m going to show you another image enhancing technique with Java’s Buffered image class. That is rotating an image. To rotate an image with Java we use classes called AffineTransform and AffineTransformOp. And let’s see how to rotate an image. It is very easy as previous things.

In this post I’m not going to describe basics like creating an buffered image, display a buffered image on a JLabel..  etc .. but to describe methods I wrote in my program.

1). public void rescale() {}

2). private void rorateImg() {}

Let’s consider one by one..

public void rescale() {

        tx = new AffineTransform();
        tx.rotate(angel,w / 2, h / 2);//(radian,arbit_X,arbit_Y)

        op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);
        bufferedImage=op.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale()

Before rotating the image...

In rescale() method I’ve created an AffineTransform object then called the rotate() method.

tx = new AffineTransform();

double theta, double anchorx, double anchory parameters should be passed into the rotate() method. This method rotates an image around an anchor point which coordinates equals to anchorx,anchory . And the theta should be give in radians. And this procedure equal to these three operations.
translate(anchorx, anchory);      // final translation
rotate(theta);                                 // rotate around anchor
translate(-anchorx, -anchory);   // translate anchor to origin

double angel=Math.PI/2;

This Math.PI/2 equals to 90 degrees.

   int w;// width of buffered image
   int h;//height of buffered image

then Buffered Image’s getWidth() and getHeight() methods assigns image’s width and height into w and h.

  w= bufferedImage.getWidth();
  h=bufferedImage.getHeight();

tx.rotate(angel,w / 2, h / 2);

By assigning w/2 and h/2 into anchorx and anchory I made the image to rotate around it’s center point. Then AffineTransformOp object is created. When creating the object an AffineTransform object and Bilinear interpolation type are given as parameters.

op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);

Then the filter() method is called with AffineTransformOp object. This public final BufferedImage filter(BufferedImage src, BufferedImage dst) method is more likely the filter() in RescaleOp which we discussed. And this method compares source and destination images then returns the filtered buffered image. 

bufferedImage=op.filter(bufferedImage,null);

After rotating the image...

private void rorateImg(){

        w= bufferedImage.getWidth();
        h=bufferedImage.getHeight();

        rescale();             

        icon = new ImageIcon(bufferedImage);          
        picLabel.setIcon(icon);

    }//end rotateImg()

In here I earlier discussed what happens with w= bufferedImage.getWidth(); and h=bufferedImage.getHeight(); . Then rescale() method is called and the other codes describes the displaying the buffered image on a JLabel. 😀 😀 ok that all.

And here is related Java docs.

1) AffineTransform

2) AffineTransformOp

Here is the source code of it and if you want you can DOWNLOAD my Netbeans project. And it has two classes Rotate.java and Main.java which is included the main method.

Main.java

/*
 * Main.java
 */
package rotate;

/**
 *
 * @author gihan
 */
public class Main {
     public static void main(String[] args) {
        Rotate obj=new Rotate();
    }

}

Rotate.java

/*
 * Rotate.java
 */
package rotate;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;

/**
 *
 * @author gihan
 */
public class Rotate extends JFrame{

    // globel variables

    BufferedImage bufferedImage;
    RescaleOp rescale;
    ImageIcon icon;
    AffineTransformOp op;
    AffineTransform tx;
    int w;// width of buffered image
    int h;//height of buffered image
    double angel=Math.PI/2; /** angle should be given in radian and
                                        * this program rotates the image in 90 degrees */
    String path=”/home/gihan/Pictures/nfs_bmw.jpg”;// image file path  
    JLabel picLabel=new JLabel();

    public Rotate(){

         JFrame jf=new JFrame();
         JPanel jp=new JPanel();        

         jf.add(jp);
         jp.add(picLabel);

            jf.setVisible(true);
            jf.setSize(487, 640);
            jf.setLocation(200,200);
            jf.setTitle(“Gihan’s Image Processing Test Area.. “);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            File file = new File(path);

        try {           
            bufferedImage = ImageIO.read(file); // create a buffered image
        } catch (IOException ex) {
            Logger.getLogger(Rotate.class.getName()).log(Level.SEVERE, null, ex);
        }
            rorateImg();

         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
    }

    private void rorateImg(){//rotates 90 degrees

        w= bufferedImage.getWidth();
        h=bufferedImage.getHeight();

        rescale();             

        icon = new ImageIcon(bufferedImage);          
        picLabel.setIcon(icon);

    }

    public void rescale() {

        tx = new AffineTransform();
        tx.rotate(angel,w / 2, h / 2);//(radian,arbit_X,arbit_Y)

        op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);
        bufferedImage=op.filter(bufferedImage,null);//(sourse,destination)

       }

}//end class Rotate

 

If you have any doubt, feel free to ask. :D
Thank you

Gihan Malan De Silva @ gihansblog.wordpress.com

Contrast control with java Buffered image class..

Hi, in this post I’m going to tell you how to change the contrast of an buffered image. And it will be very easy to you if you read my previous post on Brightness control with java Buffered image class... Here I’m going to explain only the key methods and others will be same as Brightness control.

In this program also here are two methods I’ve written.

1). public void rescale() {}

2). private void contrastChange() {}

Let’s consider them, one by one

An Image before change the Contrast...

        public void rescale() {

        rescale = new RescaleOp(scaleFactor,20.0f, null);
bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale
In here, I’ve created RescaleOp object, and should pass parameters as in order sacleFactors, offsets,  hints .

By changing offsets value we can adjust the brightness of an image, and by changing sacleFactors value we can adjust contrast of an image and hints for the specified RenderingHints or can be kept as null. In my program scaleFactor is set to 1.0 in float for default image and for enhanced image it is set to 3.6 in float.

An Image after increasing the Contrast...

private void contrastChange(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
         System.out.println(“scaleFactor : “+scaleFactor  );

    }//end  contrastChange()

In the filter method filter(sourse_bufferedImage, destination_bufferedImage); should be given as like this, and it returns filtered buffered image. Then in the contrastChange() the rescale() method is called and as I mentioned in my previous post, the buffered image is printed on a JLabel. :D

Here is the source code of it and if you want you can DOWNLOAD my Netbeans project. And it has two classes Contrast.java and Main.java which is included the main method.

Main.java

/*

* Main.java

*/
package contrast;

/**
 *
 * @author gihan
 */
public class Main {
     public static void main(String[] args) {
        Contrast obj=new Contrast();
    }//end main()

}//end class Main

Contrast.java

/*
 * Contrast.java
 */
package contrast;

import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author gihan
 */
public class Contrast extends JFrame{
       //globel variables
        BufferedImage bufferedImage;
        String path=”/home/gihan/Pictures/nfs_bmw.jpg”;// image file path     
        float scaleFactor=3.6f;//change scaleFactor to change contrast        
        /*keep the value scaleFactor = 1.0f; as for a normal image*/
        RescaleOp rescale;
        ImageIcon icon;
        JLabel picLabel=new JLabel();

     public Contrast() {

         JFrame jf=new JFrame();
         JPanel jp=new JPanel();        

         jf.add(jp);
         jp.add(picLabel);

            jf.setVisible(true);
            jf.setSize(740, 487);
            jf.setLocation(200,100);
            jf.setTitle(“Gihan’s Image Processing Test Area.. “);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            File file = new File(path);

        try {           
            bufferedImage = ImageIO.read(file); // create a buffered image
        } catch (IOException ex) {
            Logger.getLogger(Contrast.class.getName()).log(Level.SEVERE, null, ex);
        }

         contrastChange();   
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);       

    }

     private void contrastChange(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
         System.out.println(“scaleFactor : “+scaleFactor  );

    }//contrastChange()

     public void rescale() {

        rescale = new RescaleOp(scaleFactor,20.0f, null);
        bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale

}//end class contrast

If you have any doubt, feel free to ask. :D
Thank you

Gihan Malan De Silva @ gihansblog.wordpress.com

Brightness control with java Buffered image class..

Hi, today I’m going to tell you how to change brightness of an image with Java’s Buffered image class. .. And consider this will be a series of posts regarding image processing/enhancement with Java  🙂 .

First we need to create an String variable to store the path of image file.

String path=”filepath_of_ your_image”;

for a example I used : String path=”/home/gihan/Pictures/nfs_bmw.jpg”;

Then create a file type object. And give our path as parameter.

File file = new File(path);

Then create a  buffered image.

BufferedImage bufferedImage = ImageIO.read(file);

If you want to, now you can preview your image using :

ImageIcon icon;
JLabel picLabel=new JLabel();

 icon = new ImageIcon(bufferedImage);          
 picLabel.setIcon(icon);

An Image before change the Brightness...

But we are going to process that image so let’s move to next point. There are two methods I’ve written in my programm.

1). public void rescale() {}

2). private void brighten() {}

Let’s consider them, one by one
     public void rescale() {

        rescale = new RescaleOp(1.0f,offset, null);
        bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale
In here, I’ve created RescaleOp object, and should pass parameters as in order sacleFactors, offsetshints .

By changing offsets value we can adjust the brightness of an image, and by changing sacleFactors value we can adjust contrast of an image and hints for the specified RenderingHints or can be kept as null. In my program offset is set to 20 in float for default image and for enhanced image it is set to 170 in float.

An Image after change the Brightness...

Here you can look at the related java docs.

In the filter method filter(sourse_bufferedImage, destination_bufferedImage); should be given as like this, and it returns filtered buffered image.

Then in the private void brighten()  method I think there is nothing to describe. 😀 :D. I called the rescale() method and as I mentioned earlier, the buffered image is printed on a JLabel. 😀
private void brighten(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);

    }//end  brighten()

Here is the source code of it and if you want you can DOWNLOAD my Netbeans project. And it has two classes Bright.java and Main.java which is included the main method.

Main.java
/*
 * Main.java
 */
package bright;

/**
 *
 * @author gihan
 */
public class Main {

    public static void main(String[] args) {
        Bright obj=new Bright();
    }//end main()

}//end class Main

Bright.java

/*
 * Bright.java
 */
package bright;

import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author gihan
 */
public class Bright extends JFrame{
       //globel variables
        BufferedImage bufferedImage;
        String path=”/home/gihan/Pictures/nfs_bmw.jpg”;// image file path         
        float offset = 170.0f;//change offset to brighten
        /*keep the value offset = 170.0f; as for a normal image*/
        RescaleOp rescale;
        ImageIcon icon;
        JLabel picLabel=new JLabel();

     public Bright() {

         JFrame jf=new JFrame();
         JPanel jp=new JPanel();        

         jf.add(jp);
         jp.add(picLabel);

            jf.setVisible(true);
            jf.setSize(550, 550);
            jf.setLocation(200,100);
            jf.setTitle(“Gihan’s Image Processing Test Area.. “);
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            File file = new File(path);

        try {           
            bufferedImage = ImageIO.read(file); // create a buffered image
        } catch (IOException ex) {
            Logger.getLogger(Bright.class.getName()).log(Level.SEVERE, null, ex);
        }

         brighten();   
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);       

    }

     private void brighten(){

         rescale();
         icon = new ImageIcon(bufferedImage);          
         picLabel.setIcon(icon);
         System.out.println(“offset : “+offset  );

    }//end  brighten()

     public void rescale() {

        rescale = new RescaleOp(1.0f,offset, null);
        bufferedImage=rescale.filter(bufferedImage,null);//(sourse,destination)

       }//end rescale

}//end class Bright

If you have any doubt, feel free to ask. 😀
Thank you

Gihan Malan De Silva @ gihansblog.wordpress.com

Apple CEO Steve Jobs doing great speech @ Stanford University.

I think everyone in Com.science field  must watch this. He is doing amazing speech. Just watch it. 😀

Convert your Blogger Bolg into WordPress or WordPress Blog into Blogger…

Hi, today my blog post will be a little one. Because today I’m not going to give you clues about software or any other thing. I thing this will also help you sometime or some day. Sometimes you may wondering How to bring your WordPress blog to Blogger or  Blogger blog into WordPress Blog. But the problem is WordPress still do not facilitate to export it to Blogger .

OK this is the simplest way to do it. I found a Open source project that facilitate us to convert Blog. And it contains a number of converters  for different Blog services. The source code is written in Python. And if you want to, you can download the source code too.

Link for Blog Converter Open Source Project: http://code.google.com/p/google-blog-converters-appengine/

Convert your WordPress Blog into Blogger Blog…!

First go to your WordPress Blog,

then under the Tools click export

Then clicking the export get the xml file.

then goto this link

Then get the converted xml file from that site.

Then go to your Blogger  blog.

under the settings click import blog

😀 Now your WordPress blog live in Blogger.

Convert your Blogger Blog into WordPress Blog…!

This is much easy than the other thing, because already this feature is facilitated by WordPress. 🙂

 

 

First go to Your Blogger blog

under the settings click export blog

By clicking Export blog Download the xml file

Then go to the WordPress Blog.Then click import

After that you will see a page like this..

Because WordPress allows to import Blogger Blogs.. 😀

So, import your blogger xml file, then you will see your blogger bog on WordPress. 😀

Thank you

Gihan Malan De Silva.