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…