Lab 1: Elementary image operations

Similar documents
Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Digital image processing

Image Manipulation in MATLAB Due Monday, July 17 at 5:00 PM

CS1114 Section 8: The Fourier Transform March 13th, 2013

EE 301 Signals & Systems I MATLAB Tutorial with Questions

What will we learn? What is a histogram? What is a histogram? Histogram example. Chapter 9 Histogram Processing. Examples of image and its histograms

Assignment 02 (Due: Monday, February 1, 2016)

Lab # 2 - ACS I Part I - DATA COMPRESSION in IMAGE PROCESSING using SVD

APPM 2360 Project 2 Due Nov. 3 at 5:00 PM in D2L

Intensity Transformations and Spatial Filtering

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

How to learn MATLAB? Some predefined variables

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

CHAPTER 6. The Normal Probability Distribution

(Refer Slide Time: 00:03:51)

ELEC6021 Research Methods Matlab Session 2

CPSC 535 Assignment 1: Introduction to Matlab and Octave

2. You are required to enter a password of up to 100 characters. The characters must be lower ASCII, printing characters.

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Computer Vision. Matlab

Introduction to Scientific Computing with Matlab

1.Some Basic Gray Level Transformations

Making Science Graphs and Interpreting Data

SD 575 Image Processing

Image Enhancement. Digital Image Processing, Pratt Chapter 10 (pages ) Part 1: pixel-based operations

Exercise #1. MATLAB Environment + Image Processing Toolbox - Introduction

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Lab 4: Automatical thresholding and simple OCR

CS/NEUR125 Brains, Minds, and Machines. Due: Wednesday, March 8

Chapter 2. MATLAB Fundamentals

How to program with Matlab (PART 1/3)

2D/3D Geometric Transformations and Scene Graphs

Exercises: Instructions and Advice

PART 1 PROGRAMMING WITH MATHLAB

AMS 27L LAB #2 Winter 2009

Chapter - 2 : IMAGE ENHANCEMENT

Digital Image Processing

The Interpolating Polynomial

Matlab Introduction. Scalar Variables and Arithmetic Operators

Practical 4: The Integrate & Fire neuron

Artificial Neural Networks Lab 2 Classical Pattern Recognition

Introduction to MATLAB

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

Inf2B assignment 2. Natural images classification. Hiroshi Shimodaira and Pol Moreno. Submission due: 4pm, Wednesday 30 March 2016.

LAB 1 General MATLAB Information 1

Matlab Practice Sessions

Computer Vision, Laboratory session 1

1 Background and Introduction 2. 2 Assessment 2

7 Control Structures, Logical Statements

Motivation. Gray Levels

MATH 2221A Mathematics Laboratory II

Getting started with MATLAB

Compact Matlab Course

LAB A Translating Data to Binary

Week 7: The normal distribution and sample means

Introduction to MATLAB

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

LAB #2: SAMPLING, SAMPLING DISTRIBUTIONS, AND THE CLT

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

Babu Madhav Institute of Information Technology Years Integrated M.Sc.(IT)(Semester - 7)

Sampling, Aliasing, & Mipmaps

Lecture 5 2D Transformation

MATLAB TUTORIAL WORKSHEET

Intensive Course on Image Processing Matlab project

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

CS4495 Fall 2014 Computer Vision Problem Set 5: Optic Flow

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Week 2: Frequency distributions

EE 216 Experiment 1. MATLAB Structure and Use

EE-3221 MATLAB INTRODUCTION

Introduction to Geographic Information Systems Dr. Arun K Saraf Department of Earth Sciences Indian Institute of Technology, Roorkee

Image Processing. Bilkent University. CS554 Computer Vision Pinar Duygulu

Chapter 3: Intensity Transformations and Spatial Filtering

Name of student. Personal number. Teaching assistant. Optimisation: Stereo correspondences for fundamental matrix estimation.

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

Lecture 4 Image Enhancement in Spatial Domain

Problem Set 4: Streams and Lazy Evaluation

MAT 003 Brian Killough s Instructor Notes Saint Leo University

MATLAB Introductory Course Computer Exercise Session

Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)

IMAGING. Images are stored by capturing the binary data using some electronic devices (SENSORS)

CHAPTER 6 Parametric Spline Curves

Dr Richard Greenaway

EL2310 Scientific Programming

Module 7 VIDEO CODING AND MOTION ESTIMATION

Image Pyramids and Applications

EE168 Lab/Homework #1 Introduction to Digital Image Processing Handout #3

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ORGANIZING THE DATA IN A FREQUENCY TABLE

Learning from Data Introduction to Matlab

Exploration Assignment #1. (Linear Systems)

An Introduction to MATLAB

CS443: Digital Imaging and Multimedia Binary Image Analysis. Spring 2008 Ahmed Elgammal Dept. of Computer Science Rutgers University

Sampling and Reconstruction

Computer Vision I - Basics of Image Processing Part 1

AN INTRODUCTION TO MATLAB

Worksheet 1. Hello Matlab

CME 192: Introduction to Matlab

Homework #2: Introduction to Images Due 4 th Week of Spring 2018 at the start of lab CSE 7, Spring 2018

IMAGE ENHANCEMENT in SPATIAL DOMAIN by Intensity Transformations

Transcription:

CSC, KTH DD2423 Image Analysis and Computer Vision : Lab 1: Elementary image operations The goal of the labs is to gain practice with some of the fundamental techniques in image processing on grey-level images, such as stretching of grey-level values, histogram equalization, sampling and quantization. You will visualize image information in a number of different ways. The lab should be completed by simultaneously study the related sections in the course literature. Examination: For a more efficient examination, prepare script files, such that the results can easily be reproduced. Questions that are explicitly stated in the text, should be answered in written. If results take too much time to compute, you should complement the script files with print outs. Before you begin read the instructions in General laboratory guidelines and study the related sections on grey-level transformation and histogram equalization in the course literature and seminar notes. Reading images: Image formats Images used in this lab are stored in the file system either as 1. Matlab-variables stored using the command save in files under the directory $DSGKHOME/Images-mat 2. function definitions stored in files under the directory $DSGKHOME/Images-m 3. jpeg- and tiff-files under the directory $DSGKHOME/Images If your search paths are correctly set, you can load the files using: 1. Reading Matlab-variables 1 load canoe256 2. Reading images defined as function definitions nallo = nallo256; 3. Reading jpeg- or tiff-images hund1 = double(imread( dog.jpg )); hund2 = double(imread( dog.tiff )); The size of an image can be found with whos or size(variable ) If you want to know the largest and smallest value in an image, you can use: max(max(canoe)) max(canoe(:)) The reason for the double calls is that the function max applied to a matrix returns a vector of maxvalues, one value for each column. The alternative notation Canoe(:) means that the image matrix is regarded as one long column vector. 1 If you are not already familiar with the save-command, read the documentation with help save. From now on it is taken for granted that you use help command to learn more about commands mentioned in these instructions. Image Canoe is stored in a Matlab-variable. To see the defined variables, as well as their sizes, write whos.

2 DD2423 Image Analysis and Computer Vision 1 Displaying images: Colour tables and quantization Matlab has an embedded function image to visualize matrices. Since there are many alternatives to represent colors, the translation from numbers in the matrix to colors on the screen is not fixed. Instead a colour table is used. This colour table is represented by a matrix of three columns, each of which assumes values in the interval [0, 1]. These columns respectively represent the red, green and blue colour components. When the command image(canoe) is called, the value of an image element of the matrix Canoe is used as an index to this table. All floating-point values are rounded to its nearest integer and values outside the table s definition area are rounded to the nearest boundary value. 2 Let us take a look at an image. Load the canoe image following the instructions in the beginning of this lab. In order not to rescale the pixel values to the interval [0.5, 64.5] we simply use a colour table of 256 grey-levels colormap(gray(256)) Question 1: What happens in the image apart from the color change? You may then look at the image with image(canoe) When displaying an image, we want the image elements to be square. This can be achieved with axis equal When working with images of different types, you may need to make sure that the definition area of the colour table corresponds to the interval in which pixel values exist. A Matlab-function showgrey is provided in the function library of the course. If nothing else is stated, this function first computes the largest and smallest values, and then transforms this interval of grey-levels to an interval of a grey-level colour table of 64 levels. You may also explicitly state the length of the colour table, as well as the interval of values to be shown. For more information on this write help showgrey Now try to look at the canoe image with showgrey(canoe) 2 You can determine the length of the current colour table by size(colormap, 1), which returns the number of rows of the matrix. For the display mechanism to work, all values in the matrix to be displayed should be in the interval [0.5, M + 0.5], where M is the length of the colour table. You may show the elements of the colour table by writing colormap. To graphically visualize the colour table, you write plot(colormap), which results in three curves being displayed one for each component. If only one curve is shown, the three curves probably overlap, i.e. the colour table is grey-level. Matlab provides a number of predefined colour tables. You may see all defined tables by writing help graph3d. Please, test some other colour tables using commands such as plot(hsv) and plot(copper(16)). Note that the length of the colour table can be adjusted.

Lab 1: Elementary image operations 3 and change the number of colour levels by varying the display function s second argument in even powers of two in the interval [2, 256] showgrey(canoe, 256). showgrey(canoe, 2) This technique simulates the results of quantizing the image using different numbers of bits. Try to apply the method to the following image phone = phonecalc256; Question 2: Why does a pattern appear in the background of the telephone image? How many grey-levels are needed to get a (subjectively) acceptable result in this case? To exclusively base the display of grey-level images on the largest and smallest values has limitations for images in which only a few image elements have values significantly different from remaining values. If you display such an image, the result may typically be very dark (light) with a few light (dark) areas. Try this by loading the following image vad = whatisthis256; and look at it using the default settings with showgrey(vad) Then from the largest and smallest image values (found as described in the first section) enhance different parts of the grey-level interval by applying different interval limits zmin and zmax to showgrey showgrey(vad, 64, zmin, zmax) Question 3: What does the image show? Why is it difficult to interpret the information in the original image? Look at the image nallo256 with the visualization routine image and colour tables colormap(gray(256)) colormap(cool) colormap(hot)

4 DD2423 Image Analysis and Computer Vision Question 4: Interpret the plots in terms of image content. Which colormap makes the visualization more clear and why? 2 Subsampling The density of image elements used to sample an image affects, in a fundamental way, the information contained in the image. To simulate the effect of this we shall in this exercise take a given image and reduce the resolution at which image information is represented. In Matlab the resolution of an image matrix may e.g. be reduced as follows: function pixels = rawsubsample(inpic) [m, n] = size(inpic); pixels = inpic(1:2:m, 1:2:n); (This function already exists in the function library of the course). To illustrate the effect of this function, first apply it to a simple test image, such as the 9 9-pixel image defined by the following function call: ninepic = indexpic9 rawsubsample(ninepic) Question 5: Repeatedly apply the subsampling operator to some of the images mentioned above. What are the results and your conclusions? As a comparison you should also study the effect of the subsampling operation function pixels = binsubsample(inpic) prefilterrow = [1 2 1]/4; prefilter = prefilterrow * prefilterrow; presmoothpic = filter2(prefilter, inpic); pixels = rawsubsample(presmoothpic); in which the image is filtered with a binomial kernel coefficients 1/4 1/16 1/8 1/16 1/2 (1/4, 1/2, 1/4) = 1/8 1/4 1/8 1/4 1/16 1/8 1/16 before the pure subsampling stage. If you are unaware of the connections between linear filtering and subsampling you should not worry. We will talk about this later on in this course. Here you only

Lab 1: Elementary image operations 5 have to observe the qualitative effects and try to draw conclusions on how and why the methods are different. Apply functions rawsubsample and binsubsample twice to the image phonecalc256. Question 6: Describe in which ways the results are similar and different. Explain the reasons behind the differences. Question 7: What will the results be if you repeatedly apply these two types of operators to a textured image? 3 Grey-level transformations and look-up tables A common way to transform an image is via grey-level transformations. If the purpose is to show an image on screen in Matlab we may perform these using one of these methods 1. apply embedded point-wise operations on image data, 2. transform grey-levels via a look-up table, 3. create a new colour table. 3.1 Point-wise operations In Matlab there is a number of embedded functions within the first category (see e.g. help elfun ) that can easily be applied using the image s variable name as argument: neg1 = - Canoe; showgrey(neg1); neg2 = 255 - Canoe; showgrey(neg2); nallo = nallo256; showgrey(nallo.^(1/3)); showgrey(cos(nallo/10)); Investigate the histograms of the first two image with hist(neg1(:)) hist(neg2(:))

6 DD2423 Image Analysis and Computer Vision Question 8: Related to neg1 and neg2 - why are the histograms different but images similar? Related to nallo - explain how the above transformation functions affect the image histograms. 3.2 Look-up tables For some types of grey-level transformations it may be necessary to represent transformations in terms of look-up tables. Typical examples are transformation that imply extensive computations for each image element, or if a closed expression for a transformation cannot be found. For methods based on look-up tables, the image value of each point is used as an index to a precomputed table. The grey-level transformation is then implemented as a simple look-up of this table. Understandably, this techniques is suitable only for images of integer values or when rounding to integers is a reasonable approximation. 3 In the course library there is a routine compose that performs a composition of an input image inpic and a precomputed table lookuptable: outpic = compose(lookuptable, inpic) Since techniques based on look-up tables will show to be useful for later exercises, that involve stretching of grey-levels and histogram equalization, we will here illustrate how it be used for reverse traversion. For the grey-level interval [0, 255] it is possible to create a look-up table in Matlab using negtransf = (255 : -1 : 0) ; Then the grey-level transformation is computed using neg3 = compose(negtransf, Canoe + 1); Look at this image on screen and compare it to the earlier negation operation by creating a difference image diff = neg3 - neg2; and compute the min- and max-values of this image and/or histogram. Question 9: Why was value 1 added to the image before the look-up? 3 Naturally, it might be possible to combine table look-ups using linear interpolation and thus improve the accuracy.

Lab 1: Elementary image operations 7 3.3 Manipulation of colour tables As we saw in exercise 1, every colour table also works as a grey-level transformation. Thus it is possible to create a contrast reversed image simply by manipulating the colour table. After you have shown the canoe image with image(canoe + 1) you may create an affine function that decreases from the value 1.0 to 0.0 in 256 steps by writing negcolormapcol = linspace(1, 0, 256) ; and use this to set up a colour table with colormap([negcolormapcol negcolormapcol negcolormapcol]) Using a more compact notation, you may let showgrey perform the same kind of operations by writing showgrey(canoe, linspace(1, 0, 256), 0, 255) The two last arguments tell showgrey that the image has values in the interval [0, 255], which means that we no longer have to add a value 1. The obvious drawback of just manipulating the colour table is that the result is not available for further processing or analysis. 4 Stretching of grey-levels Load image nallo256float 4 and dislay it using showgrey. This image has been scanned with high dynamics so that both grey-level variations in the light part of the image as well as in the lower dark areas have been dissolved. Unlike the integer value image nallo256 it has been stored as a floating-point image with a finer quantization of grey-levels. As you can see, the lower part of the image has poor contrast. Compute a histogram of the image and use this as a hint to create a set of different look-up tables, with which to transform the grey-level values. For this image, you may for example begin by stretching each third of the grey-level scale so that the whole dynamics can be viewed on screen. Preferably, use the techniques we covered in previous exercise, based on grey-level specifications to showgrey and/or look-up tables. Visualize with subplot the following properties on screen: the original image the histogram of the original image the transformation function the transformed image the histogram of the transformed image. Question 10: What would be the best transformation function and why? 4 The name Nallo refers to an place in the Kebnekaise area where the image was taken.

8 DD2423 Image Analysis and Computer Vision 5 Logarithmic compression Apply the logarithmic transformation function to nallo256float. T (z) = log(α + z) Question 11: What are the effects of the operation? Explain in which cases it is a good technique. Why do you need the parameter α and how does it affect the result? What is a suitable value for α? 6 Histogram equalization Combine the command hist and the command cumsum to generate a tabulated grey-level transformation eqtransf that equalizes the histogram of the image nallo based on some reasonable discrete transformation equivalent to T (z) = z ζ=0 p(ζ) dζ where p(ζ) is the normalized frequency function (normalized histogram) of the image. 5 Collect all commands you have used and write a Matlab-function function pixels = histeq(image, nacc, verbose) The function must accept any image as input together with the number of accumulators nacc used for histogramming. Naturally, the output is the histogram equalized image. If the argument verbose has a positive value the histograms before and after equalization shall be displayed, as text as well as graphically. If you need advice on how to write functions in Matlab, you may study the source code of for example the function showgrey by typing type showgrey. Display the generated transformation function, create the histogram equalized image, and compute the histograms for this image based on 16, 64 and 256 accumulators. (Remember: store results either as print outs or scripts, such that they can easily be presented.) Question 12: How do you expect the resulting image and histogram will look like? What did you actually get and why is it different? How does the histogram equalized image and its histogram depend on the number of accumulators? 5 Normalization of histograms is preferably done by dividing it with the Matlab-expression prod(size(nallo)), that returns the product of the elements of the vector size(nallo), i.e. the number of image elements. Remember to normalize after the call to cumsum. Why?

Lab 1: Elementary image operations 9 Question 13: How are the results compared to the transformation functions used in previous sections? How will the results be for different kinds of images? What happens if you apply histeq to the similar image nallo256what? (If you do not get similar results, you have probably done something wrong.) Question 14: What happens if you histogram equalize the image phonecalc256? Think of what results to expect, before you perform the actual operation. What kinds of images are suitable for histogram equalization? Question 15: Would it be possible to improve the results by exploiting the fact that nallo256float contains image data stored as floating-point values, unlike nallo256 that contains integers? Make sure you have answered all questions before the examination! Laboration 1 in DD2423 Image Analysis and Computer Vision.................................................................................................... Student s personal number and name (filled in by student).................................................................................................... Approved on (date) Course assistant