Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Image Compression Methods

  1. Apr 23, 2009 #1
    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.

    Code (Text):
    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?
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Image Compression Methods
  1. Reading in an image? (Replies: 13)

  2. Image Processing (Replies: 4)

  3. Compression conundrum (Replies: 7)

Loading...