SlideShare a Scribd company logo
1 of 20
Download to read offline
NATIONAL CHENG KUNG UNIVERSITY
Inst. of Manufacturing Information & Systems
DIGITAL IMAGE PROCESSING AND SOFTWARE
IMPLEMENTATION
HOMEWORK 1
Professor name: Chen, Shang-Liang
Student name: Nguyen Van Thanh
Student ID: P96007019
Class: P9-009 Image Processing and Software Implementation
Time: [4] 2  4
1
Table of Contents
PROBLEM................................................................................................................................................................. 2
SOLUTION................................................................................................................................................................ 3
3.2.1 Negative transformation ............................................................................................................................ 3
3.2.2 Log transformation..................................................................................................................................... 3
3.2.3 Power-law transformation ......................................................................................................................... 4
3.2.4 Piecewise-linear transformation ................................................................................................................ 7
3.3.1 Histogram equalization.............................................................................................................................10
3.4.2 Subtraction ...............................................................................................................................................12
3.6.1 Smoothing Linear Filters...........................................................................................................................14
3.6.2 Order-Statistics Filters..............................................................................................................................16
3.7.2 The Laplacian............................................................................................................................................17
3.7.3 The Gradient.............................................................................................................................................19
2
PROBLEM
影像處理與軟體實現[HW1]
課程碼:P953300 授課教授:陳響亮 教授 助教:陳怡瑄 日期:2011/03/10
題目:請以C# 撰寫一程式,可讀入一影像檔,並可執行以下之影像
空間強化功能。
a. 每一程式需設計一適當之人機操作介面。
b. 每一功能請以不同方法分開撰寫,各項參數需讓使用者自行輸入。
c. 以C# 撰寫時,可直接呼叫Matlab 現有函式,但呼叫多寡,將列為評分考量。
(呼叫越少,分數越高)
一、 基本灰階轉換
1. 影像負片轉換
2. Log轉換
3. 乘冪律轉換
4. 逐段線性函數轉換
二、 直方圖處理
1. 直方圖等化處理
2. 直方圖匹配處理
三、 使用算術/邏輯運算做增強
1. 影像相減增強
2. 影像平均增強
四、 平滑空間濾波器
1. 平滑線性濾波器
2. 排序統計濾波器
五、 銳化空間濾波器
1. 拉普拉斯銳化空間濾波器
2. 梯度銳化空間濾波器
3
SOLUTION
Using Matlab for solving the problem
3.2.1 Negative transformation
Given an image (input image) with gray level in the interval [0, L-1], the negative of that
image is obtained by using the expression: s = (L – 1) – r,
Where r is the gray level of the input image, and s is the gray level of the output.
In Matlab, we use the commands,
>> f=imread('Fig3.04(a).jpg');
g = imcomplement(f);
imshow(f), figure, imshow(g)
In/output image Out/in image
3.2.2 Log transformation
The Logarithm transformations are implemented using the expression:
s = c*log (1+r).
In this case, c = 1. The commands,
>> f=imread('Fig3.05(a).jpg');
g=im2uint8 (mat2gray (log (1+double (f))));
imshow(f), figure, imshow(g)
4
In/output image Out/in image
3.2.3 Power-law transformation
Power-law transformations have the basic form,
s = c*r. ^, where c and  are positive constants.
The commands,
>> f = imread ('Fig3.08(a).jpg');
f = im2double (f);
[m n]=size (f);
c = 1;
gama = input('gama value = ');
for i=1:m
for j=1:n
g(i,j)=c*(f(i,j)^gama);
end
end;
imshow(f),figure, imshow(g);
With  = 0.6, 0.4 and 0.3 respectively, we can get three images respectively, as shown in the
following figure,
5
a b
c d
(a) The original image. (b) – (d) result of applying the power -
law transformation with  = 0.6, 0.4 and 0.3 respectively
6
a b
c d
(a) The original image. (b) – (d) result of applying the power -
law transformation with  = 3, 4 and 5 respectively
7
3.2.4 Piecewise-linear transformation
Contrast stretching
The commands,
% function contrast stretching;
>> r1 = 100; s1 = 40;
r2 = 141; s2 = 216;
a = (s1/r1);
b = ((s2-s1)/ (r2-r1));
c = ((255-s2)/ (255-r2));
k = 0:r1;
y1 = a*k;
plot (k,y1); hold on;
k = r1: r2;
y2 = b*(k - r1) + a*r1;
plot (k,y2);
k = r2+1:255;
y3 = c*(k-r2) + b*(r2-r1)+a*r1;
plot (k,y3);
xlim([0 255]);
ylim([0 255]);
xlabel('input gray level, r');
ylabel('outphut gray level, s');
title('Form of transformation');
hold on; figure;
f = imread('Fig3.10(b).jpg');
[m, n] = size (f);
for i = 1:m
for j = 1:n
if((f(i,j)>=0) & (f(i,j)<=r1))
g(i,j) = a*f(i,j);
else
if((f(i,j)>r1) & (f(i,j)<=r2))
g(i,j) = ((b*(f(i,j)-r1)+(a*r1)));
else
if((f(i,j)>r2) & (f(i,j)<=255))
g(i,j) = ((c*(f(i,j)-r2)+(b*(r2-r1)+(a*r1))));
end
end
end
end
end
imshow(f), figure, imshow(g);
% function thresholding
>> f = imread('Fig3.10(b).jpg');
[m, n] = size(f);
for i = 1:m
for j = 1:n
if((f(i,j)>=0) & (f(i,j)<128))
8
g(i,j) = 0;
else
g(i,j) = 255;
end
end
end
imshow(f), figure, imshow(g);
(a) Form of contrast stretching transformation function.
(b) A low-contrast image. (c) Result of contrast stretching. (d)
Result of thresholding
a b
c d
9
(a) An 8-bit image. (b) – (f) The 8 bit plane
a b c
d e f
10
3.3.1 Histogram equalization
The transformation function of histogram equalization is
( ) ∑ ( ) ∑
k = 0, 1, …, L – 1.
% Histogram;
f1 = imread('Fig3.15(a)1top.jpg');
f2 = imread('Fig3.15(a)2.jpg');
f3 = imread('Fig3.15(a)3.jpg');
f4 = imread('Fig3.15(a)4.jpg');
f = input('image: ');
imhist(f), figure;
g = histeq(f, 256);
imshow(g), figure, imhist(g);
a b c
Fig. 3.17 Transformation functions (1) through (4) were obtained from the
images in Fig. 3.17 (a), using histogram equalization
11
a b
Fig. 3.15 Four
basic image
types: dark,
light, low
contrast, high
contrast, and
their
corresponding
histograms
12
a b c
Fig. 3.17 (a) Image from Fig. 3.15. (b) Results of histogram equalization. (c)
Corresponding histograms.
13
3.4.2 Subtraction
The difference between tow images f (x, y) and h (x, y), expressed as
g (x, y) = f (x, y) – h (x, y),
The commands,
f1 = imread('Fig3.28.a.jpg');
f2 = imread('Fig3.28.b.jpg');
f3 = imsubtract(f1,f2);
f4 = histeq(f3,256);
imshow(f3), figure, imshow(f4);
a b
c d
Fig. 3.17 (a) The first image. (b) The second image. (c) Difference between (a) and
(b). (d) Histogram – equalized difference image.
14
3.6.1 Smoothing Linear Filters
The commands,
f = imread('Fig3.35(a).jpg');
w3 = 1/ (3. ^2)*ones (3);
g3 = imfilter (f, w3, 'conv', 'replicate', 'same');
w5 = 1/ (5. ^2)*ones (5);
g5 = imfilter (f, w5, 'conv', 'replicate', 'same');
w9 = 1/ (9. ^2)*ones (9);
g9 = imfilter (f, w9, 'conv', 'replicate', 'same');
w15 = 1/ (15. ^2)*ones (15);
g15 = imfilter (f, w15, 'conv', 'replicate', 'same');
w35 = 1/ (35. ^2)*ones (35);
g35 = imfilter(f, w35, 'conv', 'replicate', 'same');
imshow (g3), figure, imshow (g5), figure, imshow (g9), figure, imshow
(g15), figure, imshow (g35), figure;
h = imread ('Fig3.36(a).jpg');
h15 = imfilter (h, w15, 'conv', 'replicate', 'same');
[m, n] = size (h15);
for i = 1:m
for j = 1:n
if ((h15 (i,j)>=0) & (h15 (i,j)<128))
g (i,j) = 0;
else
g(i,j) = 255;
end
end
end
imshow(h15), figure, imshow(g);
15
Fig. 3.35 (a) Original image, of size 500 x 500 pixels. (b) – (f) Result of
smoothing with square averaging filter masks of size n = 3, 5, 9, 15,
and 35 respectively.
a b
c d
e f
16
3.6.2 Order-Statistics Filters
The commands,
>> f = imread('Fig3.37(a).jpg');
w3 = 1/(3.^2)*ones(3);
g3 = imfilter(f, w3, 'conv', 'replicate', 'same');
g = medfilt2(g3);
imshow(g3), figure, imshow(g);
a b c
Fig. 3.36 (a) Original image. (b) Image processed by a 15 x 15 averaging mask.
(c) Result of thresholding (b)
Fig. 3.37 (a) X – ray image of circuit board corrupted by salt – and –
pepper noise. (b) Noise reduction with a 3 x 3 averaging mask. (c)
Noise reduction with a 3 x 3 median filter
a b c
17
3.7.2 The Laplacian
The Laplacian for image enhancement is as follows:
( )
{
( ) ( )
( ) ( )
( )
The commands,
% Laplacian function
f1 = imread('Fig3.40(a).jpg');
w4 = fspecial('laplacian', 0);
g1 = imfilter(f1, w4, 'replicate');
imshow(g1, [ ]), figure;
f2 = im2double(f1);
g2 = imfilter(f2, w4, 'replicate');
imshow(g2, [ ]), figure;
g3 = imsubtract(f2,g2);
imshow(g3)
Fig. 3.40 (a) Image of
the North Pole
of the moon.
(b) Laplacian
image scaled
for display
purposes. (d)
Image
enhanced by
Eq. (3.7 – 5)
a b
c d
18
% Laplacian simplication
f1 = imread ('Fig3.41(c).jpg');
w5 = [0 -1 0; -1 5 -1; 0 -1 0];
g1 = imfilter (f1, w5, 'replicate');
imshow (g1), figure;
w9 = [-1 -1 -1; -1 9 -1; -1 -1 -1];
g2 = imfilter (f1, w9, 'replicate');
imshow (g2);
0 -1 0
-1 5 -1
0 -1 0
-1 -1 -1
-1 9 -1
-1 -1 -1
a b c
d e
Fig. 3.37 (a) Composite Laplacian mask. (b) A second composite
mask. (c) Scanning electron microscope image. (d) and (e)
Result of filtering with the masks in (a) and (b) respectively.
19
3.7.3 The Gradient
The commands,
>> f1 = imread('Fig3.45(a).jpg');
w = fspecial('sobel');
g1 = imfilter(f1, w, 'replicate');
imshow(g1);
a b Fig. 3.45 (a) Optical image of contact lens (note defects on the
boundary at 4 and 5 o’clock). (b) Sobel gradient

More Related Content

What's hot

Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)asodariyabhavesh
 
Digital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsDigital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsMostafa G. M. Mostafa
 
Lec 07 image enhancement in frequency domain i
Lec 07 image enhancement in frequency domain iLec 07 image enhancement in frequency domain i
Lec 07 image enhancement in frequency domain iAli Hassan
 
Filtering in frequency domain
Filtering in frequency domainFiltering in frequency domain
Filtering in frequency domainGowriLatha1
 
Histogram Processing
Histogram ProcessingHistogram Processing
Histogram ProcessingAmnaakhaan
 
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...Shahbaz Alam
 
Image Enhancement in Spatial Domain
Image Enhancement in Spatial DomainImage Enhancement in Spatial Domain
Image Enhancement in Spatial DomainDEEPASHRI HK
 
5. gray level transformation
5. gray level transformation5. gray level transformation
5. gray level transformationMdFazleRabbi18
 
Image enhancement techniques
Image enhancement techniquesImage enhancement techniques
Image enhancement techniquesSaideep
 
Enhancement in spatial domain
Enhancement in spatial domainEnhancement in spatial domain
Enhancement in spatial domainAshish Kumar
 
Image processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filtersImage processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filtersKuppusamy P
 
Lect 03 - first portion
Lect 03 - first portionLect 03 - first portion
Lect 03 - first portionMoe Moe Myint
 
Filtering an image is to apply a convolution
Filtering an image is to apply a convolutionFiltering an image is to apply a convolution
Filtering an image is to apply a convolutionAbhishek Mukherjee
 
Image Enhancement - Point Processing
Image Enhancement - Point ProcessingImage Enhancement - Point Processing
Image Enhancement - Point ProcessingGayathri31093
 
Intensity Transformation and Spatial filtering
Intensity Transformation and Spatial filteringIntensity Transformation and Spatial filtering
Intensity Transformation and Spatial filteringShajun Nisha
 
Lecture 15 DCT, Walsh and Hadamard Transform
Lecture 15 DCT, Walsh and Hadamard TransformLecture 15 DCT, Walsh and Hadamard Transform
Lecture 15 DCT, Walsh and Hadamard TransformVARUN KUMAR
 

What's hot (20)

Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)Chapter 3 image enhancement (spatial domain)
Chapter 3 image enhancement (spatial domain)
 
Digital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsDigital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image Fundamentals
 
Image compression .
Image compression .Image compression .
Image compression .
 
Lec 07 image enhancement in frequency domain i
Lec 07 image enhancement in frequency domain iLec 07 image enhancement in frequency domain i
Lec 07 image enhancement in frequency domain i
 
Filtering in frequency domain
Filtering in frequency domainFiltering in frequency domain
Filtering in frequency domain
 
Histogram Processing
Histogram ProcessingHistogram Processing
Histogram Processing
 
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
A Comparative Study of Histogram Equalization Based Image Enhancement Techniq...
 
Image Enhancement in Spatial Domain
Image Enhancement in Spatial DomainImage Enhancement in Spatial Domain
Image Enhancement in Spatial Domain
 
5. gray level transformation
5. gray level transformation5. gray level transformation
5. gray level transformation
 
Image enhancement techniques
Image enhancement techniquesImage enhancement techniques
Image enhancement techniques
 
Enhancement in spatial domain
Enhancement in spatial domainEnhancement in spatial domain
Enhancement in spatial domain
 
Morphological operations
Morphological operationsMorphological operations
Morphological operations
 
Image processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filtersImage processing, Noise, Noise Removal filters
Image processing, Noise, Noise Removal filters
 
Lect 03 - first portion
Lect 03 - first portionLect 03 - first portion
Lect 03 - first portion
 
Filtering an image is to apply a convolution
Filtering an image is to apply a convolutionFiltering an image is to apply a convolution
Filtering an image is to apply a convolution
 
image enhancement
 image enhancement image enhancement
image enhancement
 
image compression ppt
image compression pptimage compression ppt
image compression ppt
 
Image Enhancement - Point Processing
Image Enhancement - Point ProcessingImage Enhancement - Point Processing
Image Enhancement - Point Processing
 
Intensity Transformation and Spatial filtering
Intensity Transformation and Spatial filteringIntensity Transformation and Spatial filtering
Intensity Transformation and Spatial filtering
 
Lecture 15 DCT, Walsh and Hadamard Transform
Lecture 15 DCT, Walsh and Hadamard TransformLecture 15 DCT, Walsh and Hadamard Transform
Lecture 15 DCT, Walsh and Hadamard Transform
 

Similar to Digital image processing using matlab: basic transformations, filters and operators

G Intensity transformation and spatial filtering(1).ppt
G Intensity transformation and spatial filtering(1).pptG Intensity transformation and spatial filtering(1).ppt
G Intensity transformation and spatial filtering(1).pptdeekshithadasari26
 
Notes on image processing
Notes on image processingNotes on image processing
Notes on image processingMohammed Kamel
 
Introduction to image contrast and enhancement method
Introduction to image contrast and enhancement methodIntroduction to image contrast and enhancement method
Introduction to image contrast and enhancement methodAbhishekvb
 
Hand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th editionHand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th editionPriSim
 
Computer vision 3 4
Computer vision 3 4Computer vision 3 4
Computer vision 3 4sachinmore76
 
Image Processing Homework 1
Image Processing Homework 1Image Processing Homework 1
Image Processing Homework 1Joshua Smith
 
xy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docx
xy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docxxy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docx
xy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docxericbrooks84875
 
Civil engineering mock test
Civil engineering mock testCivil engineering mock test
Civil engineering mock testakshay015
 
image processing intensity transformation
image processing intensity transformationimage processing intensity transformation
image processing intensity transformationalobaidimki
 
SpatialEnhancement of course CE7491 of NTU
SpatialEnhancement of course CE7491 of NTUSpatialEnhancement of course CE7491 of NTU
SpatialEnhancement of course CE7491 of NTUlyumingzhi
 
Copy Move Forgery Detection Using GLCM Based Statistical Features
Copy Move Forgery Detection Using GLCM Based Statistical Features Copy Move Forgery Detection Using GLCM Based Statistical Features
Copy Move Forgery Detection Using GLCM Based Statistical Features ijcisjournal
 

Similar to Digital image processing using matlab: basic transformations, filters and operators (20)

annotated-chap-3-gw.ppt
annotated-chap-3-gw.pptannotated-chap-3-gw.ppt
annotated-chap-3-gw.ppt
 
Aistats RTD
Aistats RTDAistats RTD
Aistats RTD
 
matlab.docx
matlab.docxmatlab.docx
matlab.docx
 
G Intensity transformation and spatial filtering(1).ppt
G Intensity transformation and spatial filtering(1).pptG Intensity transformation and spatial filtering(1).ppt
G Intensity transformation and spatial filtering(1).ppt
 
Notes on image processing
Notes on image processingNotes on image processing
Notes on image processing
 
DIP_Manual.pdf
DIP_Manual.pdfDIP_Manual.pdf
DIP_Manual.pdf
 
1.funtions (1)
1.funtions (1)1.funtions (1)
1.funtions (1)
 
Lect02.ppt
Lect02.pptLect02.ppt
Lect02.ppt
 
Funções 1
Funções 1Funções 1
Funções 1
 
Introduction to image contrast and enhancement method
Introduction to image contrast and enhancement methodIntroduction to image contrast and enhancement method
Introduction to image contrast and enhancement method
 
Hand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th editionHand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th edition
 
Computer vision 3 4
Computer vision 3 4Computer vision 3 4
Computer vision 3 4
 
Image Processing Homework 1
Image Processing Homework 1Image Processing Homework 1
Image Processing Homework 1
 
DIP_Lecture5.pdf
DIP_Lecture5.pdfDIP_Lecture5.pdf
DIP_Lecture5.pdf
 
DIP_Lecture5.pdf
DIP_Lecture5.pdfDIP_Lecture5.pdf
DIP_Lecture5.pdf
 
xy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docx
xy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docxxy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docx
xy2.5 3.0 3.5-1.0 6 7 81.0 0 1 23.0 -6 -5 .docx
 
Civil engineering mock test
Civil engineering mock testCivil engineering mock test
Civil engineering mock test
 
image processing intensity transformation
image processing intensity transformationimage processing intensity transformation
image processing intensity transformation
 
SpatialEnhancement of course CE7491 of NTU
SpatialEnhancement of course CE7491 of NTUSpatialEnhancement of course CE7491 of NTU
SpatialEnhancement of course CE7491 of NTU
 
Copy Move Forgery Detection Using GLCM Based Statistical Features
Copy Move Forgery Detection Using GLCM Based Statistical Features Copy Move Forgery Detection Using GLCM Based Statistical Features
Copy Move Forgery Detection Using GLCM Based Statistical Features
 

Recently uploaded

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 

Digital image processing using matlab: basic transformations, filters and operators

  • 1. NATIONAL CHENG KUNG UNIVERSITY Inst. of Manufacturing Information & Systems DIGITAL IMAGE PROCESSING AND SOFTWARE IMPLEMENTATION HOMEWORK 1 Professor name: Chen, Shang-Liang Student name: Nguyen Van Thanh Student ID: P96007019 Class: P9-009 Image Processing and Software Implementation Time: [4] 2  4
  • 2. 1 Table of Contents PROBLEM................................................................................................................................................................. 2 SOLUTION................................................................................................................................................................ 3 3.2.1 Negative transformation ............................................................................................................................ 3 3.2.2 Log transformation..................................................................................................................................... 3 3.2.3 Power-law transformation ......................................................................................................................... 4 3.2.4 Piecewise-linear transformation ................................................................................................................ 7 3.3.1 Histogram equalization.............................................................................................................................10 3.4.2 Subtraction ...............................................................................................................................................12 3.6.1 Smoothing Linear Filters...........................................................................................................................14 3.6.2 Order-Statistics Filters..............................................................................................................................16 3.7.2 The Laplacian............................................................................................................................................17 3.7.3 The Gradient.............................................................................................................................................19
  • 3. 2 PROBLEM 影像處理與軟體實現[HW1] 課程碼:P953300 授課教授:陳響亮 教授 助教:陳怡瑄 日期:2011/03/10 題目:請以C# 撰寫一程式,可讀入一影像檔,並可執行以下之影像 空間強化功能。 a. 每一程式需設計一適當之人機操作介面。 b. 每一功能請以不同方法分開撰寫,各項參數需讓使用者自行輸入。 c. 以C# 撰寫時,可直接呼叫Matlab 現有函式,但呼叫多寡,將列為評分考量。 (呼叫越少,分數越高) 一、 基本灰階轉換 1. 影像負片轉換 2. Log轉換 3. 乘冪律轉換 4. 逐段線性函數轉換 二、 直方圖處理 1. 直方圖等化處理 2. 直方圖匹配處理 三、 使用算術/邏輯運算做增強 1. 影像相減增強 2. 影像平均增強 四、 平滑空間濾波器 1. 平滑線性濾波器 2. 排序統計濾波器 五、 銳化空間濾波器 1. 拉普拉斯銳化空間濾波器 2. 梯度銳化空間濾波器
  • 4. 3 SOLUTION Using Matlab for solving the problem 3.2.1 Negative transformation Given an image (input image) with gray level in the interval [0, L-1], the negative of that image is obtained by using the expression: s = (L – 1) – r, Where r is the gray level of the input image, and s is the gray level of the output. In Matlab, we use the commands, >> f=imread('Fig3.04(a).jpg'); g = imcomplement(f); imshow(f), figure, imshow(g) In/output image Out/in image 3.2.2 Log transformation The Logarithm transformations are implemented using the expression: s = c*log (1+r). In this case, c = 1. The commands, >> f=imread('Fig3.05(a).jpg'); g=im2uint8 (mat2gray (log (1+double (f)))); imshow(f), figure, imshow(g)
  • 5. 4 In/output image Out/in image 3.2.3 Power-law transformation Power-law transformations have the basic form, s = c*r. ^, where c and  are positive constants. The commands, >> f = imread ('Fig3.08(a).jpg'); f = im2double (f); [m n]=size (f); c = 1; gama = input('gama value = '); for i=1:m for j=1:n g(i,j)=c*(f(i,j)^gama); end end; imshow(f),figure, imshow(g); With  = 0.6, 0.4 and 0.3 respectively, we can get three images respectively, as shown in the following figure,
  • 6. 5 a b c d (a) The original image. (b) – (d) result of applying the power - law transformation with  = 0.6, 0.4 and 0.3 respectively
  • 7. 6 a b c d (a) The original image. (b) – (d) result of applying the power - law transformation with  = 3, 4 and 5 respectively
  • 8. 7 3.2.4 Piecewise-linear transformation Contrast stretching The commands, % function contrast stretching; >> r1 = 100; s1 = 40; r2 = 141; s2 = 216; a = (s1/r1); b = ((s2-s1)/ (r2-r1)); c = ((255-s2)/ (255-r2)); k = 0:r1; y1 = a*k; plot (k,y1); hold on; k = r1: r2; y2 = b*(k - r1) + a*r1; plot (k,y2); k = r2+1:255; y3 = c*(k-r2) + b*(r2-r1)+a*r1; plot (k,y3); xlim([0 255]); ylim([0 255]); xlabel('input gray level, r'); ylabel('outphut gray level, s'); title('Form of transformation'); hold on; figure; f = imread('Fig3.10(b).jpg'); [m, n] = size (f); for i = 1:m for j = 1:n if((f(i,j)>=0) & (f(i,j)<=r1)) g(i,j) = a*f(i,j); else if((f(i,j)>r1) & (f(i,j)<=r2)) g(i,j) = ((b*(f(i,j)-r1)+(a*r1))); else if((f(i,j)>r2) & (f(i,j)<=255)) g(i,j) = ((c*(f(i,j)-r2)+(b*(r2-r1)+(a*r1)))); end end end end end imshow(f), figure, imshow(g); % function thresholding >> f = imread('Fig3.10(b).jpg'); [m, n] = size(f); for i = 1:m for j = 1:n if((f(i,j)>=0) & (f(i,j)<128))
  • 9. 8 g(i,j) = 0; else g(i,j) = 255; end end end imshow(f), figure, imshow(g); (a) Form of contrast stretching transformation function. (b) A low-contrast image. (c) Result of contrast stretching. (d) Result of thresholding a b c d
  • 10. 9 (a) An 8-bit image. (b) – (f) The 8 bit plane a b c d e f
  • 11. 10 3.3.1 Histogram equalization The transformation function of histogram equalization is ( ) ∑ ( ) ∑ k = 0, 1, …, L – 1. % Histogram; f1 = imread('Fig3.15(a)1top.jpg'); f2 = imread('Fig3.15(a)2.jpg'); f3 = imread('Fig3.15(a)3.jpg'); f4 = imread('Fig3.15(a)4.jpg'); f = input('image: '); imhist(f), figure; g = histeq(f, 256); imshow(g), figure, imhist(g); a b c Fig. 3.17 Transformation functions (1) through (4) were obtained from the images in Fig. 3.17 (a), using histogram equalization
  • 12. 11 a b Fig. 3.15 Four basic image types: dark, light, low contrast, high contrast, and their corresponding histograms
  • 13. 12 a b c Fig. 3.17 (a) Image from Fig. 3.15. (b) Results of histogram equalization. (c) Corresponding histograms.
  • 14. 13 3.4.2 Subtraction The difference between tow images f (x, y) and h (x, y), expressed as g (x, y) = f (x, y) – h (x, y), The commands, f1 = imread('Fig3.28.a.jpg'); f2 = imread('Fig3.28.b.jpg'); f3 = imsubtract(f1,f2); f4 = histeq(f3,256); imshow(f3), figure, imshow(f4); a b c d Fig. 3.17 (a) The first image. (b) The second image. (c) Difference between (a) and (b). (d) Histogram – equalized difference image.
  • 15. 14 3.6.1 Smoothing Linear Filters The commands, f = imread('Fig3.35(a).jpg'); w3 = 1/ (3. ^2)*ones (3); g3 = imfilter (f, w3, 'conv', 'replicate', 'same'); w5 = 1/ (5. ^2)*ones (5); g5 = imfilter (f, w5, 'conv', 'replicate', 'same'); w9 = 1/ (9. ^2)*ones (9); g9 = imfilter (f, w9, 'conv', 'replicate', 'same'); w15 = 1/ (15. ^2)*ones (15); g15 = imfilter (f, w15, 'conv', 'replicate', 'same'); w35 = 1/ (35. ^2)*ones (35); g35 = imfilter(f, w35, 'conv', 'replicate', 'same'); imshow (g3), figure, imshow (g5), figure, imshow (g9), figure, imshow (g15), figure, imshow (g35), figure; h = imread ('Fig3.36(a).jpg'); h15 = imfilter (h, w15, 'conv', 'replicate', 'same'); [m, n] = size (h15); for i = 1:m for j = 1:n if ((h15 (i,j)>=0) & (h15 (i,j)<128)) g (i,j) = 0; else g(i,j) = 255; end end end imshow(h15), figure, imshow(g);
  • 16. 15 Fig. 3.35 (a) Original image, of size 500 x 500 pixels. (b) – (f) Result of smoothing with square averaging filter masks of size n = 3, 5, 9, 15, and 35 respectively. a b c d e f
  • 17. 16 3.6.2 Order-Statistics Filters The commands, >> f = imread('Fig3.37(a).jpg'); w3 = 1/(3.^2)*ones(3); g3 = imfilter(f, w3, 'conv', 'replicate', 'same'); g = medfilt2(g3); imshow(g3), figure, imshow(g); a b c Fig. 3.36 (a) Original image. (b) Image processed by a 15 x 15 averaging mask. (c) Result of thresholding (b) Fig. 3.37 (a) X – ray image of circuit board corrupted by salt – and – pepper noise. (b) Noise reduction with a 3 x 3 averaging mask. (c) Noise reduction with a 3 x 3 median filter a b c
  • 18. 17 3.7.2 The Laplacian The Laplacian for image enhancement is as follows: ( ) { ( ) ( ) ( ) ( ) ( ) The commands, % Laplacian function f1 = imread('Fig3.40(a).jpg'); w4 = fspecial('laplacian', 0); g1 = imfilter(f1, w4, 'replicate'); imshow(g1, [ ]), figure; f2 = im2double(f1); g2 = imfilter(f2, w4, 'replicate'); imshow(g2, [ ]), figure; g3 = imsubtract(f2,g2); imshow(g3) Fig. 3.40 (a) Image of the North Pole of the moon. (b) Laplacian image scaled for display purposes. (d) Image enhanced by Eq. (3.7 – 5) a b c d
  • 19. 18 % Laplacian simplication f1 = imread ('Fig3.41(c).jpg'); w5 = [0 -1 0; -1 5 -1; 0 -1 0]; g1 = imfilter (f1, w5, 'replicate'); imshow (g1), figure; w9 = [-1 -1 -1; -1 9 -1; -1 -1 -1]; g2 = imfilter (f1, w9, 'replicate'); imshow (g2); 0 -1 0 -1 5 -1 0 -1 0 -1 -1 -1 -1 9 -1 -1 -1 -1 a b c d e Fig. 3.37 (a) Composite Laplacian mask. (b) A second composite mask. (c) Scanning electron microscope image. (d) and (e) Result of filtering with the masks in (a) and (b) respectively.
  • 20. 19 3.7.3 The Gradient The commands, >> f1 = imread('Fig3.45(a).jpg'); w = fspecial('sobel'); g1 = imfilter(f1, w, 'replicate'); imshow(g1); a b Fig. 3.45 (a) Optical image of contact lens (note defects on the boundary at 4 and 5 o’clock). (b) Sobel gradient