For a school project, I need to think up some (hopefully easy) ways to compress (and decompress) images. I have looked at JPEG's algorithm, but it seems like much too much work to implement. This is just an assignment, so I was trying to think of algorithms that would be easier to implement in Matlab.
Lately, I have been trying to compress a grayscale image by transforming it into frequency space with a Fourier Transform. Then I would examine each value of the transformed matrix and, if the value was small enough, I would just set it zero. I would then use run-length-encoding to pack all the zeroes. However, when I decoded (i.e. unpacked and transformed back to pixel space) the image, pretty much all the values were zero (i.e. the image was all black); however, most values in frequency space were not zero. What am I doing wrong?
Here is my Matlab code. It takes as input a 3-d matrix that stores red green and blue values.
function out = FFTCOMPRESS( in )
x = length(in(1,)/3
y = length(in(:,1))
fr = fft2(in(:,:,1));
fg = fft2(in(:,:,2));
fb = fft2(in(:,:,3));
myout = zeros(1, 5+4*y*x*3);
myout(1) = x;
myout(2) = y;
myout(3) = 6;
for ii=1:y,
for jj=1:x,
if fr(ii,jj)<10
fr(ii,jj)=0;
end
if fg(ii,jj)<10
fg(ii,jj)=0;
end
if fb(ii,jj)<10
fb(ii,jj)=0;
end
end
end
n = 6
nz = 0
for jj=1:x,
for ii=1:y,
if nz ~= 0,
if fr(ii,jj)==0
nz=nz+1;
else
myout(n)=0;
myout(n+1)=nz;
myout(n+2)=fr(ii,jj);
nz=0;
n=n+3;
end
else
if fr(ii,jj)==0
nz=nz+1;
else
myout(n)=fr(ii,jj);
n=n+1;
end
end
end
end
nz=0;
myout(4)=n;
%Do the same think for fg & fb - I ommited this part.
out=myout(1:(n-1));
Also, does anyone have any other good ideas about how I could easily compress images? Furthermore, does anyone know of a good way to compare the quality of a compressed image with its original?
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
Image Compression
in Computer Science
Posted
For a school project, I need to think up some (hopefully easy) ways to compress (and decompress) images. I have looked at JPEG's algorithm, but it seems like much too much work to implement. This is just an assignment, so I was trying to think of algorithms that would be easier to implement in Matlab.
Lately, I have been trying to compress a grayscale image by transforming it into frequency space with a Fourier Transform. Then I would examine each value of the transformed matrix and, if the value was small enough, I would just set it zero. I would then use run-length-encoding to pack all the zeroes. However, when I decoded (i.e. unpacked and transformed back to pixel space) the image, pretty much all the values were zero (i.e. the image was all black); however, most values in frequency space were not zero. What am I doing wrong?
Here is my Matlab code. It takes as input a 3-d matrix that stores red green and blue values.
Also, does anyone have any other good ideas about how I could easily compress images? Furthermore, does anyone know of a good way to compare the quality of a compressed image with its original?