Lecture 3
Intensity Transformations
   and Spatial Filtering
Outlines
 ▪ About image enhancement
 ▪ Some basic intensity transformation functions
 ▪ Histogram processing
 ▪ Fundamentals of spatial filtering
 ▪ Smoothing spatial filters
 ▪ Sharpening spatial filters
  About Image Enhancement
❖ Image enhancement is the process of making images
   more useful
❖ The reasons for doing this include:
       ▪ Highlighting interesting detail in images
       ▪ Removing noise from images
       ▪ Making images more visually appealing
  About Image Enhancement
Schematic diagram of image enhancement technique
    About Image Enhancement
Spatial Domain Image Enhancement Techniques: Basically, two
categories: mask processing and point processing .
1. Point processing: each pixel in original image at
   coordinates (x, y) is processed to create the corresponding
   pixel at coordinates (x, y) in the enhanced image
2. Mask processing: Not only the pixel in original image at
   coordinates (x, y) is processed, but also some neighboring
   pixels of this pixel at coordinates (x, y) in the enhanced
   image are involved in creating the new pixel.
About Image Enhancement—Several Examples
About Image Enhancement—Several Examples
About Image Enhancement—Several Examples
About Image Enhancement—Several Examples
About Image Enhancement—Several Examples
Spatial domain VS frequency domain
   Spatial domain VS frequency domain
▪ Spatial domain techniques directly manipulate image
  pixels
▪ Frequency domain techniques manipulate Fourier
  transform or wavelet transform of an image
      About Image Enhancement
Image is often described in the space domain or the frequency
domain
(a) Schematic diagram of
mask processing with
many input pixels to
produce one output pixel
(b) Schematic diagram of
point processing technique
using one to one.
Spatial domain
Spatial domain
Mask/Filter
Image Pixels Manipulation
Spatial domain
Some basic intensity transformation functions
Some basic intensity transformation functions
Phép biến đổi âm bản- Image Negatives
   Phép biến đổi âm bản- Image Negatives
Used for enhancing white or gray details embedded in
dark regions, especially when the black areas are dominant in size
  Phép biến đổi âm bản- Image Negatives
                  (a)                Negative image of (a)
Implementation Tips
1. You can write your own code since it is straightforward
2. Or you can use the routine imcomplement
3. Or you can use the routine imadjust
Phép biến đổi âm bản- Image Negatives
%This script shows how to generate a negative image for
a given image
im = imread('hand-xray.jpg');
im = rgb2gray(im);
imNeg = 255 - im;
figure;
imshow(imNeg,[]);
%or, you can use the matlab routine imcomplement
imNeg = imcomplement(im);
figure;
imshow(imNeg,[]);
%or, you can use the matlab routine imadjust
imNeg = imadjust(im,[0,1],[1,0]);
figure;
imshow(imNeg,[]);
     Phép biến đổi âm bản- Image Negatives
Results
      Input Images (a)          Negative Images of (a)
Phép biến đổi âm bản- Image Negatives
Phép biến đổi âm bản- Image Negatives
      Thresholding
Thresholding transformations are particularly useful f
or segmentation in which we want to isolate an object
of interest from a background
 Implementation Tips
 1. You can write your own code since it is straightforward
 2. Or you can use the routine im2bw
Thresholding
                     close all
                     clear all
                     im = imread('hand-xray.jpg');
                     im = rgb2gray(im);
                     figure;
                     imshow(im,[]);
                     %you can use the matlab routine im2bw
                     imNeg = im2bw(im, 0.1);
                     figure;
                     imshow(imNeg,[]);
  Input Images (a)        Thresholding result of (a)
Log Transformations – Phép biến đổi Log
Log Transformations – Phép biến đổi Log
Phép biến đổi Log ngược
Log Transformations – Phép biến đổi Log
Log Transformations – Phép biến đổi Log
Log Transformations – Phép biến đổi Log
Log Transformations – Phép biến đổi Log
close all
clear all
im =imread(‘lena.jpg');
Figure; imshow(im)
% im = rgb2gray(im);
imfft = abs(fft2(im));
imfft = fftshift(imfft);
figure;
imshow(imfft,[]);
imfftlog = log10(1+imfft);
figure;
imshow(imfftlog,[]);
              (a)                     (b)                        (c)
(a)original image; (b) Fourier magnitude of (a) in linear scale; (c) Fourier magnitude
of (a) shown in log scale
Power‐Law (Gamma) Transformations
Power‐Law (Gamma) Transformations
Power‐Law (Gamma) Transformations
   Power‐Law (Gamma) Transformations
Implementation Tips
1. You can write your own code since it is straightforward
2. Or you can use the routine imadjust
           im =imread('citylandscape.tif');
           imEnhanced = imadjust(im,[0,1],[0,1],4.0);
           figure;
           subplot(1,2,1);
           imshow(im,[]);
           title('original input');
           subplot(1,2,2);
           imshow(imEnhanced,[]);
           title('power-law enhanced output');
     Power‐Law (Gamma) Transformations
Power law
transformations are
useful for general‐
purpose contrast
manipulation
Power‐Law (Gamma) Transformations
Another Contrast Stretching Function
   Another Contrast Stretching Function
Implementation in Matlab
       %This script shows how to perform contrast
       stretching for a a given image
       im = imread('boneXRay.tif');
       im = im2single(im);
       m = 0.2;
       E = 0.9;
       csResult = constrastStrechForAnImage(im, m, E);
       figure;
       subplot(1,2,1); imshow(im,[]);
       title('original input');
       subplot(1,2,2); imshow(csResult,[]);
       title('constrast stretched result');
      function result = constrastStrechForAnImage(im, m, E)
      result = 1./(1+(m./im).^E);
Another Contrast Stretching Function- An Example
  Piece‐wise Linear Transformations
❖ Giãn độ tương phản
              Giãn độ tương phản
❑ Phép biến đổi tuyến tính từng khúc
Giãn độ tương phản
Giãn độ tương phản
Giãn độ tương phản
Giãn độ tương phản
Giãn độ tương phản
 Intensity level slicing - Làm mỏng mức xám
❑ Trong thực tế, chiếu sáng cao trong một giải đặc trưng các
  cấp xám đối với một ảnh là việc thường xảy ra
Intensity level slicing - Làm mỏng mức xám
Intensity level slicing - Làm mỏng mức xám
Intensity level slicing - Làm mỏng mức xám
Implementation in Matlab
close all
clear all
im = double(imread('kidney.bmp'));
highLevel = 200;
intervalMask = im > 60 & im < 80;
resultIm = im .* (1-intervalMask) + intervalMask * highLevel;
figure;
subplot(1,2,1); imshow(uint8(im));
title('original input');
subplot(1,2,2); imshow(uint8(resultIm));
title('intensity slicing output');
Intensity level slicing - Làm mỏng mức xám
Intensity level slicing - Làm mỏng mức xám
Bit‐plane slicing- Làm mỏng mứcmặt phẳng Bit
Bit‐plane slicing- Example
                           Implementation in Matlab
im = imread('HUST.jpg');
im= rgb2gray(im);
imshow(im)
[rows, cols] = size(im);
bitPlanes = zeros(rows, cols, 8); %since the image is a 8-bit gray
image, there are 8 bit-planes
           for shiftIndex = 0:7
               bitShiftedIm = bitshift(im, -shiftIndex);
               bitPlane = mod(bitShiftedIm, 2);
               figure;
               imshow(bitPlane,[]);
               bitPlanes(:,:,shiftIndex+1) = bitPlane;
           end
 %reconstruction based on bitplane 8,7,and 6
reconstructedImage1 = 128 * bitPlanes(:,:,8) + 64 * bitPlanes(:,:,7) +
32 * bitPlanes(:,:,6);
figure;
imshow(reconstructedImage1,[]);
imwrite(uint8(reconstructedImage1),'reconstructed1.bmp');
 %reconstruction based on bitplane 8,7,6,and 5
reconstructedImage2 = 128 * bitPlanes(:,:,8) + 64 * bitPlanes(:,:,7) +
32 * bitPlanes(:,:,6) + 16 * bitPlanes(:,:,5);
figure;
imshow(reconstructedImage2,[]);
imwrite(uint8(reconstructedImage2),'reconstructed2.bmp');
Bit‐plane slicing- Example
                Image of our university
Bit‐plane slicing- Example
                             bp0   bp1
             bp2             bp3   bp4
             bp5             bp6   bp7
 Bit‐plane slicing- Example
         Original image                 reconstruction by highest 3 bitplanes
reconstruction by highest 4 bitplanes    reconstruction by highest 5 bitplanes
Introduction to Histogram (Lược đồ xám)
   Introduction to Histogram (Lược đồ xám)
Ví dụ: Tính lược đồ xám của ảnh I
                                Biểu diễn lược đồ xám của ảnh I
Lập bảng
Introduction to Histogram
Introduction to Histogram
Introduction to Histogram
         Histogram of given image
                   Introduction to Histogram
Implementation in Matlab
close all
clear all;
im = imread(‘lena.jpg’);
%im= rgb2gray(im);
imwrite(uint8(im),'truong.bmp');
imshow(im)
f=imread('truong.bmp');
h=imhist(f);
imhist(f);
% axis([0 255 min(h) max(h)]);
axis([0 255 min(h) 5e4]);
                           Histogram of given image
                Introduction to Histogram
Chuẩn hóa lược đồ xám
                Introduction to Histogram
Xử lý lược đồ xám
Introduction to Histogram
Introduction to Histogram
Introduction to Histogram
        h(k) or p(k)
                            k
                    Introduction to Histogram
                                                Ảnh tối
close all
clear all;
f=imread(‘I1.jpg');
figure(1)
imshow(f)
h=imhist(f);
figure(2)
imhist(f);
axis([0 255 min(h) max(h)]);
Introduction to Histogram
                        Ảnh sáng
Introduction to Histogram
Introduction to Histogram
 Properties of the Histogram
Histogram h(x) does not depend on the locations of
image pixels. Thus, it is impossible to reproduce image
f from its histogram.
Properties of the Histogram