+ All Categories
Home > Documents > INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL...

INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL...

Date post: 16-Mar-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
68
Transcript
Page 1: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

IMAGE PROCESSING LABORATORY

INSTRUCTION MANUAL

Department of Interdisciplinary Studies

FACULTY OF ENGINEERING

Tel-Aviv University

Second Edition (August 1994)

Pr. M. Tur, M. Keselbrener and R. Birman

Page 2: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

Contents

0 Introduction : Image Processing Laboratory 50.1 Image Processing History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50.2 Digital Image Processing Equipment . . . . . . . . . . . . . . . . . . . . . . 50.3 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60.4 Our System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60.5 Khoros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

0.5.1 Cantata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1 LAB 1 111.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.2 Preparing Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.3 Login - Logout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.4 The First Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.5 The Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.6 Xcalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.7 Xedit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.8 Cantata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

1.8.1 Cantata Master Form . . . . . . . . . . . . . . . . . . . . . . . . . . . 161.8.2 Creating a Cantata Program . . . . . . . . . . . . . . . . . . . . . . . 17

1.9 Ending a session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191.9.1 Saving and Quitting . . . . . . . . . . . . . . . . . . . . . . . . . . . 191.9.2 Restoring a previous workspace . . . . . . . . . . . . . . . . . . . . . 191.9.3 Saving your Work Space to be Checked . . . . . . . . . . . . . . . . . 19

1.10 Geometrical Manipulation and Subregion . . . . . . . . . . . . . . . . . . . . 201.10.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201.10.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

1

Page 3: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

2 CONTENTS

1.11 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211.12 Appendix A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

1.12.1 Program Subforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231.12.2 Subform Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241.12.3 Master Action Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . 281.12.4 Routines Master Action Button . . . . . . . . . . . . . . . . . . . . . 281.12.5 Run and Reset Master Action Button . . . . . . . . . . . . . . . . . . 281.12.6 Quit Master Action Button . . . . . . . . . . . . . . . . . . . . . . . 29

2 LAB 2: Data Format and Analysis 312.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.2 Preparing Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.3 Image, Type and Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

2.3.1 background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.3.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.3.3 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

2.4 Creating my Own Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.4.1 Sinusoidal Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.4.2 Piece wise Linear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.4.3 Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.4.4 Other Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

2.5 Image analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.5.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.5.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382.5.3 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

2.6 Appendix B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.6.1 Statistics in Khoros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

3 LAB 3 : Algebraic Operations and Image Enhancement 433.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433.2 Preparing Ourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433.3 Algebraic Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

3.3.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443.3.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

3.4 2D spatial Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453.4.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Page 4: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

CONTENTS 3

3.4.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463.4.3 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483.4.4 Extra Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4 LAB 4 : 2D Frequency Domain Filter 494.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494.2 Preparing Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494.3 2D Transform : 2D FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

4.3.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504.3.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

4.4 Frequency Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544.4.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544.4.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574.4.3 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

5 LAB 5 : Image Restoration 615.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615.2 Preparing Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615.3 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635.4 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665.5 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Page 5: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

4 CONTENTS

Page 6: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

Chapter 0

Introduction : Image Processing

Laboratory

0.1 Image Processing History

Interest in digital image processing dates back to the early 1920's when digitized pictures ofworld news events were �rst transmitted by submarine cable between New York and London.Application of digital image processing concepts, however did not become widespread untilthe middle 1960's, when third-generation digital computers began to o�er the speed andstorage capabilities required for practical implementation of image processing algorithms.

Since then, this area has experienced vigorous growth, having been a subject of studyand research in such �elds as engineering, computer science, information science, statistics,physics, chemistry, biology and medicine. The results of these e�orts have established thevalue of image processing techniques in a variety of problems ranging from restoration andenhancement of space-probe pictures to processing of �ngerprints for commercial transac-tions.

0.2 Digital Image Processing Equipment

Digital image processing basically requires a computer upon which to process images. Inaddition, the system must have two pieces of special I/O equipment, an image digitizerand an image display device. Figure 1 shows a complete system for image processing. Thedigital image produced by the digitizer goes into a temporal storage on a suitable device.The computers executes image processing programs from a library, in response to job control

5

Page 7: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

6 CHAPTER 0. INTRODUCTION : IMAGE PROCESSING LABORATORY

Figure 1: A typical digital image processing sequence

unit. As the output image is created, it is written on the output data storage device. Afterprocessing, the image is displayed by a process which is the inverse of the digitization. Thegray level of each pixel is used to determine the brightness of the corresponding point on adisplay screen .

0.3 Objective

The lab session is not a course in system or processing programming. Its objective is to getyou into image processing as soon as possible and acquire an understanding of the purposeand result of selected processes. To get this objective we will introduce you into the worldof KHOROS... But before let us take a look around our system.

0.4 Our System

In this lab we already have digitized some images and we will process them on our system. Allthe images are stored on a magnetic disk and will be pop up to be displayed and processed.The central unit of the system is a Sparc Station 2 (SUN), 28.5 MIPS and 4.2 MFLOPS with

Page 8: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

0.5. KHOROS 7

48Mbyte memory. This work station is connected to the network via the Ethernet Port (see�g. 2). Through the network, we communicate with the CPU under X terminal display.Also existing in the lab is an Indy graphics workstation of Silicon Graphics which enable usto grab images by using it's camera.

And what about software ? We work under UNIX system and use the X11 protocol forwindows. X applications might be called under the TWM window manager. Speci�cally, youwill learn to use the Cantata user interface, which is a small part of the big Image processingPackage : KHOROS

0.5 Khoros

Nowadays, there are many software utilities for image processing and visualization. Most aregeared to speci�c hardware. Here, at the Image Processing Lab of Tel Aviv University, wedecided to use the image processing software KHOROS. It is not hardware dependent, andruns on any Unix machine, both by line commands and by visual programming. It is freelydistributed by the KHOROS Consortium and can be obtained by anyone via anonymousFTP (File Transfer Protocol) to ftp.eece.unm.edu (129.24.24.119).

Khoros is a software environment, specially designed for image processing application bythe Khoros Group, Department of Electrical and Computer Engineering, University of NewMexico, Albuquerque, USA.

Khoros is the greek word for \chorus". A de�nition of a \chorus" is a band of singers ordancers who sing or dance in concert. The \singers or dancers" are the many programs inthe Khoros system; our objective is to provide a group of programs that will, when used inconcert, provide a harmonic environment for the user.

The system integrates multiple user interface modes, code generators, instructional aids,information processing, data visualization to produce a comprehensive image/informationprocessing research tool.

One of the most powerful features of the system is its high level, abstract visual language- CANTATA.

0.5.1 Cantata

CANTATA is a graphically expressed, data ow oriented language which provides a visualprogramming environment within the Khoros system. Data ow is a \naturally visible"approach in which a program is described as a direct graph, where each node represents anoperator (or function) and each direct arc represents a path over which data tokens ow(see

Page 9: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

8 CHAPTER 0. INTRODUCTION : IMAGE PROCESSING LABORATORY

Disc Disc

Cmera

CPU: Sparc 2

UNICORN

CPU: Indy

PEGASUS

x_medusa x_hydra

x_phoenix x_phaun

PC

Ethernet Network

x_minotaur

centaur

pegasusunicorn

Figure 2: Tel Aviv Image Processing System

Page 10: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

0.6. REFERENCES 9

�g. 3). In the data-driven model, execution of a node occurs whenever all its input datatokens are available. The result is placed on the node's output arc(s) and ows on to thenext node for processing.

In CANTATA, the nodes represent processing routines from the Khoros libraries and thetokens represent data to be processed by the nodes. To create a cantata application, the userselects the desired programs (and control structures, as needed), places the correspondingglyph icons on the workspace and interconnects these elements to indicate the ow of pro-cessing from routine to routine. The graphical programming elements of the visual languageconsist of the workspace master form and a ow graph based on connected glyphs.

We suggest you to follow this instruction manual step by step, and learn the variety ofutilities provided by cantata as you go along.

You are encouraged to try new utilities on your own, but please call upon your labinstructor when you are not sure what you are doing. Please remember: Think beforeAction!

0.6 References

� "Fundamentals of Digital Image Processing", Anil K. Jain, Prentice Hall Informationand System Sciences Series, Thomas Kailath, Series Editor.

� "Digital image processing", Kenneth R. Castleman,Prentice Hall

� "Digital Image Processing", Rafael C. Gonzalez and Paul Wintz, Addison-Wesley Pub-lishing Compagny.

� "KHOROS", in our "mythologic" IP lab.

Page 11: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

10 CHAPTER 0. INTRODUCTION : IMAGE PROCESSING LABORATORY

Figure 3: Cantata Work Space Interface

Page 12: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

Chapter 1

LAB 1

1.1 Objectives

� Introduction to the X11 environment windows system.

� Introduction to the user interface Cantata software.

� Starting some simple image processing operations.

1.2 Preparing Yourself

Before you execute a speci�c lab, you need to prepare yourself. To help you, in the beginningof each lab manual, there is a section title Preparing Yourself . Read it before the laband answer the questions. You can already start to read this �rst manual.

1.3 Login - Logout

It is your �rst time in the lab and your �rst login in our system. First of all, you can see thatyou are sitting in front of X "terminals" (named : x medusa, x phaun, x hydra, pegasus,x mintaur or unicorn). Each of them display the list of the computers you can login. Tologin, click twice with the mouse left button on one of the computer names. The XDMlogin prompt will appear on the screen, prompting for login/password, authenticating theuser. You already got your user name from the instructor, please type it and return. Thecomputer asks you for a password. You will set up your password during your �rst login

11

Page 13: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

12 CHAPTER 1. LAB 1

session, so now just press 'enter'. You are now in a session and ready to work. We wantto emphasize the fact that your account is personal. Please change the password using thecommand line "passwd" in the Xterm called unicorn or pegasus. You will be prompted totype the old password, enter it. Then you will be asked for the new password twice. Pleasedon't forget this password and keep it secret. Use the mouse to logout, and wait for theinstructor's order to login again, using now the new password be WELCOME to the newImage processing world of CANTATA.

1.4 The First Screen

Welcome aboard. In front of you is the main screen, composed of di�erent X applicationincluding the Cantata masterform. Look around on the screen.

By default, application windows are surrounded by a \frame" with a blue titlebar atthe top and a special border around the window. The titlebar contains the window's name,a rectangle that is lit when the window is receiving key- board input, and function boxesknown as \titlebuttons" at the left and right edges of the titlebar. On the very top, youcan see the TWM Icon Manager. Windows are iconi�ed by clicking (pressing and then

immediately releasing) the left titlebutton (which looks like a small X ) This is not a partof CANTATA, but you may want to use it. Conversely, windows are deiconi�ed by clickingin the associated icon or entry in the icon manager. Each entry is a key to a useful utility.For your convenience there are icons for a calculator, for a screen editor and the "xterm"the terminal emulator for X. We shall return to these later.

The rest of the screen is a window, framed in blue, containing the programming workspaceof cantata's master form. A window is just like any other screen. Whenever you chose autility from a menu, a new window opens up. Within this window you enter the programparameters. Then you close the window. The main window contains the master form whichconsists of the following components: action buttons (on the left), pull down menus (onthe top) that provide access to subforms, and a blue workspace - in which the graphicalrepresentation of your program appears. Before you do anything (: : : harmful), you mustget familiar with the mouse.

1.5 The Mouse

The mouse is the little grey thing on the side of your keyboard, waiting quietly to be movedaround. It has 3 buttons. Move the mouse over the table kindly . To do some useful exercise,

Page 14: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.6. XCALC 13

move the arrow (with the mouse !) to the calculator and iconfy it, then deiconfy it clipping

in the X in the title blue line, with the left button on the mouse. Now use the calculator :Try clicking 2� 2, using your mouse, on the newly opened calculator window. Did you get4? Well done. Play on and enjoy. Let's suppose you are through with your new toy.

Windows are resized by pressing the left button on the mouse in the right titlebutton(which resembles group of nested squares) , dragging the pointer over edge that is to bemoved, and releasing the pointer when the outline of the window is the desired size. Similarly,windows are moved by pressing in the title or highlight region, dragging a window outlineto the new location, and then releasing when the outline is in the desired position. Justclicking in the title or highlight region raises the window without moving it. Now go back tothe cantata master form screen. You should be comfortable with using the mouse. However,if you still su�er from mouse - phobia, call the lab instructor.

1.6 Xcalc

You already met Xcalc. It is a scienti�c calculator desktop accessory that can emulate aTI-30 or an HP-10C. It will be very useful later, but you can use your own calculator, if youcan't be separated from it !!!

1.7 Xedit

Xedit is a simple text editor for X. Xedit lets you load a �le or create a new �le after it hasstarted up. It provides a window consisting of the following four areas:

� Commands Section : A set of commands that allow you to exit xedit, save the �le, orload a new �le into the edit window.

� Message Window : Displays xedit messages. In addition, this window can be used asa scratch pad.

� Filename Display : Displays the name of the �le currently being edited, and whetherthis �le is Read/Write or Read Only.

� Edit Window : Displays the text of the �le that you are editing or creating.

The characters typed will go to the Text widget (area) that the pointer cursor is currentlyover. If the pointer cursor is not over a text widget then the keypress will have no e�ect on

Page 15: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

14 CHAPTER 1. LAB 1

the application. This also applies to the special key sequences that popup dialog widgets,so typing Control-S in the �lename widget will enable searching in that widget, not the editwidget. Both the message window and the edit window will create a scrollbar if the text todisplay is too large to �t in that window.

COMMANDS

� Quit : Quits the current editing session. If changes have not been saved, xedit displaysa warning message, allowing the user to save the �le.

� Save : Overwrites the �le with the contents of the edit window. The �lename is re-trieved from the Text widget directly to the right of the Load button.

� Load : Loads the �le named in the text widget immediately to the right of the thisbutton and displays it in the Edit window. If the currently displayed �le has beenmodi�ed, a warning message will ask the user to save the changes, or press load again.

Handling text with the Mouse Pointer button one (usually left) is used to save textinto the cut bu�er. Move the cursor to the beginning of the text, and then hold the buttondown while moving the cursor to the end of the region and release the button. The selectedtext is highlighted and saved in the global cut bu�er and turn to the PRIMARY selectionwhen the button is released. Double-clicking selects by words. Triple-clicking selects by lines.Pointer button two (usually middle) `types' (pastes) the text from the PRIMARY selection,if any, otherwise from the cut bu�er, inserting it as keyboard input (where the cursor is). Bycutting and pasting pieces of text without trailing new lines, you can take text from severalplaces in di�erent places in the Xedit window.

Using the Xedit editor Use this very simple text editor, writing, saving, getting a new�le, and copy some part of the text using the mouse. Please, if you have some questions askthe instructor.

Page 16: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.7. XEDIT 15

Table 1.1: The following keystroke combinations are de�ned in xedit:Ctrl-a Beginning Of Line Meta-b Backward WordCtrl-b Backward Character Meta-f Forward WordCtrl-d Delete Next Characte Meta-i Insert FileCtrl-e End Of Line Meta-k Kill To End Of ParagraphCtrl-f Forward Character Meta-q Form ParagraphCtrl-g Multiply Reset Meta-v Previous PageCtrl-h Delete Previous Character Meta-y Insert Current SelectionCtrl-j Newline And Indent Meta-z Scroll One Line DownCtrl-k Kill To End Of Line Meta-d Delete Next WordCtrl-l Redraw Display Meta-D Kill WordCtrl-m Newline Meta-h Delete Previous WordCtrl-n Next Line Meta-H Backward Kill WordCtrl-o Newline And Backup Meta-< Beginning Of FileCtrl-p Previous Line Meta-> End Of FileCtrl-r Search/Replace Backward Meta-] Forward ParagraphCtrl-s Search/Replace Forward Meta-[ Backward ParagraphCtrl-t Transpose CharactersCtrl-u Multiply by 4 Meta-Delete Delete Previous WordCtrl-v Next Page Meta-Shift DeleteKill Previous WordCtrl-w Kill Selection Meta-Backspace Delete Previous WordCtrl-y Unkill Meta-Shift BackspaceKill Previous WordCtrl-z Scroll One Line Up

Page 17: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

16 CHAPTER 1. LAB 1

1.8 Cantata

1.8.1 Cantata Master Form

Overview

The cantata visual programming environment is used to access the programs contained inthe Khoros libraries via a graphical user interface. The master form which appears on thescreen when cantata is executed provides the user with a programming workspace whichconsists of the following components: action buttons, pull-down menus that provide accessto subforms and action selections, subform buttons, and a workspace.

On-Line Documentation

Local, on-line information is provided by clicking on `HELP' buttons. These may be in theform of a single window, or a menu of help options at the top of a window. Clicking on anoption brings up additional documentation on that topic.

Cantata Master Form

The master form is used to initiate the user's top level interaction with cantata. The followingdescription summarizes the di�erent types of buttons located on the master form and theiruse.

Master Form Action Buttons

Action buttons are located along the left side of the master form. These actions provide thebasic operations needed for the creation of and execution of processing ow graphs.

� RUN executes the entire ow graph of glyphs.

� RESET resets all glyphs so that the entire ow graph will be re-executed the next timethe workspace is `RUN'.

� REDRAW refreshes the lines and glyphs of the ow graph.

� ROUTINES gives the user access to Khoros programs by name instead of using themenus along the top of the master form.

� HELP displays master form documentation.

Page 18: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.8. CANTATA 17

� QUIT exit from cantata.

Program Subforms

The subform buttons and subform menu buttons located along the top of the master formare used to access the processing routines currently available in Khoros.

Interaction Subforms

These subform buttons, located on the top-left and left side of the master form, allow theuser to interact with certain features within the cantata environment. They are accessedby clicking the mouse on the desired selection. A complete description is given under thedocumentation for each individual subform menu. They include:

� Edit gives the user access to the various functions of the interactive visual editor ofcantata. Many of the editing functions are the same as those that you would expectin a very simple draw program. In addition, you can save programs (groups of glyphs)and create subprocedures.

� Workspace allows the user to interact with the cantata workspace, selecting visibleattributes, execution modes, saving and restoring cantata programs and subprocedures,setting default directories, saving individual �les, etc.

� Variables is being used to de�ne variables and evaluate expressions.

1.8.2 Creating a Cantata Program

The following is an introductory tutorial designed to acquaint the user with the fundamentalsof using cantata.

� InputClick and hold the mouse key on the `INPUT SOURCES' subform menu button nearthe top middle of the cantata master form. A menu will "drop down" beneath thebutton. Slide the mouse down to highlight `Input Data File' then release the key. Ifyour window manager does not auto place, the outline of a window will appear on thescreen to be positioned with a mouse click. This is the subform for `Input Data Files'.A list of standard input `Images' will be shown in the pane to the right, with `007.xv'selected. Click on the `Glyph' button in the upper left corner of the window. Thesubform will be replaced by the `images' glyph icon.

Page 19: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

18 CHAPTER 1. LAB 1

� OutputRepeat the above procedure with the `OUTPUT' button, selecting the `Display Im-age' subform. The `Display With Update' pane should be shown on the subform."Glyphing" the subform replaces it with the `put update' glyph. The glyphs may berepositioned on the workspace by dragging ( click and hold the mouse on a clear spoton the glyph, move to desired position, and release ).

� ConnectionsClick the mouse �rst on the black output arrow of the `images' glyph, then click onthe black input arrow of the `put update' glyph (or visa versa). A line should appearconnecting the two glyphs. Open the `put update' glyph back to the subform byclicking on the top, middle button on the glyph (representing the subform). The nameof the selected `KHOROS HOME/data/iplabimages/lab1/007.xv' should now appearin the `Input Image' �eld. `Glyph' the subform again.

� ExecutionExecute `put update' by clicking on the "light-switch" run button in the upper rightcorner of the glyph. The glyph will reverse video to indicate that the process is running,and the "light-switch" will invert to the opposite position (becoming a stop button).After a few moments, the image outline will appear on the screen (or will need to beplaced with a mouse click). The displayed image may be removed by either clickingon the inverted "light-switch" or clicking within the image itself.

� Adding to the ProgramClick on the `IMAGE PROCESSING' menu button and select the `Geometric Manip.'subform entry. Note that the `Shrink Image' routine is currently displayed, change itto 'Expand Image' clicking on it. It is displayed with a `Expand Factor' of `2'. Glyphthe subform and connect the output of `images' to the input of `vexpand', and theoutput of `vexpand' to the input of `put update'. Note that this rede�nes the inputto `put update'. We could now run the individual glyphs, as before, but instead, let'sexecute the entire program using the `RUN' action button to the left of the workspace.A larger version of 007.xv should be displayed. Remove the displayed image and trychanging the `Expand Factor' and Rerun the program.

� Deleting GlyphsGlyphs may be removed from the workspace by clicking on the "bomb" kill button inthe upper left corner of the glyph. This is equivalent to clicking the `QUIT' button onthe corresponding subform.

Page 20: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.9. ENDING A SESSION 19

� Exit from cantataYou may leave the cantata visual programming environment by clicking on the `QUIT'button (lower left edge of workspace). Unless the workspace is empty, you will beprompted if you wish to SAVE the contents of the workspace before quitting (or CAN-CEL and return to the workspace).

More information You may �nd more information on Cantata and its features inthe appendix of lab1.

1.9 Ending a session

1.9.1 Saving and Quitting

Since you might be tired, let's learn how to save the cantata workspace, so you can beginnext time where you left o�. Saving the workspace is done by clicking and holding theworkspace menu (left part of the subform menu options line) and releasing the key over

File Utilities . In this subform enter a name in the 'output �lename' �eld and press return .If this was done properly you will be informed that the workspace has been saved, and youwill also be asked if you wish to save all the temporary �les. Reply by selecting NO . When

saving is complete, close the window by clicking close and then quit cantata by clicking

quit on the Master Form Action buttons, on the left bottom of the main workspace.

1.9.2 Restoring a previous workspace

When you enter cantata again, you can recall the saved workspace by repeating the aboveprocess, except that you must choose the saved workspace name in the 'input �lename' �eldand then press return . The workspace will be immediately restored.

1.9.3 Saving your Work Space to be Checked

Like you already saw, your home directory is named : ipl95a or ipl95b...ipl95c etc... Underthis directory you have two subdirectories : work and checkpoint . Under checkpoint appearsubsubdirectories :lab1 ,lab2, lab3 etc... You will be asked to save your work under certainnames, to be checked by your instructor. Please try to save the workspace you have createdinto the ipl95*/checkpoint/lab1 under the following name : tutorial.wksp (the asteric stands

Page 21: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

20 CHAPTER 1. LAB 1

for your account identi�cation letter). Save it, and quit Cantata. Check yourself, runningCantata again and loading your workspace called : tutorial.wksp. If you succeed, go on.

1.10 Geometrical Manipulation and Subregion

1.10.1 Background

This is your �rst image processing lab, and we start with a process that seems to be verysimple : geometrical operations. Geometrical operations change the spatial relationshipsbetween objects within the image. This is a very wide subject within image processing, itincludes many features like, spatial transformation, gray level interpolation, pixel transferetc. In the next section, you will get acquainted with some tools that you may use when youperform several geometrical manipulations.

1.10.2 Tools

It is required to expand or to shrink an image and save the result of the process. Implemen-tation of this task, we already begin our �rst image processing algorithm with cantata.First, repeat the algorithm for displaying an image, using the `put update' option for display.Now click on IMAGE PROCESSING subform menu and slide to

GEOMETRIC MANIPULATION , release the key. The opened subform enables variousgeometric manipulations of an image.

shrink image - reduce the size of the image by skipping pixel, depending on the factor.

expand image - enlarge the size of the image by multiplying each pixel by a factor inboth directions.

Resize - change the length and width of an image.

Rotate - turn the image in any angle.

Transpose - p(x; y) �! p(y; x)

Translate - move the image inside the frame warping it around the edges

Flip - re ect the image right-left or top-bottom.

Page 22: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.11. PROJECT 21

You can choose any of these options, enter the value of the parameters needed in thesubform, and then glyph . Back on the Masterform workspace, connect the newly formedglyph between the `images ' glyph and the display glyph.

Having three connected glyphs on the workspace, your �rst image processing algorithmis ready to run. You can execute the algorithm by clicking each glyph individually in itsturn, or run the entire program, as you did before. Your manipulated image should appear.Notice what happens when you expand the image with a large factor.Try to implement more complicated algorithm involving a series of geometric manipulationsconnected in a row (such as shrinking and expanding of an image). Display the results atvarious points along your series. Have fun! (you may, for example, perform "transpose"using "rotate" and " ip"?)

ROI : Region Of Interest You may perform geometric operations on part of the imageinstead of using the whole image. These operations are categorized under the subregionutilities within cantata. They enable you to examine and extract particular features ofthe original image. This is done using IMAGE PROCESSING �! SUBREGIONS .

Try Extract Subregion and Extract Center . The �rst allows you to extract any size ofsubregion beginning anywhere in the image. The second option extracts a section of a givensize around the center. Look carefully at the parameters in the subform. When you aredone - glyph . Combine this glyph with the previous one i.e. enlarge the subregion using

Expand image , and display it.

Now, you can try another useful tool called Pad Image . This program completes an

image to a new size by �lling the empty lines and columns with a constant value (usuallyzero). Try selecting a subregion from an image and then pad it with zeros, so that the image

returns to its original size. You can use Geometric Manip �! translate to move it backto its original location.As a more complicated exercise try to ip the eye of lenna right-left, and then return it toits original location. If you manage to do that, you are doing all right.

1.11 Project

This is your �rst project in this laboratory. Before giving you some directives about the taskto perform, we want to make clear how to present your di�erent projects during the labs.Prepare a workspace using some already known algorithms. All project workspaces should beexplained very broadly using comments ( we will learn later how to use comment). The �rst

Page 23: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

22 CHAPTER 1. LAB 1

comment will explain the purpose of the algorithm, and the last one need to describe someconclusions about the di�erent algorithms used. Along the glyphs through the workspace,you have to explain your actions and specify your reasons for choosing certain parametersto perform a speci�c function.

In this lab we have learned to perform some geometric transformations on an imageand on parts of it. For this �rst project you are being asked to exercise yourself with thecantata interface, using the already learned functions, to compose a creative image of yourimagination from di�erent existing pictures. Your �nal work with all the comments need tobe saved under the following name: lab1 pro1.wksp.Z under the �ipl95*/checkpoint/ lab1directory.

Comment your Work Space It is very simple. Go to the PROGRAM UTILITIES

entry with the pointer, click on it ,slide to Program Comment , and release the key. Theopened subform allows you to type comments into the window. You can change the title ofthe comment i.e. 'Purpose' or 'Conclusion' and close this window clicking on the Glyphbutton.

Conclusion You have learned to use the Cantata interface using di�erent tools. We hopeyou enjoyed.... The result of lab1 is the two workspaces :tutorial.wksp.Z and lab1 pro1.wksp.Z.save it in ipl95*/checkpoint/lab1 to be checked.

Page 24: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.12. APPENDIX A 23

1.12 Appendix A

1.12.1 Program Subforms

The Khoros processing programs are typically accessed using the subform buttons whichare grouped under general categories in menus across the top of the master form. Eachsubform contains the information for a group of related processing programs available fromthe Khoros libraries. (Alternately, programs may be selected directly by name using the`ROUTINES' action button.)

There are two subform buttons, which when selected give direct access to a subformand there are subform menu buttons, which give you access to a group of subforms via apull-down menu. The default cantata workspace uses all subform menu buttons.

� Subform Buttons: Clicking the mouse on a subform button selects the corresponding

subform which then appears in the workspace window, or alternatively an outline ofthe subform will appear for interactive placement if your window manager does notauto place. The subform guide pane (see below) lists the programs available on thatsubform.

� Subform Menu Buttons:The menu buttons on the top of the master form (for example,`INPUT SOURCES') provide a pull-down menu of related subforms. To use, positionthe mouse cursor on the category of interest, then press and hold the mouse key. Themenu of subforms will "drop down" beneath the button. A speci�c subform is selectedby sliding the mouse down until the desired title is highlighted, then releasing themouse button. The corresponding subform of programs will then appear.

� Guide Panes: The guide pane on the left of the subforms presents the user with achoice of the available programs on that subform. Selecting a program, presents thepane section (to the right) containing information for that speci�c program. Once aprogram has been chosen and its parameters speci�ed, the subform must be "glyphed"so that it may be connected in a program ow graph.

Each subform contains `HELP' which provides additional documentation on subform usage,as well as a general description of the programs on that subform and speci�c help for eachprogram.

Page 25: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

24 CHAPTER 1. LAB 1

1.12.2 Subform Usage

A speci�c program is selected from the general category represented by the subform byclicking on the desired button in the guide pane on the left of the subform. This brings upa corresponding pane to the right of the subform for the setting of appropriate required andoptional parameters for that program. The subform may then be glyphed for use in a owgraph or executed directly using the `Execute' or `Run' button.

Subform Guide Pane The guide pane is the left most portion of a subform. It is wherethe user accesses the individual program and gets `HELP', or `QUIT's the subform.

� Guide ButtonsThe guide buttons are labeled with the speci�c programs that are available on thatsubform. Clicking on a guide button will �ll in the pane section (to the right) withinformation appropriate to that particular program. When a program is selected, itsbutton in the guide pane will be highlighted while the corresponding pane presentsparameters to be set by the user.

� HELPThe `HELP' button brings up an Overview describing the general area of interestwhich that particular subform addresses. In addition, help is provided on how to usethe di�erent parts of the subform. Documentation concerning each individual programaccessed from a subform may be obtained from the HELP button on the pane for thatprogram.

� QUITThe `QUIT' button removes the subform from the screen and may be used whenprograms from that subform are no longer needed. It corresponds to the "kill" buttonon the glyph.

Setting Program Parameters The pane section (located on the right of the subform)is where most actual input of parameter information for a processing program takes place.When a speci�c program is selected from the guide pane, the corresponding pane sectionappears with required and optional parameters which may be entered/changed/selected forthat program.

� Text Selections"Text selections" are provided for entering string, integer, and oat values. Typically

Page 26: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.12. APPENDIX A 25

these appear as narrow rectangular boxes in which the required information is enteredby positioning the mouse cursor on the box and typing in a number. Typing in aspeci�c number is the same as saying that the parameter that you entered will be aconstant. Besides entering constants, variables or expressions can be used. See thedocumentation on the expression parser.

� Live Text Selections"Live" parameters are indicated by a stylized CR arrow that appears to the right ofthe parameter input box. If the `Responsive Execution' mode is turned ON, the re-execution of the ow graph is also initiated by the user entering the required value andthen hitting the carriage return.

� SlidersFor numerical values, optional "sliders" may be used to enter a value between prede-�ned limits. To use, position the mouse cursor on the gray band, hold down the middlebutton and move the mouse horizontally, releasing when at the desired level.

� FilenamesNames for input/output �les may be typed in or, or alternately, selected from a "�lebrowser". Clicking on a �lename prompt will bring up a browser window containing alist of �les in the current directory. A �lename may be selected from the browser byclicking on the desired name. A di�erent directory may be accessed either by clickingon a subdirectory name (or ../ to back up) or by typing it in directly in the space atthe bottom of the browser.

Filenames for intermediate results are typically NOT typed in, but generated by can-tata when the glyphed programs are connected into a program ow graph.

� LogicalsLogical values are distinguished by elliptical buttons (if your X server has shape ex-tensions) which toggle between two alternate choices when clicked on. For example:"Yes/No", "True/False", "On/O�", etc.

� Optional Selections"Optional" parameters are prefaced by a small box. When selected, the box is high-lighted, meaning the parameter value is to be used.

� Toggles and Mutually Exclusive GroupsText selections may be grouped together so that only ONE of the group may be selected

Page 27: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

26 CHAPTER 1. LAB 1

at a time. For "Toggles" one and only one of the listed options must be selected. For"Mutually Exclusives" one of the listed options may be selected or an alternative typedin.

� Action ButtonsFor most situations, it is necessary for the user to enter several text selections beforeinitiating any action. In the gather and execute mode, the user �rst enters all therequired parameters, then clicks the mouse on an "action button" to register the valuesand perform the desired operation. The `Execute' and `Glyph' buttons are actionbuttons in cantata.

Subform Glyph Button The `Glyph' button makes a small icon of the subform whichcan then be used to construct a processing pipeline. The glyphed subform represents onlythe speci�c processing routine that was chosen from the guide pane. In other words, theglyph does not represent the entire subform but only a single program which was accessedby that subform. This is why the glyph is labelled (bottom) with the program name insteadof the subform name (for example `vadd' instead of `arith binary').

Using Cantata to Construct a Visual Program

A glyph is a small icon representing a processing routine, which may be selected from theroutines list or from a subform. A visual program consists of a number of glyphed routinesconnected together in a pipeline or ow graph.

Glyph INPUT/OUTPUT Glyphs contain "input" and "output" connections, repre-sented by buttons located on the left and right sides of the glyph, respectively. Input buttonshave arrows which point INTO the glyph, and output arrows point OUT. If an arrow is dark,then its corresponding input/output is a required parameter for that routine. If the arrowis a lighter color, then it is an optional parameter. Required parameters must always beconnected in the ow graph. The `Check' function via the `Workspace' menu may be usedto check a workspace for any missing required input/output connections.

Glyph Connection The connections between glyphs are made by clicking the mouseon the output button of one glyph and then on the input button of another glyph (orvice versa). Upon a successful connection, a line will be drawn between the two glyphs.Connections can go from one output button to more than one input button if needed.Once a connection has been made between two glyphs, it can be changed by either connecting

Page 28: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.12. APPENDIX A 27

that glyph to a di�erent glyph or by deleting the connection altogether. Clicking on the lineconnecting two glyphs will bring up a form which you may use to delete a connection, savethe �le associated with that connection, or choose the data transport mechanism that youhave used for that connection. `Delete Connection' will remove that connection. `Save Datato File' bring up a text widget in which you can enter the �lename in which to save a copyof the �le associated with that connection. Under these two action buttons will be a listof the available data transport mechanisms. You may click on the desired data transportmechanism, and it will be used to transport the data involved with that connection. Selecting`Cancel' leaves the connection unchanged.

Executing a Glyph The "run" button, a stylized light switch, in the upper rightcorner of the glyph is used to execute the glyphed pane. After a ow graph is constructed,each of the glyphed panes must either be run individually using this button, or the `RUN'action button on the master form may be used to execute the entire ow graph. When theprocess that a glyph represents is executing, its glyph will be displayed in reverse video.This provides animated feedback as to the execution state of the ow graph. In addition,the run button "light switch" on the executing glyph will change from an "OFF switch" toan "ON switch". To stop an individual glyph that is running, click the mouse on the "run"button again and the execution of that routine will be halted.If an error is detected during the execution of a glyph routine, a "frowning face" error buttonwill appear ( ashing) on the glyph. Clicking the mouse on the button will pop up an errormessage window indicating the problem.

Expanding a Glyph to a Subform The center button located on the top of theglyph (with the small picture of a subform) is used to access the subform associated withthat glyph. This is useful when parameters for the glyphed routine need to be changed ora di�erent routine on that subform is needed. When clicked on, the glyph will disappear ifthe workspace attribute `Always Display Glyph' is set to NO, and will be replaced by thesubform. To return to the glyphed form, click on the `Glyph' button of the subform.

Resetting a Control Glyph Control glyphs have an extra "reset" button (top, rightcenter) which may be used to reinitialize loop control glyphs.

Destroying the Glyph The leftmost button on the top of the glyph (bomb with litfuse) is used to "destroy" or quit the glyph. It is equivalent to clicking on the `QUIT' button

Page 29: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

28 CHAPTER 1. LAB 1

on the guide pane of its associated subform. When clicked on, the glyph will be removedfrom the screen. If that glyph has a process running, it will be stopped.

Moving a Glyph Glyphs may be moved by placing the mouse cursor on the glyph,pressing the mouse key and dragging the glyph to the desired position, then releasing thekey.

1.12.3 Master Action Buttons

The action buttons on the master form provide the basic operations needed for the creationof and execution of processing ow graphs.

1.12.4 Routines Master Action Button

The `ROUTINES' action button may be used to select programs(s) by name as a short-cutin accessing program glyphs from the list of Khoros processing routines. Instead of bringingup a subform, choosing a program from that subform, and then glyphing that program, the`ROUTINES' action button allows the user to select the desired program(s) by name andbring them up in the glyphed state directly.When selected, the `ROUTINES' button brings up a window with an alphabetical listingof all of the routines currently available within cantata. The user then selects the desiredprograms(s) by clicking on the name(s) with the mouse. After all desired routines areidenti�ed, click on the `Use' button at the top of the display window. The selected routinesthen come up directly in glyphed state in the order that they were chosen.

1.12.5 Run and Reset Master Action Button

Once glyphs have been selected and connected together in a ow graph, the programs theyrepresent may be executed individually by clicking on the "run" button of each individualglyph, or the entire processing pipeline may be executed using the master action `RUN'button.The `RUN' action button is used to automatically execute an entire workspace ow graph.Because the ow graph may contain several di�erent paths, the scheduler will �nd a correctsequence for executing the glyphs and run them in that order. Once programs have beenexecuted, if changes are made to the ow graph, `RUN' will re-execute only those programsthat are a�ected by the change. Therefore, the entire ow graph does not have to be Rerun.The `RUN' button, during processing, will be labelled `STOP'. While `RUN' is executing it

Page 30: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

1.12. APPENDIX A 29

can be interrupted by clicking on the `RUN/STOP' button again.The execution mode described above is typically referred to as data driven. Cantata isdesigned to support a more interactive execution mode referred to as responsive executionmode. This mode can be set on the `Workspace Attributes' pane. If this mode is set, the`RUN' button operation is di�erent, please see the help for responsive execution mode.The `RESET' button is used to "touch" all glyphs in the workspace so that RUN will re-execute ALL glyphs, whether they have been modi�ed or not. To just reinitialize loops, the`RESET' button on the individual loop control glyphs may be selected.

1.12.6 Quit Master Action Button

The `QUIT' button is used to terminate the cantata editing session. If there are glyphs in theworkspace, you will be prompted if you wish to save the contents of the current workspace.The options are to:

� CANCEL return to the workspace, i.e. do not quit, or

� EXIT not saving anything, or

� SAVE the contents of the workspace.

If `SAVE' is selected, the user will be prompted for a �lename (default is cantata.wksp),then the entire workspace, including intermediate results, will be saved for later use. Savedworkspaces may be restored via the `File Utilities' subform available.

Page 31: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

30 CHAPTER 1. LAB 1

Page 32: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

Chapter 2

LAB 2: Data Format and Analysis

2.1 Objectives

� What's an image, an image format, an image type ?

� Create your own images.

� Acquiring image parameters using image information utilities.

� Image enhancement using histogram modi�cation.

2.2 Preparing Yourself

Answer the following questions. You will need the results during the lab to validate theresults of your lab exercises.

(1) What 's a "Skewness" of an image ? Explain and give a mathematic expression.

(2) What 's a "Kurtosis" of an image ? Explain and give a mathematic expression.

(3) What 's an "Entropy" of an image ? Explain and give a mathematic expression.

(4) What 's a "Contrast" of an image ? Explain and give a mathematic expression.

(5) Explain the "histogram equalization" algorithm and build a numerical example of thetransformation. You will check your example in the lab.(create a 64x64 image)

31

Page 33: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

32 CHAPTER 2. LAB 2: DATA FORMAT AND ANALYSIS

2.3 Image, Type and Format

2.3.1 background

Digital Images and Image Type

Since computers work with numerical data, an image must be converted to numerical formbefore processing. The conversion is called "Digitization". The image is divided into smallregions called "picture elements" or "pixels" for short. At each pixel location, the imagebrightness is sampled and quantized. This step generates an integer at each pixel representingthe brightness of the image at that point, the "gray level" of the pixel for black and whiteimages. Once this has been done for each pixels, the image is represented by a rectangulararray of integers. The gray level of the pixel might be a byte, if one wants to work withgray levels from 0 to 255. If needed, it could also be a oating point, a complex number (inthis case one has to work with two images : the real one and the imaginary one, or to workwith the power of the image). If the image represents a yes or no type of decision, i.e. 0or 1, there is really no need to keep a byte for each pixel, in this case each pixel might berepresented by a single bit. Since the images are usually built from a large number of pixels- as 512x512 - one may want to represent each pixel with the smallest possible type.

Images Format

An image has to be stored within the computer in its digital form. The way the imageappears in the computer depends on the system you work with and each system works witha speci�c FORMAT. If one wishes to transfer images from one system to another, one hasto know exactly the formats of the two systems. All the information about the image andthe way it is recorded appears at the beginning of the image in the HEADER. Usually, theheader is built from 512 bytes, however, in some programs it might be larger. In the header,all the parameters of the image recording are kept. An image is stored in the computeras a binary �le. Each pixel value may be represented by a byte in a RAW FILE or by itsASCII code in an ASCII �le. The two types of �le do not in uence later operations on theimage, it is chosen according to the convenience of each image processing program. Theimage may also be compressed in order to reduce the length of the �le. Once again, thecompression depends only on the program and usually, the user does not need to understandit's operation.

Page 34: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

2.3. IMAGE, TYPE AND FORMAT 33

2.3.2 Tools

Format Tools

One of the di�erences between various formats of images is the header. The header is a listof words, characters and numbers containing information about the image, such as: imagesize, format (byte, ASCII etc.), color look-up tables, comments, etc.

Cantata uses an internal format called VIFF. VIFF uses a 1024 byte header. (For furtherinformation about VIFF refer to the Khoros manual)

Displaying an image of a di�erent format

It is required to display an image stored in a 'cvl' format, for example, 'boy.cvl.' Supposewe do not know the size of the header. However, we can guess the image size would be apower of 2 (as most stored images are). What should we do, in order to �nd the header sizeand display the image correctly?

First, let's �nd out what the actual size of the image is. In order to do so we have toleave Cantata for a while and look at the list of �les in the directory. Don't quit! Usingthe windows, we can open a window and do all our interactions with the operating system(Unix) there. Move the arrow over the TWM Icon Manager , click with the mouse key

in unicorn . A window opens up showing unix command line. Move the arrow into the

window, leave it, and type ls -l $CVL/boy.cvl - which is a unix command for listing the �le

having this name. You can read that the actual size of boy.cvl is 16428 bytes.Remember your calculator utility ? Now it is the time to use it. What do you think the

image size is, knowing it should be a power of two? If you can't guess, calculate the squareroot of 16428. What is the closest power of 2 to the answer? Now you know the image size.The rest is the header. If you did all the calculations correctly, you should have found thatthe header is 44 bytes long.

We can use this information to convert the boy.cvl data �le to VIFF, so it can be handled bythe display programs of Cantata. Close the xterm window by clicking the arrow over thesmall button on the top-left corner of the window. Similarly, close the calculator window.Now return to your previous algorithm for displaying an image. Edit the `images' glyph andselect the boy.cvl image glyph back to the workspace.Click the mouse key on CONVERSIONS and slide to RAW FILE FORMAT . Release

the key. Within the subform, select RAW TO VIFF , which is what you want to do toboy.cvl. Get the arrow to the �eld containing the image number of rows. Delete whatever isthere using the delete key of your keyboard and rewrite 128 using the keyboard. Repeat the

Page 35: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

34 CHAPTER 2. LAB 2: DATA FORMAT AND ANALYSIS

process for the number of columns. We are not �nished yet. Move the arrow to `header o�set'and key in the correct number (44). Don't forget to click on this entry option by clickinginside the small square on the left of the `header o�set'. The square will turn black. When youare done with this subform click glyph . The `raw2vi�' glyph appears on the workspace.Back on the masterform workspace, join the `images' glyph with the `raw2vi�' glyph, andthe outgoing arrow of the `raw2vi�' glyph to the incoming arrow of the `edit-image' glyph.Your algorithm is complete. You can execute each glyph separately or execute the wholealgorithm. Can you see the boy?

Type Tools

Now try to display the spine.xv images. What's happen ? Now click the mouse key on theYES button. Usually, when you know that the image output of the glyph is in a di�erent

representation than the one needed for the input of the next glyph, you must convert thedata using CONVERSION �! data convert subform menu. However, the Cantatavisual data ow system detects such problems and warns you that conversion should beperformed. Now take an image and convert its type to oat and try to display it. Whichvalue did you expect to get when you move around the image with the mouse and get thepixel grey level values in the bottom of the image ? Try di�erent type of transforms and seewhat happens when you display the picture.

Viewing ASCII Files We can see the �le using a new option: OUTPUT �! INFORMATION

�! ASCII File Viewer . Connect the output arrow of 'vhisto' glyph to the input arrow of'xviewer' glyph and execute.You can slide down the �le by moving the arrow to the grey column on the left side of thewindow and clicking the left key of the mouse. Clicking the right key will get you back tothe �le. Do you understand the content of this �le ?

Image Information

Use the Image Utilities to show IMAGE INFO of the image head.xv. You can see thatthe \File data storage type" is oat. This is why it was necessary to convert the image tobyte, before displaying.Notice the other features describing the image such as size.In general Cantata can handle any size of an image, however some processes as �t requirethat the image size will be a power of 2.Look up the IMAGE INFO of other images.

Page 36: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

2.4. CREATING MY OWN IMAGE 35

Summary

VIFF - an internal format for image storage

CONVERSIONS - used to convert one data type to another

IMAGE INFO - displays the information about the image.

header - a series of ASCII bytes containing information about the image, located at the headof image �le before the image itself.

CONVERSION �! RAW FILE FORMAT - converts various �le formats to VIFF.

2.3.3 Project

There are four 4x4 pixels images $LAB2/ima1, $LAB2/ima2, $LAB2/ima3 and $LAB2/ima4.These images are of types - integer, real, complex and raw �le data. You need to determinethe format and data type of each image, and to display it in the byte type. We advice youto use the ascii �le viewer to accomplish this task. Please save this workspace to be checkedin : ipl95*/lab2/lab2 pro1.wksp

2.4 Creating my Own Image

In this section, we shall learn how to create our own simple image, an image which is wellunderstood, and which we can test under various mathematical processes.

We can produce such an image in many ways. One simple method is to use a �le editor(xedit), and using the editor to enter values - for every pixel in the image. This might besimple for very small images, but would be cumbersome for large ones. Use xedit to createyour own image. Create 1) a raw image, 2) an ASCII image, 3) a oat image and 4) acomplex image using xedit.(Create images of dimension: 2x2 or 3x3). Try to display yourdi�erent pictures using the vexpand function.

How the convert function deal with pixel value greater than 255 or less than zero ?Which component of the complex is displayed on the screen ? Answer these questions inyour workspace using the comment utility.

Another method is to write a computer program which generates values for each (x,y)coordinate and writes these values in a �le. In both of the above methods we shall end upwith an ASCII �le of oat (or integer) type, which we can import as a source to a cantataalgorithm. This �le will have to be converted to VIFF using the conversions utilities,mentioned in section 2.3.2.

Page 37: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

36 CHAPTER 2. LAB 2: DATA FORMAT AND ANALYSIS

We might return to this method of image generation later on in this course. In themean time, we want to use a cantata utility which enables us to produce our own image.

Click on the input-source subform menu, and slide to CREATE-DATA(2D) . This routine

enables you to produce various kinds of images, such as sinusoidal functions, piece wiselinear, constant, gaussian etc. It also enables you to add noise to images.

2.4.1 Sinusoidal Image

Select sinusoidal in the subform option list. Look at the parameters values. Change theimage size to 64 (or less). Chose only X frequency, and set Y frequency to 0. Set theamplitude to 255. When choosing a frequency, think what it means - how many cycles doyou expect to see in your image. Note the units. Now glyph .

Note that the output of this routine is of type oat. It must therefore be converted to bytebefore displaying. You have learned conversion utilities in section 2.3.2. When you do theconversions, normalize the image to 255. We also suggest you expand before displaying it,for better display.

When the glyphs are all connected, run the program. Did you get a top view of a sine wave?Is the number of cycles right?

Edit the 'vgsign' glyph and change the X direction frequency (try: pi=2), add a phase inthe X direction. Add Y direction frequency and phase etc. Look at the result each time.Before you leave this section, make sure you understand what is the maximum frequency perpixel of a sine-wave which can be displayed; what happens when the frequency is increasedor decreased, and what is the e�ect of phase.

You can always use help to get further information.

2.4.2 Piece wise Linear

Now try piece wise linear image instead of the sine wave. Create an image of a similarfrequency to the one you used for creating a sine wave, except that now you are actuallyproducing a square wave of positive values. For a start, use an image of size 64 rows andcolumns, sampling frequency: 1. Click o� all the Y related parameters and give the X pulsewidth a value which is half the cycle length, (e.g. X period - 8 and X pulse width 4). Glyphand display!.

You may want to use this option later, when you learn about Fourier Transforms .

Page 38: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

2.5. IMAGE ANALYSIS 37

2.4.3 Constant

Another useful utility is the constant. You can use this option in combination with extract subregion

and Pad Image to create rectangular shapes etc.

2.4.4 Other Options

There are other CREATE IMAGE 2D options such as - Gauss, Circle, Box, Impulse, Frac-tal, etc. You may try them all with various parameters. Do not create large images (over64 � 64) - it will take a very long time. A better method is to create smaller images andexpand them.

2.4.5 Summary

CREATE IMAGE 2D - subform for creating various images. such as: sinusoidal functions,piece wise linear, constant, gaussian, circular, noise etc.

2.5 Image analysis

2.5.1 Background

Image Statistics

Analyzing an image by a computer might be a somehow complex task. In order to performsuch analysis and to remain consistent with other studies, a few parameters are usually de-�ned for example :

� the average of the gray levels of all the pixels in the image or in a previously de�nedarea which is referred to as "Area of Interest" or AOI, and sometimes as "Region OfInterest" or ROI. If the histogram of the image presents a single peak, then the graylevel corresponding to this peak will be the average gray level of the image.

� the standard deviation of the whole image or only of a ROI presents a good evaluationof the noise in the image, when the noise is de�ned as any data which appears in thedigitized image and did not appear in the source scene.

Page 39: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

38 CHAPTER 2. LAB 2: DATA FORMAT AND ANALYSIS

� the median gray level of a ROI, which is the gray level just in the center of the sortedlist of all the pixels. As an example, if the gray levels of the pixels are : 120 100 110100 120 128 and 99, the corresponding sorted list will be : 99 100 100 110 120 120 128.The median will be 110. Half of the pixels have gray levels lower than the median andhalf have gray levels higher than the median. Keep in mind that usually the medianhas to be taken from an odd number of pixels otherwise it is not well de�ned.

Histogram

The histogram of an image consists in a graph showing the number of pixels at each graylevel. Usually the x-coordinate is the gray level from 0 to 512 or 128 (according to the kind ofimages you are dealing with), and the y-coordinate is the number of pixels corresponding tothe gray level. The histogram is a very useful tool in analyzing the image or any processing.A frequent histogram presents two separate peaks, such an image is called "bi-modal".

The histogram is also used if one wants to improve the visual appearance of the image.

Pro�le

The pro�le of a line is the list of all the gray levels of the pixels along a de�ned line in theimage. One may also draw a di�erences pro�le which displays the di�erences of the presentpixel and the previous one. This second kind of pro�le might be useful in edge veri�cationor small feature detection. Generally the user is allowed to trace any line on the image andthe computer displays the pro�le graph where the x-coordinate is the place of the pixel onthe line (beware of the place where you begin to trace the line !), and the y-coordinate isthe gray level of the corresponding pixel.

2.5.2 Tools

Image Statistics

We will now compute some statistics of an input VIFF image. First select an imageand display it. Now, to get some statistics from this image we need to add some newglyph to the work space: OUTPUT �! Information . In the Information subform chose

Image (2D) Stats

Page 40: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

2.5. IMAGE ANALYSIS 39

Histogram

Let us look at the histograms of several grey-level images. Repeat your basic algorithmfor displaying an image. This time choose bb.xv as your image. Add a new glyph to thealgorithm: IMAGE PROCESSING �! Histograms . In the histogram subform, choose

Find Histogram . This program calculates the histogram of the image, and produces anASCII �le with values representing the number of pixels for each value between 0..255. Keyin a name of an output �le at the output �le �eld, and glyph.

Graphic Display Graphic display of the histogram (or any other �le) is accomplished

using the XPRISM programs. These programs are Khoros programs and can be called

from cantata by OUTPUT �! PLOT . In order to display the histogram, only a 2

dimensional plotting is needed. So, select the option XPrism2 . As for now, there is no need

to select any particular settings, so just glyph . Connect the 'vhisto' glyph with 'xprism2'glyph and run the program. You should get a graph of the histogram.

Histogram Equalize Looking at the graph, you probably notice that not all the values be-tween 0..255 have a pixel count, meaning that the image does not take advantage of the wholedynamic range available. This can be corrected by a routine called Histogram Equalize, whichstretches out the histogram. Let's try it. This utility is called by IMAGE PROCESSING

�! Histograms �! equalize . Notice its input is a 'byte' image and its output is an image.

You can display the image, �nd the histogram (as you did in Section 10.2) and display thegraph of the new histogram. Is it now stretched over the entire dynamic range? It shouldbe.

Pro�le

Another information you can get from an image is the line pro�le. For this purpose you needthe function "vsamp" which is in the IMAGE PROCESSING ! Subregion ! Sample on Linesubform. You may create an image using the create yourself tools and present the pro�le ina speci�c direction of the image. The tools used to display the pro�le are the same as theones used for the histogram presentation.

Summary

IMAGE PROCESSING �! histograms

Page 41: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

40 CHAPTER 2. LAB 2: DATA FORMAT AND ANALYSIS

�! �nd histogram - calculates the histogram of an image.

�! equalize - stretches the histogram over the entire dynamic range of 0..255 and redis-tributes the pixels so that there will be a similar number of pixels at every value.ASCII �le viewer - Peeps at an ASCII �le.

XPRISM2 - Produces a 2 dimensional graph of input data.

XPRISM3 - Produces a 3 dimensional graph of input data.

IMAGE PROCESSING �! Subregion �! Sample on Line - Sample an image along anarbitrary line.

2.5.3 Project

Using xedit, create an image of 64x64 pixels, with a known grey level distribution. Performhistogram equalization on this image and compare your result to the calculation you havealready made. Repeat this algorithm on a real image spine.xv . Did you improve the imagecontrast ? Give the contrast result for the di�erent images.

Save your workspace in : ipl95*/checkpoint/lab2/lab2 pro2.wksp to be checked.

Page 42: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

2.6. APPENDIX B 41

2.6 Appendix B

2.6.1 Statistics in Khoros

� Calculation of Mean:

mean =�1

N

��P xi

Where N is the number of samples, the sum is from i=0 to i=N-1, and xi is the sampledvalue of x at i.

� Calculation of Variance:

variance =�

1

N�1

���P

(xi �mean)2�

Where N is the number of samples, the sum is from i=0 to i=N-1, and xi is the sampledvalue of x at i.

� Calculation of Standard Deviation:

standard deviation =pvariance

� Calculation of RMS:

RMS =

rPx2i

N

Where N is the number of samples, the sum is from i=0 to i=N-1, and xi is the sampledvalue of x at i.

� Calculation of Integral Values:

total integral =Pxi

positive part of integral =Pxi, for all xi >= 0

negative part of integral =Pxi, for all xi < 0

Where N is the number of samples, the sum is from i=0 to i=N-1, and xi is the sampledvalue of x at i.

� Calculation of Skewness: Skewness is a measure of the tendency of the deviationsfrom the mean to be larger in one direction than in the other, or, in other words,the asymmetry of a distribution about its mean. A positive skew value signi�es adistribution whose tail extends out towards more positive x, and a negative skewsigni�es a distribution whose tail extends out towards more negative x. Populationskewness is unitless and is de�ned as:

Page 43: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

42 CHAPTER 2. LAB 2: DATA FORMAT AND ANALYSIS

Eh((x�mean) = (stdev))3

i,

where stdev is the standard deviation of the data. lvstats computes the sample skew-ness as:

skew = 1

stdev3�N��P

(xi �mean)3�

Where N is the number of samples, the sum is from i=0 to i=N-1, and xi is the sampledvalue of x at i.

� Calculation of Kurtosis: Kurtosis is a unitless measure of the tail heaviness of a distri-bution and is de�ned as:

E��

x�meanstdev

�4�� 3,

where stdev is the standard deviation of the data. lvstats computes the sample kurtosisas:

kurtosis =�

1

stdev4�N

���P

(xi �mean)4�� 3

Where N is the number of samples, the sum is from i=0 to i=N-1, and xi is the sampledvalue of x at i.

� Calculation of Entropy:

entropy = � (P(norm hist � log2 (norm hist))) where

norm hist = (num pixels with gray level x)/(total number pixels),

the sum is from i=0 to i=N-1, and N is the number of gray levels.

� Calculation of Contrast:

contrast =P((pixel value2) � norm hist)

where

norm hist = (num pixels with gray level x)/(total number pixels),

the sum is from i=0 to i=N-1, and N is the number of gray levels.

Page 44: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

Chapter 3

LAB 3 : Algebraic Operations and

Image Enhancement

3.1 Objectives

� Algebraic Operation on images.

� Spatial �ltering.

3.2 Preparing Ourself

� Can we use some arithmetics on image for noise reduction ?

� How can we perform movement detection on a set of images ?

� Mention di�erent noise reduction methodes ?

� Mention di�erent edge detection methodes ?

� Write a normalized averaging operator ?

� What is a Laplace operator ? Write down a discrete Laplace operator.

� Is the Median �lter linear or nonlinear ? Prove your answer.

� Find the discrete mathematical description of the Gradient �lter.

� Write a gradient operator. For what purposes can it be used, and how does it work ?

43

Page 45: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

44CHAPTER 3. LAB 3 : ALGEBRAIC OPERATIONS AND IMAGE ENHANCEMENT

3.3 Algebraic Operation

3.3.1 Background

Algebraic operations produce an output image that is the pixel by pixel sum, di�erence,product or quotient of two input images. An important application of image addition isaveraging together multiple images of the same noise in order to reduce additive randomnoise. The Signal to Noise amplitude Ratio increases with the square root of the number ofimages averaged. Image addition may also be used to superimpose the content of an imageupon another. Image subtraction can be used to remove an undesired additive pattern froman image. It may be a slowly varying background shading pattern, a periodic noise patternor any other additive contamination that is known at every point in the image. Subtractionis also useful in detecting changes between two images of the same scene. For example, onecould detect motion by subtracting sequential images of a scene. Image subtraction is alsorequired to compute the gradient, a useful function for locating edges. Multiplication anddivision �nd less application in digital image processing. They can be used to correct thee�ects of a digitizer the sensitivity of which varies from point to point within the image.Division can produce ratio images that are important in multi-spectral analysis. Multiplica-tion by a "mask" can remove parts of images, leaving only objects of interest.One may also perform logical operations on images, such as AND, OR or XOR. As an ex-ample, try to see the result of the XOR operation on two images built of a white line, wherethe only di�erence between the two images is the location of the line.

3.3.2 Tools

We can perform algebraic manipulation on images of four kinds :

� "UNARY" arithmetic that will involve only one image.

� "BINARY" arithmetic that will perform algebraic operation between two images.

� "LOGICAL" operation on one or between two images.

� "MATRIX" perform matrix operation on the image.

You can get all of this function using the ARITHMETIC utilities.

Page 46: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

3.4. 2D SPATIAL FILTERS 45

3.4 2D spatial Filters

3.4.1 Background

Noise

The noise in an image consists of all the information that did not appear in the originalscene. It might come from the recording process, or any further processing on the imagesuch as mathematical processes or �lters... The distribution of the gray levels of the noisemight be a Gaussian distribution, such noise is referred to as "GAUSSIAN" noise.

Smoothing

In any digitized image, noise will usually occur. There might be many noise sources, suchas in the digitization or quantization processes, detectors image processing etc... One ofthe most important issues of Image Processing is removing the noise o� the image, com-monly referred to as "Smoothing". Several types of processing try to deal with this task.In this paragraph we shall discuss the processing which involve convolution on the image.Convolution in the space domain (we shall discuss later on convolution in the frequencydomain) is performed by applying a mask of weights on the image, multiply each pixel withthe corresponding weight, replace the central pixel of the mask window by the result of themultiplication, moving the mask to the next position of the image and so on until all thepixels are replaced. The image borders are treated according to the programmer decision,they might not be processed at all, or the convolution might be cyclic, where the image iscompleted by repeating itself periodically. A common smoothing �lter is the "Average" �l-ter, where all the pixels of the window are averaged with or without weights. A 3x3 averagemask will be

1=9

264 1 1 11 1 11 1 1

375 (3.1)

Such �lters blur edges or small features in the original process image, therefore "smoothing"the image. Di�erent approaches can be used in order to reduce noise without smoothingthe image, thus conserving a good resolution. Let us remind that the spatial resolution ofthe image is the capability of an observer to detect small high contrast features. For spaceresolution ; the contrast resolution is de�ned as the capability to detect two close grey levelfeatures.

Filters capable of keeping better resolution are "nonlinear" or "data dependent" �lters.They may be performed only by a method similar to convolution. The most common example

Page 47: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

46CHAPTER 3. LAB 3 : ALGEBRAIC OPERATIONS AND IMAGE ENHANCEMENT

of such �lters is the MEDIAN �lter, which replaces the central pixel of the window by themedian of all the pixels in this window. A better �lter replaces the central pixel by themedian of k pixels whose gray levels are closest to the central pixel's gray level. Such �lteris called k-Median. By the way, the same improvement might be imposed on the average�lter, creating the k-average �lter.

Edge Detection

Detecting edges in an image might be very useful for many purposes. One may want toenhance the edges, detect their location in the image or draw the contour of features in theimage. One of the most common �lter is the gradient �lter which performs the gradient, or�rst derivate of the pixels in the image. It takes the di�erence between present pixel and theprecedent one. Another way to detect edges is to apply a High Pass �lter which removes thelow frequencies of the image. The Fourier transform of an edge yields a sinc function whichhas spectral components in the entire spectral domain. If one removes the low frequencies,one removes the contribution of big objects (see the paragraph about spatial frequencies),and only the parts contributed by small objects and the edges will appear in the outputimage.

threshold

Contour lines provide an e�ective way to establish the boundary of a simple object within animage. The technique of using contour lines as boundaries is called "thresholding". Supposean image contains a dark object on a light background. There will be two major peaks inthe histogram of the image. The leftmost peak is due to the dark object and the rightmostpeak is due to the light background (one might work with the opposite convention that suits0 to white and high value to black). The relatively few midgray peak that will appear in thehistogram is due to the pixels in the region around the edges of the object. Let us remindthat the digitized image might not allow the gray value to pass with no transition at all froma low to a high value. A threshold gray level chosen in the area of the dip between the twoprincipal peaks will produce a reasonable boundary for the object.

3.4.2 Tools

The main objective of enhancement techniques is to process a given image so that the resultis more suitable than the original image for a speci�c application. To help us in this goal we

Page 48: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

3.4. 2D SPATIAL FILTERS 47

will propose you to use the IMAGE PROCESSING �! Spatial Filters utilities and youwill be introduced to the 2D Spatial Domain Filters.

Smoothing

Smoothing operation are used primarily for diminishing spurious e�ects that may be presentin a digital image as a result of a poor sampling system or transmission channel.

Create an image and add noise in order to compare the di�erent smoothing techniques: The median algorithm and the convolution averaging. You can also use an advancedalgorithm named Speckle Removal (for now read the online help, we will study this algorithmmore thoroughly in lab5).

Edge Detection

Under the title 'Edge extraction' the KHOROS has the gradient operation. There are twotypes of gradients allowed by KHOROS, the vertical one and the Roberts. You should beacquainted with the two names already, and if you are not, please read pages 348-350 of Jainbefore you go on with the lab.It is necessary to mention at this stage that KHOROS takes as a result of the gradientoperation the absolute sum of the two directions as stated in equation (9.16) page 349.For a start create a simple image (such as 'Box Projection' found in 'INPUT SOURCES'),and operate on it with the two optional gradients. Next create a sine wave image and repeatthe above. Did you get the exact derivative of the sine wave? ,if you �nd it hard to decide,take a cut through the image and display samples on line. Make sure you understand theresults before you go on.Operate with the gradient operation twice on the results of the �rst box gradient.

KHOROS has another edge extraction kernel called 'sobel'. Operate with this kernel onthe 'box projection' image twice, and see that you understand the di�erence between thedi�erent kernels. According to the results you get, explain the advantages of the sobel kernelover the simple gradient ones, add the explanation as a comment to the previous workspace.

The 2D convolution feature within cantata enable to convolve two images Use this featureand convolve the kernels you have created during the preparing part with the 'Box projection'image. See that you extract the edges correctly. Change the kernels as you wish to get abetter result.

There are three more edge detection algorithms supplied to you by KHOROS. The 'DRF'(Di�erence between the input and the output of a certain Recursive Filter), the 'GEF' (usesmaxima of Gradient), and the 'SDEF' (uses the zeros crossing of second directional derivative

Page 49: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

48CHAPTER 3. LAB 3 : ALGEBRAIC OPERATIONS AND IMAGE ENHANCEMENT

along the gradient). These methods were invented to reduce the in uence of added noise onthe edge extraction.Read the on line help of the above methods and understand the main issues, then, add someshot noise to the box projection image and try to achieve a good edge detection using theaforementioned methods.All the time compare the results you get to the simple gradient operation.

Threshold

Thresholding is used to create a binary image. This tool will be very useful in extractingthe edges of an image. Use this feature found in IMAGE ANALYSIS �! Segmentationand understand it.

Closing

This feature can be used to emphasize the edge of an image. It is a part of "Morphologic"image processing and it refers to certain operations where an object is hit with a structuringelement and thereby reduced to a more revealing shape. Boundary gives the boundary pixelof an object, but they are not ordered along its contour. Use the IMAGE PROCESSING

�! Morphology �! closing feature to enhance the images inner contours.

3.4.3 Project

Use the image of brain.xv and extract only the region border of the two brain lobes. Usethe functions: thresholding, hist equalization, gradient methods and noise �ltering.Save your work under the name : ipl95*/lab3/lab3 pro1.wksp

3.4.4 Extra Exercises

� Get the noisy moon image (moon noise.xv) and enhance it to get a smooth picture.

� Use the lenna image and �nd the edge on this image.

� Use the image of Jerusalem and extract all the roads.

Page 50: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

Chapter 4

LAB 4 : 2D Frequency Domain Filter

4.1 Objective

� Introducing you to the "world of spectra".

� View the 2-D spectrum (amplitude/phase) of a picture.

� Use the spectrum domain for �ltering

4.2 Preparing Yourself

Answer the following questions. You will need the results during the lab to check theoutcomes of your lab exercises.

(1) Find by de�nition the two dimensional discrete Fourier transforms of the followingsequences.

(a) sin(!n) for ! = �2; �; �

3.

Note what happens when the input frequency is not one of the discrete Fouriersamples.

(b) cos(!n).

(c) �(m;n).

(d)P1

m0=�1

P1n0=�1 �(m�Xm0; n� Y n0).

49

Page 51: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

50 CHAPTER 4. LAB 4 : 2D FREQUENCY DOMAIN FILTER

(2) Find by de�nition the Inverse discrete Fourier transforms of the following sequences.

(a) �(k; l).

(b) �(k � �3; l � �

4) + �(k + �

3; l + �

4).

(3) Multiply the result of 1.(d) by exp(jk) in the Fourier domain, and take the InverseFourier transform of the result.

(4) Draw an up viewed intensity levels of the two dimensional

(presented in polar coordinates) image.

g(r; �) =1

2[1 + cos(2�p�)]

Explain the meaning of the parameter p in the image.

(5) Usually, we don't use ideal 'RECT' Low Pass Filter neither in one dimensional Fourier�ltering nor in 2 dimensional. We don't do this from di�erent reasons though.

Think about the relevant reasons for both cases.

(6) Choose two di�erent two dimensional images, one of 2�3 and the other of 2�2 numbers.Expand them as necessary with zeros, and linearly convolve them.

4.3 2D Transform : 2D FFT

4.3.1 Background

One of the most important tools in Image processing is the Fourier Transform. This operationtransforms the information of an image to the frequency domain.In class you will deal a lot with the theoretical aspects and characteristics of the FourierTransform, and the Fourier domain. Using cantata you have an opportunity to see thevisual interpretation of this domain.In the space domain, the period of an object is de�ned, in order to create a basic periodicity,as 2�x, when �x is the object length. If the object is, for example, a three pixels long whiteband, the spatial period is created as the original object and a three pixels long black bandfollowing it. This creates an impression of periodicity, the wave will be of a period equalto twice the object length. The corresponding spatial frequency will then be one over theperiod, or 1=2�x.

Page 52: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

4.3. 2D TRANSFORM : 2D FFT 51

Thus, the frequency of the objects in the original scene is inversely proportional to their size.Low frequencies correspond to large objects, and high frequencies to small ones.As you probably already know from other courses, the process that allows to pass fromthe time domain to the frequency domain is the Fourier Transform. In image processing,the Fourier Transform allows us to pass from the SPACE domain to the FREQUENCYdomain, exactly as it does for time|frequency.Suppose the intensity in the original scene is described in the image as the discrete functionf(m;n). A discrete function, where m;n = 0; 1; 2; :::; N � 1 for N �N image.The discrete Fourier Transform is:

F (k; l) =N�1Xm=0

N�1Xn=0

f(m;n)exp

"�2�j(km + ln)

N

#

and the Inverse Fourier Transform is:

f(m;n) =1

N2

N�1Xk=0

N�1Xl=0

F (k; l)exp

"2�j(km+ ln)

N

#

where k and l are the discrete frequencies, and k; l = 0; 1; 2; :::; N � 1 .

4.3.2 Tools

In the preceding operations try not to use images of more than 64 � 64 points, to preventwaiting a long time for the processing. If you want to have a better look at the output image,use the Expand image utility, just before displaying the output image.

Fourier Transform of simple images

Before starting to transform images read carefully the `help' under the �t block in `cantata'.Note that the �t command does not transform the input image directly, but it �rst multipliesit by a phase factor exp[�j�(m + n)], make sure you understand why. Also pay attentionto the appropriate scaling factors of the forward and inverse transforms.

(a) Use the `constant' utility to create a constant amplitude image, make sure your outputimage is made of complex numbers, otherwise you have to convert it before transform-ing.

Use the `transform' utility to create a Fourier Transform of the constant image. Theoutput of the `v�t' program is a complex �le. The three arrows at its output looking

Page 53: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

52 CHAPTER 4. LAB 4 : 2D FREQUENCY DOMAIN FILTER

top to bottom, represent the complex, real and imaginary fourier outputs respectively.In order to see meaningful information we want to see the power spectrum or the phasein the frequency domain. We usually don't get clear directly valuable information bydisplaying the real or imaginary part of the fourier output. We therefore need anotherroutine which calculates the power of the fourier routine output. The routine is `vmmp'accessed by IMAGE PROCESSING ! transforms ! power . Use this routineand display. (you can convert the oat output into byte before displaying, otherwiseyou will get a notice from khoros. try the two options.)

Do you understand the image? What does the dot represent? Remember that everycoordinate in the fourier plane represents a frequency (fx; fy). The (0; 0) frequency isat the center of the image (N

2; N2), where N is the size of the image side.

Take a look at the real and imaginary parts of the output image. Make sure the resultsof the amplitudes agrees with the anticipated results.

Use the `sine' wave option to create `sine' and 'cosine' waves and apply a phase shiftto the constant. Do it by inserting the function cos(�x) � jsin(�x) . Transform thefunction you have created and check that the result you get agrees with the theory.

(b) Use the `sinusoidal' option to create an image. Choose only the X frequency, and setY frequency to 0. Set the amplitude to give you a magnitude of 64 after the fouriertransform. When choosing a frequency, think what it means|how many cycles do youexpect to see in your image? Note that the output of this routine is of type oat. Itmust therefore be converted to byte before displaying. Use the normalization optionin the conversion. When you �nish building your workspace, run the program. Didyou get a top view of the sine wave? Is the number of cycles right?

Edit the `vgsign' glyph and change the X direction frequency, add phase in the Xdirection, add Y direction frequency and phase. Look at the result each time. Choosea frequency which doesn't give a component at the sampled frequency points, (like�=3. Achieve the `spectral leakage' phenomena in the fourier domain.

Change the number of points in the original image, and see the in uence on the trans-formed output.

Use `subregion' option to cut a line across the `sin' image and plot a graph of thesine-wave on the screen, using the XPRISM2 utility.

(c) Use the `impulse' utility to create an impulse at several locations throughout the inputimage. Each time take the Fourier Transform of the image and account for the results.

Page 54: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

4.3. 2D TRANSFORM : 2D FFT 53

At �rst locate the impulse at the coordinates (0; 0), then move it to (N2; 0), and at

last locate it at the middle of the image. Look at the magnitude of the complex FFToutput and at the real and imaginary parts of the transform.

Use the same utility to generate several impulses, �rst only in the Y axis, then onthe X axis, and at last in both. Generate a grid of impulses and take it's transform.Display the result of the transform and make sure you have got the right result and thecorrect amplitude according to the theory. Change the spacing between the impulsesand anticipate the in uence on the output image.

Inverse Fourier Transform of simple images

(a) Take the forward transform of the sine-wave, created at the previous section, and usethe Inverse Fourier Transform to transform it back into the space domain. See that youget the expected original sine-wave with the correct amplitude and frequency. Now,multiply the transformed sine-wave by a linear phase at the frequency domain and seeit's in uence in the reconstructed Inverse Transformed sine.

(b) An interesting exercise is to build your own image in the frequency domain and performinverse �t to get back the image plane.

Build an image consisting of Impulse responses at a desired pixel. As an examplechoose a 64 � 64 image, and put an impulse at pixel (36; 32) and (28; 32). You clicko� \Impulse spacing X-dir". The number of set images is set to 2 in X, and the o�setis set to 28 in the X-dir, and 32 in the Y-dir. The impulse spacing X-dir is set to 8.This produces 2 impulses at 28 and 36. Glyph, and display. `vimpulse' output a `byte'image (you can �nd this in the 'help') so if you want to perform Fourier transform,it is advisory to convert it to a complex �le (you can try what happens if you don't -account for the result). Connect the 'vimpulse' glyph you have produced to the inputof the inverse �t program you have created in the previous subsection. Execute! Doyou get a sine wave? Is this what you have expected? Try to change the location ofthe impulses, and try the Y direction too. You can make interesting images.

Produce 4 � 4 impulses at regular intervals (not necessarily the same in X and Y)around the center, and inverse �t using the previously described procedure. Accountfor the image. Now increase the number of impulses to 6 � 6. Change the o�set, sothe image is kept symmetric around (0; 0) and see how your image gradually changesfrom two dimensional sine-waves to impulses. You probably remember that a \train of

Page 55: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

54 CHAPTER 4. LAB 4 : 2D FREQUENCY DOMAIN FILTER

impulses" transforms to a \train of impulses". You can now see visually the di�erencebetween a �nite train of impulses and an in�nite (complete image) one.

4.4 Frequency Filtering

4.4.1 Background

When one applies a digital process on an image, one actually implements a \�lter". A largenumber of digital processes can be modeled as two dimensional linear systems. When theinput is the two-dimensional Kronecker delta function at location (m0; n0), the output atlocation (m;n) is de�ned as:

h(m;n;m0; n0)def= H[�(m�m0; n� n0)]

and is called the impulse response of the system. For an imaging system, it is the image inthe output plane due to an ideal point source at location (m0; n0) in the input plane.The impulse response is called the point spread function (PSF) when the inputs and outputsrepresent a positive quantity, such as the intensity of light in imaging systems. The termimpulse response is more general and is allowed to take negative as well as complex values.The region of support of an impulse response is the smallest closed region in the m;n planeoutside which the impulse response is zero. A system is said to be a �nite impulse response(FIR) or an in�nite impulse response (IIR) system if its impulse response has �nite or in�niteregions of support, respectively.When one operates with such systems as the above on images, one can achieve an e�ect of�ltering. For example you can �lter noise out of an image.The noise in the �nal image is usually referred to as white noise. That means that thespectral analysis of the noise usually provides a constant amplitude at each frequency. Sincethe image contains more information about large objects (low frequencies) than about smallobjects (high frequencies), the signal to noise ratio (SNR) at low frequencies is signi�cantlyhigher than the SNR at high frequencies (see �gure 1.)

The basic feature of every noise removal �lter is based on the aforementioned fact. Inorder to remove noise one might remove the part of the signal which contains the highfrequencies, since there the SNR is very low, compared to the SNR at low frequencies.However, removing this part of the signal removes the information about small objects, thuscorrupts the spatial resolution of the �nal image. Every �lter that removes the part of thesignal at high frequencies is called a low pass �lter, since low frequencies pass through that�lter.

Page 56: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

4.4. FREQUENCY FILTERING 55

Figure 4.1:

There are di�erent types of low pass �lters according to the shape of the �lter and howmuch of the high frequencies is kept untouched. The graph that represents the normalizedshape of the �lter, or which ratio of the original image pass at each frequency is called theModulation Transfer Function of the �lter.

MTF =jH(u; v)jjH(0; 0)j

where u; v are the spatial frequencies in the fourier domain, and H is the spectral transferfunction of the �lter.When the �lter is time invariant one can use the convolution operator in order to decide theoutput of a �lter for a given input.The convolution of two functions, denoted by f(x) ? g(x) is de�ned by the integral:

f(x) ? g(x) =Z 1

�1f(�)g(x� �)d�

where � is a dummy variable of integration.The importance of convolution in frequency domain analysis lies in the fact that f(x) ? g(x)and F (u) �G(u) constitute a Fourier Transform pair. In other words, if F (u) is the Fourier

Page 57: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

56 CHAPTER 4. LAB 4 : 2D FREQUENCY DOMAIN FILTER

Transform of f(x) and G(u) of g(x), then F (u) �G(u) is the Fourier Transform of f(x)?g(x).Thus convolution in space domain reduces to multiplication in frequency domain.

For instance, if one wants to apply a Low Pass �lter to an image, one might either multiplythe Fourier Transform of the image and the Fourier Transform of the �lter (i.e. how muchof the signal pass at each frequency) or one might perform the convolution of the image inthe space domain with the inverse transform of the Transfer function of the �lter. Usually,convolution is more time-consuming than Fourier Transform and multiplication, when oneuses the Fast Fourier Transform algorithm.

The convolution is achieved by applying the matrix �lter or \kernel" on the image, multiplyall the pixels by the corresponding weights, replace the central pixel by the result and movethe kernel over the whole image.

The best known Low Pass �lter is the average �lter. When performed as a convolution, asmall window of, for example, 3� 3 pixels passes over the whole image. In the simplest caseof Average, the window is:

1 1 11 1 11 1 1

If in the original scene, there is a point or an edge, this �lter blures it. In fact, all kinds ofLinear Low Pass �lters smoothes the image, and as they remove noise, they also reduce thespatial resolution.

There are other kinds of �lters, such as High Pass �lters that perform edge enhancementor edge detection of the image. There are also Band Pass �lters that allows the signal ina certain band of frequencies to pass through. The last are less useful in image processingthan the two previously mentioned �lters.

There are also �lters that have no well de�ned Fourier Transform, such �lters are calledNonlinear �lters, and the only way to apply them is in the space domain. The simplestexample of such a �lter is the Median �lter that replaces the central pixel of the window bythe median of the pixels in the window. As the Average �lter, the Median �lter is a NoiseRemoving �lter. Since it does not just average the pixels in the window but searches for themedian, it keeps some features in the image that the average blures.

The Median �lter does not blur the image. It totally removes any feature it considers noise.

The window might be of square shape as we saw. It might also be a cross or any other shape.

You might also try to think about other kinds of Nonlinear �lters that are able to removenoise but do not blur the image in the same amount that the average or the median does.

Page 58: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

4.4. FREQUENCY FILTERING 57

4.4.2 Tools

Filtering in the fourier domain incorporates removal of spectral content in a certain region.For example Low Pass Filter would leave only frequencies within a circle of a given radiusaround the DC frequency (0; 0). Cantata enables you to perform various kindes of �lterings:Low Pass Filters, High Pass Filters, Band Pass Filters and others. They can all be found onthe IMAGE PROCESSING ! Frequency Filters subform.You will try the Cantata possibilities later. First let's create the most simple �lter i.e. therectangular one, and use it to �lter out the low frequencies in the Fourier domain.

(a) You can use the Create Images (2D) ! Box Projection to create a rectangular �lterin the Fourier domain. Don't forget that the �lter should be of the same dimension asthe images you are working with.

Generate an image composed of two sine-waves, as you have already done in the �t partof the lab. Using the 'ARITHMETIC' utility add the two sines and take their FourierTransform. Now generate the required rectangular Filter to cut o� the upper sine-wavefrequency. Use the 'Box Projection' utility as explained earlier. Change the 'NumberOf Rows' and the 'Number Of Columns' and adjust it to the required size. Calculatethe right position of the box in the Fourier domain and locate it there using the 'BoxY Height' and the 'Box X Width'. Set 'Box Rotation Angle' to 0, and 'Box CornerAngle' to 90.0 Deg. Set the right amplitudes using the 'Outside Box Pixels Value' andthe 'Inside Box Pixels Values'. Leave the other options on the glyph unchanged andglyph.

Operate on the transformed sine-waves image with the Filter you have just createdand make sure that you get the required result. Display the images, before and after�ltering, in the space domain and in the Fourier domain. Cut a line through the imagesand see the one dimensional result.

(b) Using the 'Input Source' utility, you can also generate a circle type of Low Pass Filter (orHigh Pass Filter). Create the two �lters and apply them to the two sine-waves image inthe Fourier domain, in order to remove the upper frequency. Add several sine-waves atdi�erent frequencies to the X and the Y dimensions simultaneously. Filter the di�erentfrequencies at the X and the Y dimensions. Filter the resulting images and accept therequired results.

(c) Now try to use the built in Filter function of Khoros. There are two major types of�lters within the Khoros environment. The Exponential and the Butterworth. You

Page 59: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

58 CHAPTER 4. LAB 4 : 2D FREQUENCY DOMAIN FILTER

can set the cuto� frequency radius (which is a value between 0 and �=2. The �lterorder is the steepness of the cuto�. Large order �lters may take longer to perform. Inorder to see and explore the characteristics of the various �lters you �rst have to createa constant image and pass it through the �lter in the Fourier domain. Then you cancut a line through the output image and get the pro�le of the �lter. Take a look atthe responses of the two �lter types.

Next create an image in the spatial domain and perform various �lterings. You cancreate a complicate sine wave containing two frequencies or more. This can be doneeither in the Fourier domain, as you did earlier, or directly in the image plane, bycreating two sine-wave images and adding them together. Display the result of theaddition before continuing with the �ltering process. Filter out the high and/or lowfrequency sine-wave by selecting the proper cuto� radius.

(d) Waiting for you under the 'INPUT SOURCES' utility is the image of the expressiong(r; �) = 1

2[1 + cos(2�p�)]. You can get this image by calling the 'cos.asc' ASCII �le

from the directory. Get the image, pass it through the correct conversion to get theVIFF format and display. Pass it (after transforming) through several types of �ltersand account for the results.

(e) Take the two images which you have convolved in the space domain during your prepara-tion. Use Xedit to create the images and expand them by zeros appropriately. Performlinear convolution of the two images. Take the Fourier transform of the images, mul-tiply their results and take the Inverse Fourier transform. See that you get the sameresults as expected.

4.4.3 Project

(1) Use the 'Input Sources' to get an image of maxhead.xv. As you present this image youcan see straight lines in the background. Your mission is to extract from the image thelines in one of the directions.

Some tips for the process, �rst you will have to extract proper part of the image to workon because the 'FFT' process manipulates images with certain number of pixels. Thenyou have to decide which kind of a �lter to use (speci�cally, the bands of frequenciesthat have to be extracted from the image).

Find a simple way of deciding the above frequencies, and explain your approach usingcomments.

Page 60: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

4.4. FREQUENCY FILTERING 59

Leave your workspace under the name:ipl95*/checkpoint/lab4/lab4 pro1.wksp to be checked.

(2) Choose one of the supplied images from the 'Input Sources' subform, and add noise.Use a gaussian white noise. Choose the parameters properly such that you are able tonotice the di�erence between the picture with the noise and the one without it.

Use �ltering in the Fourier domain to improve the noisy image.

Input the same image several times, add random noise to all of the inputs and useaverage techniques to reduce the noise. Leave your workspace under the name:ipl95*/checkpoint/lab4/lab4 pro2.wksp.Z to be checked, and don't forget to add com-ments explaining each step of the algorithm.

Page 61: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

60 CHAPTER 4. LAB 4 : 2D FREQUENCY DOMAIN FILTER

Page 62: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

Chapter 5

LAB 5 : Image Restoration

5.1 Objectives

� Introduction to PSF and MTF.� Image restoration by frequency �ltering.

Inverse �lter.Wiener �lter.

� Image restoration by spatial �ltering.Speckle removal.

5.2 Preparing Yourself

(a) Find the PSF and the MTF of the following linear system.

y(m;n)� �1y(m� 1; n)� �2y(m;n� 1) = x(m;n)

(b) Use the properties of the two dimensional Fourier transform, to �nd the PSF and theMTF of the following systems:

h(x; y) = 2sinc[�(x� x0)]sinc[�(y � y0)]

h(x; y) = 2sinc2[�(x� x0)]sinc2[�(y � y0)]

61

Page 63: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

62 CHAPTER 5. LAB 5 : IMAGE RESTORATION

(c) There are several major known blurring functions, listed below. Working in the lab youwill use No. 1,2,4.1) Di�raction limited, coherent absinc(ax)sinc(by).

(with rectangular aperture)2) Di�raction limited, incoherent sinc2(ax)sinc2(by).

(with rectangular aperture)

3) Horizontal motion 1

�0rect

�x�0� 1

2

��(y).

4)Atmospheric turbulence exp[���2(x2 + y2)].

5) Rectangular scanning aperture rect�x�; y�

�.

6) CCD interactionsP1k=�1

P1l=�1 �k;l�(x� k�; y � l�).

(d) Think of a way to restore a characters written image, where you get the Image andnothing more.

(e) Look in JAIN/Fundamentals of Digital Image Processing, and �nd the expressions forInverse Filter and Wiener Filter restoration. Derive (or copy from the book the wholederivation) the basic �lter expressions.

(f) Your working environment (i.e. KHOROS) equips you with the following inverse �lter:

IF =

(1

Hif jHj > t

1

teiargHif jHj < t

Where: t is the threshold value.H is the blurring function.

Account for the di�erences between the expressions of the book and the ones givenabove.

Specify the advantages and the disadvantages of the two methods presented, withregard to the required �ltering process in mind.

Specify your opinion about the advantages/disadvantages of the di�erent �lters.

Page 64: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

5.3. BACKGROUND 63

(g) When it comes to Wiener Filtering KHOROS supplies you with the following WienerFilter:

WF =

8<:

H�

jHj2+W 2 if jHj > tjHj2

teiargH� 1

jHj2+W 2 if jHj < t

Where: w is a wiener parameter.

H is the blurring function.

Account for the di�erences between the expressions of the book and the ones givenabove.

What does the wiener parameter mean?

Show the relationship between the Inverse Filter and the Wiener Filter and explainthe advantages of the last.

(h) What is a speckle noise, how is it being created, and how can we reduce it? (JAINp.313)

The KHOROS uses the 'eight hull algorithm' developed by T.R. crimmins to reducethe speckle noise.

Read the relevant paper (Applied Optics, Vol. 24 No. 10 Geometric �lter for specklereduction By Thomas R crimmins), and explain the reduction algorithm. Emphasizethe logical guidelines which make sense in the proposed algorithm.

5.3 Background

MTF and PSF

Let us think of a single high contrast point as an input of an optical or image grabber. Forexample, a black point in a white uniform background. Once this point passed through thesystem, it might have been deformed. It might have been blurred or appear as a star pattern,or any deformation the system does on a single point. If one calculates the Fourier transformof the point function and of the output image, their division gives the deformation functionof the system or Transfer function of the system. The spot image produced by a point sourceis the impulse response or "Point Spread Function", PSF in optical terms. One might alsode�ne the "Modulation Transfer Function", MTF of a system or a �lter. The MTF displaysthe part of the signal that passes through the system, or �lter at each spatial frequency. It

Page 65: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

64 CHAPTER 5. LAB 5 : IMAGE RESTORATION

may be measured by recording the output image of an input built of black bands in a whitebackground (or inversely), where the width of the bands gets smaller and smaller as theirfrequency increases.

Inverse Filtering

A typical imaging system consists of an image formation system, a detector, and a recorder.For example, an electro-optical system such as the television camera contains an opticalsystem that focuses an image on a photoelectric device, which is scanned for transmissionor recording the image. Similarly, an ordinary camera uses lens to form an image that isdetected and recorded on a photosensitive �lm. A general model of such systems ( Fig 5.1)can be expressed as

v(x; y) = g[w(x; y)] + �(x; y)

w(x; y) =Z Z 1

�1h(x; y; x0; y0)u(x0; y0)dx0dy0

�(x; y) = f [g(w(x; y))]�1(x; y) + �2(x; y)

where u(x; y) represents the object (also called the original image), and v(x; y) is the observedimage. The image formation process can often be modeled by the linear system presented,where h(x; y; x0; y0) is its impulse response. For space invariant systems, we may write

h(x; y; x0; y0) = h(x� x0; y � y0; 0; 0)def= h(x� x0; y � y0)

The functions f(�) and g(�) are generally nonlinear and represent the characteristics of thedetector/recording mechanisms. The term �(x; y) represents the additive noise, which hasan image dependent random component f [g(w)]�1 and an image-independent random com-ponent �2.Usually we can approximate the transfer function of the 'blurring function' h(x; y) by a lowpass �lter. Some of the common �lters being used are presented at the 'preparing yourself'section. When we do so, we can �nd the Fourier transform of the image and of the blurringfunction and divide them in the frequency domain. The ideal result of this operation shouldgive us the original image (when there is no noise). Performing the previous processingone should expect some troubles. Let us imagine for example that the transform of theblurring function includes zeros, Dividing the expression yields in�nities in the result. Toavoid this problem we decide on a threshold and when the transformed blurring function

Page 66: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

5.3. BACKGROUND 65

Figure 5.1: General model of a blurring system

Page 67: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

66 CHAPTER 5. LAB 5 : IMAGE RESTORATION

gets values lower then the threshold we replace the division result with zeros. Doing so weinsert distortions into the restored image but avoid the in�nities in the result.The above �lter is called the Inverse Filter because most of its values equal the reciprocityof the blurring function low pass �lter.

Wiener Filtering

The mains limitation of inverse �ltering is that this �lter remain very sensitive to noise.Wiener �ltering is a method of restoring images in the presence of blur as well as noise.As you have hopefully seen in your preparation the Wiener �lter uses the best linear esti-mation, in order to restore the original image out of its noisy blurred counterpart.

Speckle Reduction

When monochromatic radiation is scattered from a surface whose roughness is of the orderof a wavelength, interference of the waves produces a noise called speckle. Such noise isobserved in images produced by coherent radiation from the micro-wave to visible regionsof the spectrum. The presence of speckle noise in an imaging system reduces its resolution,particularly for low-contrast images. Therefore, suppression of speckle noise is an importantconsideration in the design of coherent imaging systems. The problem of speckle reductionis quite di�erent from additive noise smoothing because speckle noise is not additive.Because of its as though random phase nature, the speckle noise may add to the imagenarrow walls, towers or valleys. The Geometric �lter used by KHOROS is a spatial �lterwhich uses this fact to remove the speckle noise with minimum damage caused to the detailesof the image itself.

5.4 Tools

(a) Create a Gaussian function in the space domain. Chose the variance as you wish.Create 4 impulses in the space domain. Chose the spacing and locations as you wish.Convolve the two images (by transforming them �rst - meaning, in the Fourier domain)and display the result you get in the space domain.

If you performed all the previous steps correctly, you should get 4 PSF's of the Gaus-sian.

(b) In order to examine the properties of the Inverse Filter supplied to you by KHOROS,you can insert constant to the blurred image input (the upper one), and apply di�erent

Page 68: INSTR UCTION MANUAL - TAUtur/pdip/newlab1.pdfIMA GE PR OCESSING LABORA TOR Y INSTR UCTION MANUAL Departmen t of In terdisciplinary Studies F A CUL TY OF ENGINEERING T el-Aviv Univ

5.5. PROJECT 67

kinds of inputs to the blurring function input. Then you can look at The blocksdi�erent outputs.

Demonstrate for yourself the operation of the Inverse �lter, it's threshold utility, andthe preserved phase property.

(c) Repeat the above for the Wiener �lter and examine it's properties.

(d) Remember the image of 'cos.asc', you have used in the FFT lab?. Use the same imageagain. Don't forget to translate it to VIFF format, and convolve it with an ideal LowPass Filter to extract the low frequencies of the image. Now use the Inverse Filter torestore the original image.

You will not be able to restore the image correctly.(why ?), change the Low Pass Filtersuch as to restore the exact original image by using the Inverse Filter.

(e) Create two images of RECT with di�erent dimensions in the space domain. Convolvethem with one another, and use the Inverse and the Wiener �lters to restore one ofthem. Add white Gaussian noise to the convolved input image and demonstrate foryourself the advantage of the Wiener �lter under these conditions. Change the Wienerparameter to get a better restored image.

5.5 Project

Input the data �le z02, found in 'INPUT SOURCES' and display. You will see a blurredwriting. Use the hidden information in the image and the restoration techniques you havelearned to restore the writing.Save your �nal workspace with the readable writing underthe name ipl95*/checkpoint/lab5/lab5 pro1.wksp.Z.


Recommended