Digital Image Processing Laboratory: Image Filtering ...
Purdue University: Digital Image Processing Laboratories
1
Digital Image Processing Laboratory:
Image Filtering
January 26, 2021
Introduction
In this laboratory, you will filter full color images using both FIR and IIR filters, and you
also will learn to use Python to read, show, and write your images.
In this laboratory assignment, the filter algorithms should be implemented in the C
programming language, unless otherwise stated. Low level programming languages are necessary for implementing many complex image processing operations, so one objective of this
laboratory is to give you some experience in using C to solve image processing problems.
Simple example programs are provided, so you should be able to write the required programs
even if you have very little previous experience with C.
When processing images on a computer, there are usually special cases that must be properly handled. In particular, all filters will be implemented using free boundary conditions
along edges, and pixel values will be clipped to a range of [0, 255].
? Free boundary conditions - In order to understand a free boundary condition, consider
an M ¡Á N image denoted by img(i, j) where 0 ¡Ü i < M and 0 ¡Ü j < N . Some filtering
operations require that you index outside of this valid range. Pixels indexed outside
this range should be considered equal to zero.
? Clipping - Image processing operations will sometimes cause a pixel to exceed the value
255 or go below the value 0. In these cases, you should clip the pixel¡¯s value before
displaying or exporting the image.
?
?
?
0
if x(m, n) < 0
if x(m, n) > 255
y(m, n) = 255
?
?
x(m, n) if 0 ¡Ü x(m, n) ¡Ü 255
Questions or comments concerning this laboratory should be directed to Prof. Charles A. Bouman,
School of Electrical and Computer Engineering, Purdue University, West Lafayette IN 47907; (765) 4940340; bouman@ecn.purdue.edu
Purdue University: Digital Image Processing Laboratories
1
2
C Programing
An important goal of these laboratories is for you to learn good C programming skills. You
do not need much prior experience in C programming, because the laboratories will lead you
through the use of the language with examples and program templates. However, to learn
good C programming skills, you should strictly follow the following set of rules at all times.
? Use strict ANSI C constructs - All C compilers allow for enforcement of strict
ANSI C. You should use these options at all times. With the gcc compiler under the
Linux operating system, the compiler flags are
gcc -ansi -Wall -pedantic
These flag settings will insure that you receive warnings for any poor programming
constructs in your code.
? Never use global variables - Global variables should never be used. There are
exceptions to this rule, but you will never face a situation where they are truly needed.
Global variable will lead to ¡°spaghetti code¡±, that can not be understood or debugged.
? Fix all compiler warnings - Any warning from the compiler means that you have an
error in you program or are using poor programming style. Either problem is serious
and should be corrected. Typically, warnings are generated when variables are not
properly retyped. The only exception to this rule is when you dynamically allocate
memory. In this case, you may receive a warning about the byte location.
? Use prototypes for all subroutines - Every subroutine you write should have a prototype that defines its argument types. This prototype should generally be contained
in a single header file with a name such as defs.h.
Purdue University: Digital Image Processing Laboratories
2
3
Displaying and Exporting Images in Python
Most of the lab exercises in this class will require you to produce one or more output images.
These will need to be incorporated into your pdf report. Since many exercises will use
Python, we describe here some basic I/O and display commands in the Python environment.
? Setup Conda Environment - It is recommended that you create a conda environment for this course using the following procedure:
1. Install Anaconda through its website.
2. An ASCII file named ¡°environment.yml¡± is provided that can be used to configure
your Anaconda environment. The file, shown below, installs the packages called
¡°numpy¡±, ¡°matplotlib¡±, and ¡°pillow¡± that will be used in the class.
name : ECE637
dependencies :
? numpy
? matplotlib
? pillow
3. Create the conda environment by running the following command with the file
¡°environment.yml¡± in your working directory.
conda env c r e a t e ?f environment . yml
4. Activate conda environment with the following command.
conda a c t i v a t e ECE637
? Reading Images - You can read an image file, img.tif, into python using pillow using
the following commands
from PIL import Image
im = Image . open ( ¡¯ img . t i f ¡¯ )
This will produce an image matrix x of data type uint8.
? Displaying Images - You can display the image array x with the following command,
im . show ( )
? Transfer Image to numpy array - You can transfer an image object to a numpy
array using the following commands,
import numpy as np
x = np . a r r a y ( im )
Purdue University: Digital Image Processing Laboratories
4
? Writing Images - When producing a lab report document, you should strive to
present the best representation of your output images. Therefore it is best to export
your images to a lossless file format, such as TIFF or BMP, which can then be imported
into your lab report document. You can write the image array x to a file using the save
function:
img out = Image . f r o m a r r a y ( x )
img out . s a v e ( ¡¯ img out . t i f ¡¯ )
Note that if x is of type uint8, the imwrite function assumes a dynamic range of [0,255],
and will clip any values outside that range. If x is of type double, then imwrite assumes
a dynamic range of [0,1], and will linearly scale to the range [0,255], clipping values
outside that range, before writing out the image to a file. To convert the image to type
uint8 before writing, you can use
img out = Image . f r o m a r r a y ( x . a s t y p e ( np . u i n t 8 ) )
img out . s a v e ( ¡¯ img out . t i f ¡¯ )
In most of the following exercises, your C routines will output TIFF files which can be
imported into your lab document. Your lab document should be submitted in pdf (portable
document format), but it can be prepared using an application such as Latex or MS Word.
When you prepare your lab document, you may need to convert the image to an intermediate
format such as jpeg . If you do this, try to set the image quality parameters to the best
possible setting in order to preserve image detail and quality.
For your own viewing, you may display the output images using Python as described
above, or using any other standard image viewing software. Regardless, you are encouraged
to experiment with the effect of each of the above commands using one of the images provided
on the lab web page.
Purdue University: Digital Image Processing Laboratories
3
5
FIR Low Pass Filter
In this problem, you will analyze and implement a simple low pass filter given by the 9 ¡Á 9
point spread function
(
h(m, n) =
1/81 for |m| ¡Ü 4 and |n| ¡Ü 4
0
otherwise
.
1. Calculate an analytical expression for H(ej? , ej¦Í ), the DSFT of h(m, n), and use
Python¡¯s matplotlib to plot the magnitude of the frequency response |H(ej? , ej¦Í )|.
Make sure to label the axes properly and plot on over the region [?¦Ð, ¦Ð] ¡Á [?¦Ð, ¦Ð].
2. Download the bundle C-code.zip containing the C source code for reading and writing
tagged image file format (TIFF) images. Compile the application Example using an
ANSI C compiler.
3. Run the program Example on the image img03.tif by using the command
Example img03.tif
This will produce the gray scale image green.tif, which is derived from the green component of img03.tif.
4. Modify the program Example so that it filters the red, green and blue components of
img03.tif with the filter h(m, n) and generates a full color output image.
Warning: Make sure to rename the directory containing your modified program so
that it can not be overwritten with the original C-code program directory.
Note: In the example code provided, noise is added to the image before writing it
out. This is for illustration only¨Cyou are not asked to add noise to your image in this
exercise.
5. Include the filtered image in your report.
Section 3 Report:
Hand in:
1. A derivation of the analytical expression for H(ej? , ej¦Í ).
2. A plot of |H(ej? , ej¦Í )|.
3. The color image in img03.tif.
4. The filtered color image.
5. A listing of your C code.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- binglongfeng e1001928 humanoidrobotnaoplaying
- school of computing national university of singapore cs
- tkinter ucv
- interfata in python folosind pyqt5 ucv
- image handling and processing with python
- digital image processing laboratory image filtering
- tutorial for the lecture applied machine learning
- tp traitement d images noir et blanc avec numpy
- tp 5 traitement d images avec numpy sfr
- implementing data augmentation
Related searches
- filtering through crossword clue
- matlab image processing tutorial
- matlab image processing pdf
- matlab image processing examples
- basic image processing matlab
- image processing in matlab
- image processing projects using matlab
- matlab digital image processing
- digital image processing matlab pdf
- digital image processing matlab gonzalez
- digital image processing gonzalez download
- gonzalez image processing pdf download