Matlab Class Home      Class Outline      Previous Task      Next Task      Main Class Page      Evaluation 13

Task 13.2 Detail: Manipulating and modifying images

Summary of new tools and commands.

Task: Write a script to read the image in Image3.png. Determine the range of color numbers for this image. Create a new image with color numbers spanning half of the range of the original image. Display both images.

Because image descriptions are contained in arrays of integers, it is relatively easy to manipulate the image. A png image is an indexed image where each pixel has a single integer indicating the color number. You can manipulate the colormap to change the colors. Or you can manipulate the color numbers for a larger effect.

Consider that the image has color numbers from 1 to 64 (like the .png image above). Then it is possible to shift the color numbers. Consider the following transformations:

  IM2=imread('Image3.png');
  IM2a=IM2;
  i=find(IM2 > 32); IM2a(i)=64;
  i=find(IM2 < 32); IM2a(i)=1;
  figure
  image(IM2a);title('Modified image 3')
%
  IM3=.5*(IM2-32) + 32;
  figure
  image(IM3)

   SS13_2a

   SS13_2b

The first example shifts all colors above 32 to be the top color (64) while all colors below 32 will be the first color (1). The middle color (32) remains in the image. The second part reduces the color range to be half of its original range relative to the middle color.

   SS13_2c

The script below takes the flujet image (400x300) and averages the colors over 30x30 pixel blocks, creating a blocky looking image.

  FJ=load(flujet.mat);
  im4=FJ.X;Bim4=im4;
  for i=1:10
    ia=(1+(i-1)*30):(i*30);
    for j=1:10
      ja=(1+(j-1)*30):(j*30);
      m=mean(mean(im4(ia,ja)));
      Bim4(ia,ja)=m;
    end
  end
  figure;image(Bim4);colormap(FJ.map);title('Blocky flujet')

   SS13_2d

Similar commands can be used with true color (RGB) images.

Flow chart to accomplish task:

%%%  read image file
%%%  display image
%%%  determine min and max color numbers
%%%  determine middle color number
%%%  create new image with different color numbers
%%%  display new image

Script to accomplish task:

  FILE3='Image3.png';
%%%  read image file
  im3=imread(FILE3);
%%%  display image
  figure;image(im3);title('Original Image3')
%%%  determine min and max color numbers
  minC=min(min(im3));maxC=max(max(im3));
%%%  determine middle color number
  midC=round(.5*(minC+maxC));
%%%  create new image with different color numbers
  Mim3=round(.5*(im3-midC));
%%%  display new image
  figure; image(Mim3);title('Modified Image3')

   SS13_2a

   SS13_2e

Matlab Class Home      Class Outline      Previous Task      Next Task      Main Class Page      Evaluation 13


email: J. Klinck