Minggu, 16 November 2008

Image compression with Run Length Encoding (RLE) Algorithm

Before it, i made a script about image compression use quantization algorithm. This algorithm is lossy compression, it means we can't decompression our image file after compression.
With RLE algorithm we can save all information in our image.... so nothing to loss. How RLE algorithm work? I will use 6x6 pixel grayscale image (8 degree grayscale) below:
1 1 1 7 1 3
4 4 6 1 2 2

7 7 7 5 5 5
6 4 4 2 2 2
5 5 2 2 2 1

2 3 3 3 0 0

RLE code is a number that contains color intensity and frequency of color intensity coming. Here, we get RLE code below:
1 3 7 1 1 1 3 1 4 2 6 1 1 1 2 2 7 3 5 3 6 1 4 2 2 3 5 2 2 3 1 1 2 1 3 3 0 2

And here source code to make RLE code.... that made with Matlab.
g is grayscale image. And RLE code in rle array. So we can decompression with very easily, because we save all information about image.

Jumat, 31 Oktober 2008

Solution of Linear Equation System with Cramer Method

Actually to get solution of Linear Equation System, we can do it very easy with Matlab. But, remember if in the past we studied Crammer Method for this. Crammer method given in below :
From that method we can arrange an algorithm :
One : input A and B matrix.

Two : We must know dimension of matrix, because matrix A mus be square and matrix B is one column matrix that sum of row equal to matrix A.

Three : We also must know determinat matrix, because matrix A is not singular.
Four : Find matrix A1 until An, and determinat it self.




Rabu, 24 September 2008

Add Cancel Button to a Waitbar

We can add property that indicated a cancel button and a function that be executed if cancel button be select/click.
The source and output gave in above:


Jumat, 27 Juni 2008

Make a Wait Bar with Matlab

In one case, we need a wait bar to know how much process that run. We can make a wait bar to indicate process. In Matlab we use WAITBAR instruction that have syntax above:
H = WAITBAR(X,'title', property, value, property, value, ...)
creates and displays a waitbar of fractional length X. The handle to the waitbar figure is returned in H. X should be between 0 and 1. Optional arguments property and value allow to set corresponding waitbar figure properties. Property can also be an action keyword 'CreateCancelBtn', in which case a cancel button will be added to the figure, and the passed value string will be executed upon clicking on the cancel button or the close figure button (taken from MATLAB HELP)
Example :

Rabu, 14 Mei 2008

How to read text file in Matlab?

Some times we use a matrix that have a big size to testing program that we write. If we must to input it from keyboard...hmmmm....how long time spend for it? So..we can write it to a text file.
For example:
Make a file text(for example data1.txt), that contains above:
25 26 67 68 89 79 28
27 24 16 28 29 16 29
23 35 27 28 29 11 12
87 23 56 79 25 67 25
Each data separated by space.

And for read this file please to type this code in command window:
>> x=load('data1.txt')
x =
25 26 67 68 89 79 28

27 24 16 28 29 16 29
23 35 27 28 29 11 12
87 23 56 79 25 67 25

If our file contain a string don't use LOAD instruction, but we can use TEXTREAD instruction.
For example:
Make a text file('data2.txt') with this sentences:
This is an example text file with string data, that will be read with Matlab.

And for read this file please to type this code in command window:
>> n=textread('data2.txt','%s')
n =
'This'

'is'
'an'
'example'
'text'
'file'
'with'
'string'
'data,'
'that'
'will'
'be'
'read'
'with'
'Matlab.'

Senin, 28 April 2008

Convert RGB image to Grayscale Image

Actualy, there is a built up function in Matlab to convert RGB image to grayscale image. This function is RGB2GRAY. For example, we have RGB image (rgb.jpg) and grayscale image named by gray.jpg, so we have this code:

x=imread('rgb.jpg');
y=rgb2gray(x);
imwrite(y,'gray.jpg');


It's so easy. But...just for fun..i made user defined function in Matlab to do it. Very simple...conversion is done by get the average RGB component.

g=imread('lampu.jpg');
gb=double(g);
[b,kl,rgb]=size(gb);
gbrgb=zeros(b,kl);
for i=1:b
for j=1:kl
gbrgb(i,j)=round((gb(i,j,1)+gb(i,j,2)+gb(i,j,3))/3);
end
end
gbrgb1=uint8(gbrgb);
figure, imshow(g);
figure, imshow(gbrgb1);

Output from this code is :

Selasa, 22 April 2008

Image Compression with Quantization Method

Last time I try to compressed image file with quantization method. Why quantization? Because this method is more easily than other….he…he… I try with two kind of image file. First is grayscale image and the second is RGB image. Grayscale image have a simple digital data, that consist grayscale degree in each pixels (2D matrix). With quantization method we can decrease bit that represent grayscale degree. For example we have 6x6 pixel grayscale image, and each pixel represent with 8 bit. We want to decrease from 8 bit to 4 bit to represent each pixel. So we made a table that convert each value of initial grayscale degree to compressed grayscale degree. We change each value with other value according this table. If we have a RGB file it’s similar with grayscale image. But from RGB image we have 3D matrix that represent width, height and RGB factor. We can consider it as three matrix 2D, namely for R factor, G factor and B factor. Each of matrix consist of R or G or B degree of image. If in initial image three kind of matrix represent with 256 bit and we want to reduce it into 128 bit, so we do it same with in grayscale image. I implemented that method in matlab. I also compare image histogram before an after compression that give in above.
Image and histogram before and after compression in RGB image

Image and histogram before and after compression in grayscale image

Senin, 21 April 2008

Read an image file with Java

This script is used to read image file and show image file in a frame. To read image file, I use imageio. Image will be wrote and saved to image variable. Image variable consist of any information about our image, for example: resolution, color model etc.
Output from those script is :

And than it is an information that consist in image variable.

Other information that I want to know is, how to get information about value of pixels that arrange our image. So…in grayscale image, we can get grey degree and in RGB image we can get RGB degree. In Matlab it can be get easily, but in Java???? I read any online paper about it, but I still confuse…he…he…

Jumat, 11 April 2008

Programming

I'm very like in computer programming. Unfortunately, I must study more in it, because I feel, i don't know much about it. Early, I learn about Pascal in Math and Natural Science at Gadjah Mada University(GMU) in 1993. I choose Computer Science Department at GMU. Beside Pascal, I also learn about C (not C++). Others...? Nothing. But learning about programming concept, it must do. We will use Pascal, C or others it isn't a big problem. Because all of programming language have similarity.
In this time, i must study more because my jobs much relate on it. I learn about Object Oriented Programming, web programming, database programming, image processing and more. There are much topics, that i want to learn, but there aren't much times. All right...slowly but surely.

Rabu, 09 April 2008

They are sick.

I have two sons. The first is Mamat. He is 9 years old and the second is Kori. Kori is 2 years old. We're a happy family. My sons always give me the miracles. But unfortunately, this time their daddy go to Brebes. Brebes is one city at Central Java. So... our happines isn't complete without their daddy.
As mother...I'm very sad because all of my kids were sick. My first son, Mamat couldn't go to school two days ago. But this day he is going to school. Although, I'm worry. Fortunately, grandma and grandpa always give me a suport, so...I must have been strong mother.

Selasa, 08 April 2008

My first post

Hi... I'm Krisna. Live in Jogjakarta Indonesia. A mother with 2 sons. Now..... i want to learn about english. So in this media, i want to write about everything in english.
I think....i start to learn about english when i am in SMP. Because...it's not be excercise so... there aren't significant grow.
Everyones are laugh if read it. But nevermind.... I must learn...learn and learn. Please give me a comment for it, to correct about this post. Thank's....