Department of Applied Mathematics at the University of Colorado at Boulder
University of Colorado at Boulder Search A to Z Campus Map University of Colorado at BoulderCU Search Links
Print this page

PNG image

17: Read a PNG (or GIF) image, filter, and display

1. Read the grayscale PNG file denise.png into rectangular array A
2. Display A.   Display a smoothed (blurred) version of A.
3. Use FFT to smooth A, and display

Mathematica: (supports both PNG and GIF)

(1)
image = Import["denise.png","PNG"]   or
image = Import["denise.gif","GIF"]
A = image[[1,1]]/255.;

(2)
ListDensityPlot[A,Mesh->False,
    AspectRatio->Automatic]
        -- or --
Show[Graphics[Raster[A]],
    AspectRatio->Automatic]

blurA = ListConvolve[Table[1/25,5,5],A];
Show[Graphics[Raster[blurA]],
    AspectRatio->Automatic]

(3)
B = Fourier[A];
      delete higher frequencies
B[[Range[30,278],All]]=0;
B[[All,Range[30,202]]]=0;
      now invert & display
Show[Graphics[Raster[
    Re[InverseFourier[B]]
    ]], AspectRatio->Automatic]

Matlab: (doesn't support GIF)

(1)
[A,map] = imread('denise.png','PNG');

(2)
image(A);
colormap(gray(256))     % (if necessary)
imagesc(filter2(ones(5,5),A,'valid'));

(3)
B = fft2(A);
      delete higher frequencies
B(:,30:202)=0;
B(30:278,:)=0;
      now invert & display
imagesc(real(ifft2(B)));

Maple:  

 

  • does not support reading image files
  • can plot to a GIF file (but not PNG)
IDL: (doesn't support GIF)

(1)
A = read_png('denise.png')

(2)
tv, A
tv, smooth(A,5), 250, 0

(3)
B = fft(A,1)
z=size(A)
freq=dist(z[1],z[2])
tvscl, fft(B * (freq lt 40), -1)