DSPRelated.com
Code
The 2025 DSP Online Conference

Image Quantizer Demo

Ron April 1, 2011 Coded in Matlab

Shows the effect of different levels of quantizaiton on an RGB image in time lapse.

clf;
for (truncate = 0:8)
x = imread('aqua.jpg');
subplot(2,2,1);
imshow(x);
subplot(2,2,2);
x_t = (x/2^truncate) * 2^truncate;
%if above line doesn't work your MATLAB is old! use next line:
% x_t = uint8(double(uint8((double(x)/2^truncate))) * 2^truncate);
imshow(x_t);
subplot(2,2,3);
imshow(uint8(abs(double(x_t) - double(x))));
pause(0.5);
end

The 2025 DSP Online Conference