title: Applying Matlab Images Filter On RGB Images
body: <p>i have the following Matlab code to manipulate two images, gray scale image, and <code>RGB</code> image.
  The point is to apply <code>Average</code>,<code>Gaussian</code>, and <code>Laplacian</code> filters on both images.</p>
  
  <pre><code>%%Clear
  clear
  clc
  %%Reading images
  gray=imread('cameraman.tif')
  [gray_table gray_map]=gray2ind(gray,256)
  rgb=imread('peppers.png')
  [rgb_table rgb_map]=rgb2ind(rgb,256)
  %%Creating filters
  average=fspecial('average',3)
  gaussian=fspecial('gaussian',3,0.5)
  laplacian=fspecial('laplacian',0.9)
  %%Applying filters
  average_filterd_gray_table=imfilter(gray_table,average)
  gaussian_filterd_gray_table=imfilter(gray_table,gaussian)
  laplacian_filterd_gray_table=imfilter(gray_table,laplacian)
  average_filterd_rgb_table=imfilter(rgb_table,average)
  gaussian_filterd_rgb_table=imfilter(rgb_table,gaussian)
  laplacian_filterd_rgb_table=imfilter(rgb_table,laplacian)
  %%view
  figure
  subplot(1,4,1),imshow(gray_table,gray_map),title('Original Indexed Gray')
  subplot(1,4,2),imshow(average_filterd_gray_table,gray_map),title('Average Filtered Indexed Gray')
  subplot(1,4,3),imshow(gaussian_filterd_gray_table,gray_map),title('Gaussian Filtered Indexed Gray')
  subplot(1,4,4),imshow(laplacian_filterd_gray_table,gray_map),title('Laplacian Filtered Indexed Gray')
  figure
  subplot(1,4,1),imshow(rgb_table,rgb_map),title('Original Indexed RGB')
  subplot(1,4,2),imshow(average_filterd_rgb_table,rgb_map),title('Average Filtered Indexed RGB')
  subplot(1,4,3),imshow(gaussian_filterd_rgb_table,rgb_map),title('Gaussian Filtered Indexed RGB')
  subplot(1,4,4),imshow(laplacian_filterd_rgb_table,rgb_map),title('Laplacian Filtered Indexed RGB')
  </code></pre>
  
  <p>The code is working fine for the gray scale image. but on RGB image it just gives a distorted result. How to fix that?</p>