Line 28: Line 28:
  
 
%Seperate the image matrix into R G and B
 
%Seperate the image matrix into R G and B
 +
 
R = rgb(:,:,1);
 
R = rgb(:,:,1);
 +
 
G = rgb(:,:,2);
 
G = rgb(:,:,2);
 +
 
B = rgb(:,:,3);
 
B = rgb(:,:,3);
 +
 
%reform a image matrix in size-3 matrix
 
%reform a image matrix in size-3 matrix
 +
 
img(:,1) = R(:);
 
img(:,1) = R(:);
 +
 
img(:,2) = G(:);
 
img(:,2) = G(:);
 +
 
img(:,3) = B(:);
 
img(:,3) = B(:);
  

Revision as of 21:01, 29 November 2015


Implementation of Color Quantization

A slecture by ECE student Yitong Wang

Partly based on the ECE438 Fall 2015 lecture material of Boutin.



1. Introduction (Implementation of Max Quantization)

Quantization is an operation to compress a signal by reducing a range of values to a single value. Color quantization is a process to reduce the number of colors in an image in order to reduce the size. This slecture will describe the color quantization using kmean function in matlab.



2. Background

  • The brightness of a photo at each pixel is typically distributed among integers from 0 to 255. However, since some images are desired to limit the number of colors, the brightness value has to be rounded off to fit the size of the image.
  • During the procedure of quantization, there must be some loss of data. To avoid high error percentage and remain quality as good as possible, using kmean function is a good choice.
  • Max quantizier

3. Theory

  • [ind,color] = kmean(input,k) function performs k-means clustering to partition the observations of the n-by-m data matrix input into k clusters, and returns an n-by-1 vector which represent the index of the values of colors after operation. The operation uses the squared Euclidean distance measure.
  • To start the operation, the image have to be reshaped into a X-3 matrix that contains R,G and B as we used in lab 5. Where X is the number of pixels in each row.

%Seperate the image matrix into R G and B

R = rgb(:,:,1);

G = rgb(:,:,2);

B = rgb(:,:,3);

%reform a image matrix in size-3 matrix

img(:,1) = R(:);

img(:,2) = G(:);

img(:,3) = B(:);

  • Operate the kmean function to get the



$ X = double(input) $

After this, we can do the quantization.

  • Substract X with $ Min(X) $ (To see the difference of value between the pixel and the least bright pixel)
  • Divide the result by Δ and round it to integer
  • Add the result to $ Min(X) $


To make the step simple, we can make a quantization function respect to input X and quantization level N. However, the image signal is in matrix, so just simply use x(:), which convert the matrix into a vactor.

function [y] = Uquant(x,N)

delta = (max(x(:))-min(x(:)))/(N-1); % calculate delta

y = round((x-min(x(:)))/delta).*delta + min(x(:)); % round the quantized value then add with min(x)

end






File:Bit4.jpg


4. Conclusion (Replace by appropriate section title)

Text of fourth section goes here.


5. References

  • Reference 1
  • reference 2


Questions and comments

If you have any questions, comments, etc. please post them here.


Back to 2015 Fall ECE 438 Boutin


Alumni Liaison

ECE462 Survivor

Seraj Dosenbach