Computer Vision Systems Lecture Notes PDF
Document Details

Uploaded by Aliamly90
Mohanad Qusay Abbood
Tags
Related
- COMP9517 Computer Vision 2024 Term 2 Week 2 Image Processing Part 1 PDF
- COMP9517 Computer Vision Image Segmentation Part 2 PDF
- Computer Vision - Lecture 1 - Introduction Overview PDF
- Introduction to Computer Vision - Fall 2024 - Toronto Metropolitan University PDF
- Introduction to Computer Vision PDF Fall 2024
- Week 2 Module 1: Introduction to Digital Image Processing PDF
Summary
These are lecture notes on Computer Vision Systems, specifically for CAD/CAM Engineering 4th Class. Topics covered include an introduction to computer vision, image processing, and computer graphics, with a focus on display devices like Cathode Ray Tubes (CRT) and line generation algorithms such as the Digital Differential Analyzer (DDA) algorithm.
Full Transcript
CAD/CAM Engineering – Computer Vision Systems – 4th Class Introduction What is Computer Vision? The goal of computer vision is to develop algorithms that allow computer to see. Computer Vision is sometimes called the inverse problem...
CAD/CAM Engineering – Computer Vision Systems – 4th Class Introduction What is Computer Vision? The goal of computer vision is to develop algorithms that allow computer to see. Computer Vision is sometimes called the inverse problem of computer graphics. — Also called: 1- Image understanding. 2- Image analysis. 3- Machine vision. What is Image Processing? Image processing is computer imaging where application involves a human being in the visual loop. In other words the image are to be examined and a acted upon by people. What is computer graphics? Computer graphics is an art of drawing pictures, lines, charts, etc. using computers with the help of programming. Computer graphics image is made up of number of pixels. Pixel is the smallest addressable graphical unit represented on the computer screen. Dr. Mohanad Qusay Abbood 1Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 1- Display devices Display devices are also known as output devices. Most commonly used output device in a graphics system is a video monitor. What is Cathode Ray Tube? The primary output device in a graphical system is the video monitor. The main element of a video monitor is the Cathode Ray Tube (CRT), shown in the following figure (1). Fig. (1): Cathode Ray Tube. Dr. Mohanad Qusay Abbood 2Page CAD/CAM Engineering – Computer Vision Systems – 4th Class The operation of CRT is very simple: 1- The electron gun emits a beam of electrons (cathode rays). 2- The electron beam passes through focusing and deflection systems that direct it towards specified positions on the phosphor-coated screen. 3- When the beam hits the screen, the phosphor emits a small spot of light at each position contacted by the electron beam. 4- It redraws the picture by directing the electron beam back over the same screen points quickly. 2- There are two techniques used for producing images on the CRT Screen: 1- Raster scan display 2- Vector scan / Random scan display. 1- Raster Scan In a raster scan system, the electron beam is swept across the screen, one row at a time from top to bottom. As the electron beam moves across each row, the beam intensity is turned on and off to create a pattern of illuminated spots. Picture definition is stored in memory area called the Refresh Buffer or Frame Buffer. This memory area holds the set of intensity Dr. Mohanad Qusay Abbood 3Page CAD/CAM Engineering – Computer Vision Systems – 4th Class values for all the screen points. Stored intensity values are then retrieved from the refresh buffer and “painted” on the screen one row (scan line) at a time as shown in the following figure (2). Each screen point is referred to as a pixel (picture element). At the end of each scan line, the electron beam returns to the left side of the screen to begin displaying the next scan line. Fig. (2): Raster Scan. 2- Random Scan (Vector Scan) In this technique, the electron beam is directed only to the part of the screen where the picture is to be drawn rather than scanning from left to right and top to bottom as in raster scan. It is also called vector display, stroke-writing display, or calligraphic display. Dr. Mohanad Qusay Abbood 4Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Fig. (3): Random Scan. Difference between Raster scan and Random scan Dr. Mohanad Qusay Abbood 5Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Line Generation Algorithm The Cartesian slop-intercept equation for a straight line is with "m" representing slop and "b" as the intercept. The two endpoints of the line are given which are say ( ) ( ). We can determine values for the slope m by equation: We can determine values for the intercept b by equation: For the given interval along a line, we can compute the corresponding y interval as: Dr. Mohanad Qusay Abbood 6Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Similarly : For line with slope | | , can be set proportional to small horizontal deflection voltage and the corresponding vertical deflection voltage is then set proportional to which is calculated from above equation. For line with slope | | , can be set proportional to small vertical deflection voltage and the corresponding horizontal deflection voltage is then set proportional to which is calculated from above equation. For line with slope and the horizontal and vertical deflection voltages are equal. Line Generation Algorithm A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line. In the following three algorithms: 1- Digital Differential Analyzer (DDA) algorithm. 2- Bresenham’s Line algorithm. 3- Mid-Point algorithm. Dr. Mohanad Qusay Abbood 7Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 1- Digital Differential Analyzer (DDA) algorithm. Digital Differential Analyzer (DDA) is scan conversion line drawing algorithm based on calculating either using above equation. We sample the line at unit intervals in one coordinate and find corresponding integer values nearest the line path for the other coordinate. Consider first a line with positive slope and slope is less than or equal to 1: We sample at unit x interval ( ) and calculate each successive y value as follow: ( ) In general ( ) ( ) Now write this equation in form: ( ( ) ) ( ( ) ) So that it is computed fast in computer as addition is fast compare to multiplication. Dr. Mohanad Qusay Abbood 8Page CAD/CAM Engineering – Computer Vision Systems – 4th Class In above equation k takes integer values starting from 1 and increase by 1 until the final endpoints is reached. As m can be any real number between 0 and 1, the calculated y values must be rounded to the nearest integer. Consider a case for a line with positive slope greater than 1: We change the role of x and y that is sample at unit y interval ( ) and calculate each succeeding x value as: ( ) (( ) ) In general (( ) ) (( ) ) Now write this equation in form: (( ) ) (( ) ) Above both equations are based on the assumption that lines are to be processed from left endpoint to right endpoint. If we processed line from right endpoint to left endpoint than: Dr. Mohanad Qusay Abbood 9Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Above calculated equations also used to calculate pixel position along a line with negative slope. Advantages of DDA algorithm 1- It is faster algorithm. 2- It is simple algorithm. Disadvantages of DDA algorithm 1- Floating point arithmetic is time consuming. 2- Poor end point accuracy. Examples of DDA Algorithm Remember the steps If slope (m) is less than 1 (m < 1) then increment x as x1+1 and calculate y as y1= y1 + m. If slope (m) is greater than 1 (m > 1) then increment y as y1+1 and calculate x as. If slope (m) is equal to 1 (m = 1) then increment both x and y. ,. Dr. Mohanad Qusay Abbood 10Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 1: Draw a line from (1, 1) to (8, 7) using DDA algorithm? Solution: Step 1: Step 2: As is less than 1 therefore x is increased and y is Step 3: calculated. Step 4: The step will. The points generated would be Step 5: So. S. No. Pixel Plotted 1 1 1 ( ) 2 2 1.86 ( ) ( ) 3 3 4 4 ( ) 5 5 ( ) 6 6 ( ) 7 7 ( ) 8 8 ( ) Dr. Mohanad Qusay Abbood 11Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 12Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 2: Draw a line from (0, 0) to (4, 6) using DDA algorithm? Solution: Step 1: Step 2: As is more than 1 therefore y is increased and x is Step 3: calculated. Step 4: The step will. The points generated would be Step 5: So. S. No. Pixel Plotted 1 0 0 ( ) ( ) 2 1 3 2 ( ) 4 3 ( ) 5 4 ( ) 6 5 ( ) 7 6 ( ) Dr. Mohanad Qusay Abbood 13Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 14Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 3: Draw a line from (0, 0) to (7, 7) using DDA algorithm? Solution: Step 1: Step 2: As therefore x will be increased by 1 and y will be Step 3: increased by 1. Step 4: The step will. The points generated would be. Step 5: So. This would be a 45 degree line where x and y both have equal incremented value. S. No. Pixel Plotted 1 0 0 ( ) 2 1 ( ) 3 2 ( ) 4 3 ( ) 5 4 ( ) 6 5 ( ) 7 6 ( ) 8 7 ( ) Dr. Mohanad Qusay Abbood 15Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 16Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 4: Draw a line from (2, 3) to (9, 8) using DDA algorithm? Solution: Step 1: Step 2: As is less than 1 therefore x is increased and y is Step 3: calculated. Step 4: The step will. The points generated would be Step 5: So. S. No. Pixel Plotted 1 2 3 ( ) ( ) 2 3 3 4 ( ) 4 5 ( ) 5 6 ( ) 6 7 ( ) 7 8 ( ) 8 9 ( ) Dr. Mohanad Qusay Abbood 17Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 18Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 2-Bresenham’s Line Algorithm An accurate and efficient raster line-generating algorithm, developed by Bresenham which scan converts line using only incremental integer calculations that can be modified to display circles and other curves. Dr. Mohanad Qusay Abbood 19Page CAD/CAM Engineering – Computer Vision Systems – 4th Class To illustrate bresenham’s approach, we first consider the scan- conversion process for lines with positive slope less than 1. Pixel positions along a line path are then determined by sampling at unit x intervals. Starting from left endpoint ( ) of a given line, we step to each successive column and plot the pixel whose scan-line y values is closed to the line path. Assuming we have determined that the pixel at ( ) is to be displayed, we next need to decide which pixel to plot in column. Our choices are the pixels at positions ( ) and ( ). Let’s see mathematical calculation used to decide which pixel position is light up. We know that equation of line is Now for position ( ) Now calculate distance between actual line’s y value and lower pixel as and distance between actual line’s y value and upper pixel as. Dr. Mohanad Qusay Abbood 20Page CAD/CAM Engineering – Computer Vision Systems – 4th Class ( ) …1 ( ) ( ) ( ) …2 Now calculate from equation (1) and (2). ( ) (( ) ) [ ( ) ] [( ) ( ) ] [ ] [ ] ( ) …3 Now substitute in equation (3). ( )( ) …4 Now we have decision parameter for step in the line algorithm is given by: ( ) ( ( )( ) ) …5 ( ) …6 Dr. Mohanad Qusay Abbood 21Page CAD/CAM Engineering – Computer Vision Systems – 4th Class The sign of is the same as the sign of for our example. Parameter C is constant which is independent of pixel position and will eliminate in the recursive calculation for. Now if is negative then we plot the lower pixel otherwise we plot the upper pixel. So successive decision parameters using incremental integer calculation as: Now subtract from ( ) ( ) ( ) ( ) Where the terms is either 0 or 1, depends on the sign of parameter. This recursive calculation of decision parameters is performed at each integer x position starting at the left coordinate endpoint of the line. The first decision parameter is calculated using equation (5) as first time we need to take constant part into account so: Dr. Mohanad Qusay Abbood 22Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Now substitute ( ) Now substitute ( ( ) ) Dr. Mohanad Qusay Abbood 23Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 1: Draw a line from (2, 3) to (5, 8) using Bresenham’s algorithm? Solution: Step 1: Step 2: Step 3: Calculate Step 4: We will increase y by 1 and calculate x. a) If then and with new ( ) b) If then and with new Note: y is always increasing. S. No. d Pixel Plotted 1 2 3 ( ) 2 3 4 ( ) ( ) ( ) 3 3 5 ( ) ( ) 4 4 6 ( ) ( ) ( ) 5 4 7 ( ) ( ) 6 5 8 ( ) ( ) ( ) Dr. Mohanad Qusay Abbood 24Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 25Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 2: Draw a line from (1, 1) to (8, 7) using Bresenham’s algorithm? Solution: Step 1: Step 2: Step 3: Calculate Step 4: We will increase x by 1 and calculate y. a) If then and with new ( ) b) If then and with new S. No. d Pixel Plotted 1 1 1 ( ) 2 2 2 ( ) ( ) ( ) 3 3 3 ( ) ( ) ( ) 4 4 4 ( ) ( ) ( ) 5 5 4 ( ) ( ) 6 6 5 ( ) ( ) ( ) 7 7 6 ( ) ( ) ( ) 8 8 7 ( ) ( ) ( ) Dr. Mohanad Qusay Abbood 26Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 27Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 3- Mid-Point Line Generation Algorithm Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van Aken. Basic of algorithm: Given the previous pixel P, there are two candidates for the next pixel closed to the line, E and NE. If the M is above the line, choose E. If M is below the line, choose NE. Previous pixel Choices for current Previous pixel Choices for current pixel pixel Derivation: Assumptions: Two end points of a line: ( ) and ( ), also Since, we are sampling in x-direction, so, for the next pixel, x- coordinate will be i.e. and correspondingly we will calculate the value of y-coordinate. Dr. Mohanad Qusay Abbood 28Page CAD/CAM Engineering – Computer Vision Systems – 4th Class The implicit equation of a line is: ( ) …1 Slope intercept form a line is: ( ) ( ) ( ) ( ) …2 Comparing (1) and (2) we: For all points on the line, the solution to ( ) is 0. For all points above the line ( ) result in a negative number. For all points below the line ( ) result in a positive number. The relationship is used to determine the relative position of M. ( ) ( ) ( ) The sign of the decision variable "d" is used to make the midpoint determination for all remaining pixels. If d is negative, the midpoint is above the line and E is chosen i.e. ( ) will be plotted. If d is positive, the midpoint is below the line and NE is chosen i.e. ( ) will be plotted. Dr. Mohanad Qusay Abbood 29Page CAD/CAM Engineering – Computer Vision Systems – 4th Class As the algorithm progresses from pixel to pixel, d is calculated with one of two pre-calculated values based on the E/NE decision. Case 1: If E is chosen ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) Therefore, Dr. Mohanad Qusay Abbood 30Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Case 2: If NE is chosen ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) Therefore, Derivation for calculating the initial value for ( ) ( ) ( ) Dr. Mohanad Qusay Abbood 31Page CAD/CAM Engineering – Computer Vision Systems – 4th Class ( ) ( ) Therefore, Algorithm (| | ) Step 1:. Step 2: Calculate Step 3: Calculate Step 4: a) If then and with new ( ) b) If then and with new Algorithm (| | ) Step 1:. Step 2: Calculate Step 3: Calculate Step 4: a) If then and with new ( ) b) If then and with new Dr. Mohanad Qusay Abbood 32Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 1: Draw a line from (4, 8) to (9, 12) using Midpoint algorithm? Solution: Step 1: Step 2: Step 3: Calculate Step 4: a) If then and with new ( ) b) If then and with new S. No. d Pixel Plotted 1 4 8 ( ) 2 5 9 ( ) ( ) ( ) 3 6 10 ( ) ( ) ( ) 4 7 10 ( ) 5 8 11 ( ) ( ) ( ) 6 9 12 ( ) ( ) ( ) Dr. Mohanad Qusay Abbood 33Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 13 12 11 10 9 8 7 6 5 4 3 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 34Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 2: Draw a line from (1, 2) to (5, 8) using Midpoint algorithm? Solution: Step 1: Step 2: Step 3: Calculate Step 4: a) If then and with new ( ) b) If then and with new S. No. d Pixel Plotted 1 1 2 ( ) 2 2 3 ( ) ( ) ( ) 3 2 4 ( ) 4 3 5 ( ) ( ) ( ) 5 4 6 ( ) ( ) ( ) 6 4 7 ( ) 7 5 8 ( ) ( ) ( ) Dr. Mohanad Qusay Abbood 35Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 01 9 8 7 6 5 4 3 2 0 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 36Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Circle Generation Algorithm 8-Way Symmetry for Circle The most important thing in drawing a circle is learning how the circle is drawn using 8-way symmetry. It is based on Mirror reflection. If we see Right hand in the mirror we will see Left hand, Similarly if we see pixel ( ) in mirror we will see ( ). Let's understand more how these negative signs are taken. Remember following two things: 1-If we mirror reflect ( ) with respect to x-axis then y will change so it will become ( ). Similarly if we reflect point ( ) with respect to y-axis x will change, so the point will become ( ). 2-Read Point ( ) as: x is on x position and y is on y position, so when we reflect with respect to x-axis then y position becomes negative and with respect to y-axis x position becomes negative. Take this logic and reflection of point ( ) with respect to y-axis will make the x position negative and not where x is written, so it will become ( ). Dr. Mohanad Qusay Abbood 37Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 8-Way Symmetry Diagram Another explanation of the same concept This explains the same concept using quadrant. We all know there are four quadrants and First quadrant x and y both are positive. Second quadrant y is positive and x is negative (which is nothing but reflection with respect to y-axis). Third quadrant both x and y are negative. Forth quadrant y is negative and x is positive (which is reflection with respect to x-axis). Dr. Mohanad Qusay Abbood 38Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Take the following points and apply the previous logic Take a point ( ) in first quadrant. Mirror reflect point ( ) with respect to y-axis we will get another point called ( ). Mirror reflect point ( ) with respect to x-axis we will get another point called ( ). Mirror reflect point ( ) with respect to x-axis we will get another point called ( ). Take a point ( ) in first quadrant. Mirror reflect point ( ) with respect to y-axis we will get another point called ( ). Mirror reflect point ( ) with respect to x-axis we will get another point called ( ). Mirror reflect point ( ) with respect to x-axis we will get another point called ( ). Notice that 8-way symmetry generates 8 points by taking only one point ( ) and this forms the circle. Dr. Mohanad Qusay Abbood 39Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Circle Generation Algorithm Drawing a circle on the screen is a little complex than drawing a line. There are two popular algorithms for generating a circle: Bresenham’s Algorithm and Midpoint Circle Algorithm. These algorithms are based on the idea of determining the subsequent points required to draw the circle. 1- Bresenham’s Algorithm Step 1: Enter the center ( ) and radius ( ) of the circle Find and take Step 2: Where is nothing but the radius of the circle If ( ) then and Step 3: ( ) We called d as decision variable If ( ) then and Step 4: Just use the 8-way symmetry and plot following 8 points Step 5: with one point. Put pixel ( ) Put pixel ( ) Put pixel ( ) Put pixel( ) Put pixel ( ) Put pixel ( ) Put pixel( ) Put pixel( ) Step 6: Go to step 3 and repeat till √ Dr. Mohanad Qusay Abbood 40Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 1: Draw a circle using Bresenham’s Algorithm having radius as 10 and center of circle (100, 100). Solution: Step 1: Enter the center Step 2: Find ( ) and take If ( ) then and Step 3: ( ) If ( ) then and Step 4: Where to stop: √ √ So either x or y reaches 7, the algorithm will stop. S. Pixel Plotted d No. ( ) 1 0 10 ( ) ( ) 2 1 10 ( ) ( ) 3 2 10 ( ) ( ) 4 3 9 ( ) ( ) ( ) 5 4 9 ( ) ( ) 6 5 8 ( ) ( ) ( ) 7 6 7 ( ) ( ) ( ) Rest of the points will be plotted using 8-way symmetry. Dr. Mohanad Qusay Abbood 41Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 110 019 018 017 016 015 014 013 012 010 100 100 101 102 103 104 105 106 107 108 109 110 Dr. Mohanad Qusay Abbood 42Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 2- Midpoint circle algorithm Step 1: Enter the center ( ) and radius ( ) of the circle Step 2: Find and take as starting point If ( ) then and Step 3: ( ) If ( ) then and Step 4: Step 5: Stop when either x or y reaches √ Step 6: All the other points would be generated by 8-way symmetry. Example 2: Draw a circle using Midpoint Algorithm having radius as 10 and center of circle (100, 100). Solution: Step 1: Enter the center Step 2: Find and take If ( ) then and Step 3: ( ) If ( ) then and Step 4: Where to stop: √ √ So either x or y reaches 7, the algorithm will stop. Dr. Mohanad Qusay Abbood 43Page CAD/CAM Engineering – Computer Vision Systems – 4th Class S. Pixel Plotted d No. ( ) 1 0 10 ( ) 2 1 10 ( ) ( ) 3 2 10 ( ) ( ) 4 3 9 ( ) ( ) ( ) 5 4 9 ( ) ( ) 6 5 8 ( ) ( ) ( ) 7 6 7 ( ) ( ) ( ) Rest of the points will be plotted using 8-way symmetry. 110 019 018 017 016 015 014 013 012 010 100 100 101 102 103 104 105 106 107 108 109 110 Dr. Mohanad Qusay Abbood 44Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 3: Draw a circle using Midpoint Algorithm with radius 5. Solution: Step 1: Enter the center Step 2: Find and take If ( ) then and Step 3: ( ) If ( ) then and Step 4: Where to stop: √ √ So either x or y reaches 3, the algorithm will stop. S. Pixel Plotted d No. ( ) 1 0 5 ( ) 2 1 5 ( ) ( ) 3 2 4 ( ) ( ) ( ) 4 3 3 ( ) ( ) ( ) Rest of the points will be plotted using 8-way symmetry. Dr. Mohanad Qusay Abbood 45Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 10 9 8 7 6 5 4 3 2 0 0 0 1 2 3 4 5 6 7 8 9 10 Dr. Mohanad Qusay Abbood 46Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Windowing & Viewing Operations Windowing: When drawings are too complex, they become difficult to read. In such situation, it is useful to display only those portions of the drawings that are of interest. This gives the effect of locking at the image through a window. It is desirable to zoom in on these portions. The technique of selecting and enlarging portions of a drawing is called windowing. Viewing Operations Views are defined by the various angles from which the object can be observed. The most common views required to represent the object details are: Isometric view, Top view, Left side view and Right side view. In order to accommodate the display of several views simultaneously, the display screen is divided into viewports. The screen layout with four viewports is shown below. Dr. Mohanad Qusay Abbood 47Page CAD/CAM Engineering – Computer Vision Systems – 4th Class A window to viewport mapping can be expressed in the following relations: Dr. Mohanad Qusay Abbood 48Page CAD/CAM Engineering – Computer Vision Systems – 4th Class ( )( ) ( )( ) ( ) ( ) ( ) ( ) In matrix form [ ] [ ][ ] Where: Dr. Mohanad Qusay Abbood 49Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 1: Find the normalization transformation matrix which maps the rectangular A(1,0), B(4,3), C(3,4), D(0,1) to the normalized viewport defined by (0,0) and (1,1) and window defined by (0,0) and (5,5). Sol: ( ) ( ) [ ] [ ][ ] [ ] [ ] Dr. Mohanad Qusay Abbood 50Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 2: What is the viewport coordinating of the point (3.4, 1.2) in world coordinate (WCS). If W=(0,4,0,2) , V=(60,380,80,240). Sol: ( ) ( ) [ ] [ ][ ] [ ] [ ][ ] [ ] [ ] Dr. Mohanad Qusay Abbood 51Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 3: A circle has (2mm) radius and (0,0) center in WCS. The W(-2,2,-2,2) and V(0,100,0,50) What is the new shape. Sol: ( ) ( ) ( ) ( ) ( ) ( ) [ ] [ ][ ] [ ] [ ][ ] [ ] [ ] The new shape is ellipse Dr. Mohanad Qusay Abbood 52Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Clipping Clipping is the process of extracting a portion of an object. The process of clipping determines which elements of the picture lie inside the window and so are visible. The Cohen-Sutherland algorithm works well for the lines. It provides an efficient procedure for finding the category of line segment. The algorithm proceeds in two steps: 1- Assign a four-bit code to each end point of the line segment. The code is determined according to which of the following nine regions of the plane the endpoint lies in Dr. Mohanad Qusay Abbood 53Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Starting from the left most bit, each bit of the code is set to true (1) or false (0) according to the scheme: Bit 1 = end point is above the window = sign ( ) Bit 2 = endpoint is below the window = sign ( ) Bit 3 = endpoint is to the right the window = sign ( ) Bit 4 = endpoint is to the left the window = sign ( ) The convention is that sign ( ) if a is positive, and is (0) otherwise. A point with code (0000) is inside the window. 2- The line segment is visible if both endpoint codes are (0000), not visible if the logical AND of the codes is not (0000), and a candidate for clipping if the logical AND of the endpoint codes is (0000) Dr. Mohanad Qusay Abbood 54Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 1: A window is defined as (20, 20), (90, 70) in the (WCS), a line segment bounded by (20, 10) and (100, 60). 1-Determine the logical AND of the endpoints bit codes. 2-Determine the clipping boundaries of the line segment. 3- Assuming that the viewport is defined by (30, 20) and (90, 60) find the viewport coordinates for the intersection point. Sol: 1- The line AB is determined by: A(20,10), B(100,60) x y Bit1 Bit2 Bit3 Bit4 A 20 10 0 1 0 0 B 100 60 0 0 1 0 Logical AND 0 0 0 0 Dr. Mohanad Qusay Abbood 55Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 2- Clipping the line ( )( ) ( ) ( )( ) ( ) ( ) First intersection point ( ) To find the second intersection point at: ( ) Second intersection point is ( ) 3- Dr. Mohanad Qusay Abbood 56Page CAD/CAM Engineering – Computer Vision Systems – 4th Class ( ) ( ) ( ) ( ) [ ] [ ][ ] [ ] [ ] [ ] [ ] [ ] Dr. Mohanad Qusay Abbood 57Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Example 2: A window is defined as (-10, 10), (60, 60) in the (WCS), a line segment bounded by (-20, 0) and (70, 90). 1- Determine the logical AND of the endpoints bit codes. 2- Determine the clipping boundaries of the line segment. 3- Assuming that the viewport is defined by (10, 10) and (50, 60) find the viewport coordinates for the intersection point. Sol: 1- The line AB is determined by: A(-20, 0), B(70, 90) x y Bit1 Bit2 Bit3 Bit4 A -20 0 0 1 0 1 B 70 90 1 0 1 0 Logical AND 0 0 0 0 2- Clipping the line ( )( ) ( ) ( )( ) ( ) The first case y = 10 at the first intersection point. ( ) Dr. Mohanad Qusay Abbood 58Page CAD/CAM Engineering – Computer Vision Systems – 4th Class The second case x = -10 at the first intersection point. ( ) First intersection point ( ) To find the second intersection point. The first case y = 60 at the second intersection point. ( ) The second case x = 60 at the second intersection point. ( ) The second case is wrong because the max.. Therefore, the second intersection point is ( ) Dr. Mohanad Qusay Abbood 59Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 3- ( ) ( ) ( ) ( ) ( ) [ ] [ ][ ] [ ] [ ] [ ] [ ] [ ] Dr. Mohanad Qusay Abbood 60Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Processing Image processing is computer imaging where application involves a human being in the visual loop. In other words the image are to be examined and a acted upon by people. The major topics within the field of image processing include: 1. Image restoration. 2. Image enhancement. 3. Image compression. 1- Image Restoration Is the process of taking an image with some known, or estimated degradation, and restoring it to its original appearance. Image restoration is often used in the field of photography or publishing where an image was somehow degraded but needs to be improved before it can be printed. Image with distortion Restored image Dr. Mohanad Qusay Abbood 61Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 2- Image Enhancement Involves taking an image and improving it visually, typically by taking advantages of human Visual Systems responses. One of the simplest enhancement techniques is to simply stretch the contrast of an image. Enhancement methods tend to be problem specific. For example, a method that is used to enhance satellite images may not suitable for enhancing medical images. Image with poor contrast Image enhancement by contrast stretching 3- Image Compression Involves reducing the typically massive amount of data needed to represent an image. This done by eliminating data that are visually unnecessary and by taking advantage of the redundancy that is inherent in most images. Image data can be reduced 10 to 50 times, and motion image data (video) can be reduced by factors of 100 or even 200. Dr. Mohanad Qusay Abbood 62Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image before compression Image after compression (92) KB (6.59)KB The image can now be accessed as a two-dimension array of data, where each data point is referred to a pixel (picture element). For digital images we will use the following notation: ( ) ( ) Where: “When we have the data in digital form, we can use the software to process the data”. The digital image is 2D- array as: Dr. Mohanad Qusay Abbood 63Page CAD/CAM Engineering – Computer Vision Systems – 4th Class In above image matrix, the image size is (NXN) [matrix dimension] Where: : denotes the number of gray levels. : is the no. of bits contains in digital image matrix. Example 1: If we have (6 bit) in 128 X 128 image. Find the no. of gray levels to represent it, then find the no. of bit in this image? Sol: Example 2: If we have (8 bit) in 256 X 256 image. Find the no. of gray levels to represent it, then find the no. of bit in this image? Sol: Example 3: Find the number of gray level, and the number of bit for (512 × 512) image, note that the image contains 8 bit / pixel? Dr. Mohanad Qusay Abbood 64Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Resolution Pixels are the building blocks of every digital image. Clearly defined squares of light and color data are stacked up next to one another both horizontally and vertically. Each picture element (pixel for short) has a dark to light value from 0 (black) to 255 (white). That is, there are 256 defined values. In computers, resolution is the number of pixels (individual points of color) contained on a display monitor, expressed in terms of the number of pixels on the horizontal axis and the number on the vertical axis. The sharpness of the image on a display depends on the resolution and the size of the monitor. The same pixel resolution will be sharper on a smaller monitor and gradually lose sharpness on larger monitors because the same numbers of pixels are being spread out over a larger number of inches. A display with 240 pixel columns and 320 pixel rows would generally be said to have a resolution of 240*320. Resolution can also be used to refer to the total number of pixels in a digital camera image. For example, a camera that can create images of 1600*1200 pixels will sometimes be referred to as a 2 megapixel resolution camera since 1600*1200 = 1,920,000 pixels, or roughly 2 million pixels. Below is an illustration of how the same image might appear at different pixel resolutions. Dr. Mohanad Qusay Abbood 65Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Representation The image types we will consider are: 1- Binary Image Binary images are the simplest type of images and can take on two values, typically black and white, or ‘0’ and ‘1’. A binary image is referred to as a 1 bit/pixel image because it takes only 1 binary digit to represent each pixel. Binary images are often created from gray-scale images via a threshold value is, those values above it are turned white (‘1’), and those below it are turned black (‘0’). Dr. Mohanad Qusay Abbood 66Page CAD/CAM Engineering – Computer Vision Systems – 4th Class 2- Gray Scale Image Gray _scale images are referred to as monochrome, or one-color image. They contain brightness information only, no color information. The number of different brightness level available. The typical image contains 8 bit/ pixel (data, which allows us to have (0-255) different brightness (gray) levels. The 8 bit representation is typically due to the fact that the byte, which corresponds to 8-bit of data, is the standard small unit in the world of digital computer. 3- Color Image Color image can be modeled as three band monochrome image data, where each band of the data corresponds to a different color. The actual information stored in the digital image data is brightness information in each spectral band. When the image is displayed, the corresponding brightness information is displayed on the screen by picture elements that emit light energy corresponding to that particular color. Dr. Mohanad Qusay Abbood 67Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Typical color images are represented as red, green, and blue or RGB images using the 8-bit monochrome standard as a model, the corresponding color image would have 24 bit/pixel – 8 bit for each color bands (red, green and blue). The following figure we see a representation of a typical RGB color image. 4- Multispectral Images A multispectral image is one that captures image data at specific frequencies across the electromagnetic spectrum. Multispectral images typically contain information outside the normal human perceptual range. This may include infrared, ultraviolet, X-ray, acoustic or radar data. Source of these types of image include satellite systems, underwater sonar systems and medical diagnostics imaging systems. Dr. Mohanad Qusay Abbood 68Page CAD/CAM Engineering – Computer Vision Systems – 4th Class CMY & RGB Color Model 1- RGB Color Model Three colors we can obtain wide range of color this concept is used in RGB color model. This model is represented as unit cube. Origin represent black color and vertex (1,1,1) is white. Vertex of the cube on the axis represents primary color R, G, and B. This color model is used in computer monitors, television sets, LCD, and LED. The Red, Green, and Blue (RGB) color model is an additive color model for displays. Additive color model means is that where we can combine these three basic colors in various ways to get a new color. When we will combine Dr. Mohanad Qusay Abbood 69Page CAD/CAM Engineering – Computer Vision Systems – 4th Class R, G, B is of 8-bit each. Thus maximum possible range by individual is 0-255 ( ) 2- CMY Color Model The CMYK color model is designed to support color printing on White paper. The CMYK color model is termed as a subtractive color model in which the starting point begins with a White or light surface. Color pigments reduce the reflection of the original White light. The color inks thus subtract from the original White surface. Typical output devices for the CMYK color model include color inkjet, laser, and dye-sublimation printers. Each device has its own particular technology for color image reproduction. Represent by value only 0 or 1. 0 = no color. 1 = full color. Dr. Mohanad Qusay Abbood 70Page CAD/CAM Engineering – Computer Vision Systems – 4th Class CMY color model Dr. Mohanad Qusay Abbood 71Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Examples of RGB ( ) ( ) ( ) ( ) ( ) ( ) Examples of CMY ( ) ( ) ( ) Difference between RGB and CMY RGB is an additive type of color mode that combines the primary colors: Red, Green, and Blue in various levels to create a variety of different colors. Dr. Mohanad Qusay Abbood 72Page CAD/CAM Engineering – Computer Vision Systems – 4th Class CMYK is a four-color model that utilizes the colors Cyan, Magenta, Yellow, and Black in various amounts to create all of the necessary colors. RGB is vibrant. Whereas CMYK is not vibrant but good for reading. In RGB, when all three colors are combined and displayed to their full extent, the result is a pure white. In CMYK, when the first three colors are added together, the result is not pure black, but rather a very dark brown. RGB is the typical color model used on electronic devices such as computers, theaters etc. CMYK is the primary color model used by color printers. Simple relation between RGB and CMY [ ] [ ] [ ] [ ] Dr. Mohanad Qusay Abbood 73Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Processing with Matlab Image Read (imread) imread ('PictureName.jpg') Image Show (imshow) imshow (PictureName) Example: >> a = imread(‘color.jpg'); >> imshow(a) Image Save (imwrite) >> imwrite (a, 'color_out.jpg') Dr. Mohanad Qusay Abbood 74Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Size (size) size (PictureName) >> a = imread ('color.jpg'); >> imshow (a) >> b = size (a) b= 248 572 3 Binary image (im2bw) im2bw (PictureName) >> a = imread ('color.jpg'); >> b = im2bw (a); >> imshow (b) >> size (b) ans = 248 572 Dr. Mohanad Qusay Abbood 75Page CAD/CAM Engineering – Computer Vision Systems – 4th Class RGB image to Gray Image (rgb2gray) rgb2gray (PictureName) >> a = imread ('color.jpg'); >> b = rgb2gray (a); >> imshow (b) Image Resize (imresize) clc a=imread('lena.jpg'); subplot(1,2,1) imshow(a) b=imresize(a,0.4) subplot(1,2,2) imshow(b) Dr. Mohanad Qusay Abbood 76Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Resize (imresize) clc a=imread('lena.jpg'); subplot(1,3,1) imshow(a) b=imresize(a,0.4) subplot(1,3,2) imshow(b) c=imresize(a,3) subplot(1,3,3) imshow(c) Dr. Mohanad Qusay Abbood 77Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Crop (imcrop) clc a=imread('lena.jpg'); subplot(1,2,1) imshow(a) b=imcrop(a,[0 0 200 100]) subplot(1,2,2) imshow(b) c=size(a) d=size(b) c= 266 267 3 d= 100 200 3 Dr. Mohanad Qusay Abbood 78Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Translate (imtranslate) clc a=imread('lena.jpg'); b=imtranslate(a,[20,50]) subplot(1,2,1) imshow(a) subplot(1,2,2) imshow(b) Dr. Mohanad Qusay Abbood 79Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Rotation (imrotate) clc a=imread('lena.jpg'); subplot(1,3,1) imshow(a) b=imrotate(a,30) subplot(1,3,2) imshow(b) c=imrotate(a,45) subplot(1,3,3) imshow(c) Dr. Mohanad Qusay Abbood 80Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Reflection (x-axis) clc a=imread('lena.jpg'); tform = affine2d([1 0 0;0 -1 0;0 0 1]) b = imwarp(a, tform) subplot(1,2,1) imshow(a) subplot(1,2,2) imshow(b) Dr. Mohanad Qusay Abbood 81Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Reflection (y-axis) clc a=imread('lena.jpg'); tform = affine2d([-1 0 0;0 1 0;0 0 1]) b = imwarp(a, tform) subplot(1,2,1) imshow(a) subplot(1,2,2) imshow(b) Dr. Mohanad Qusay Abbood 82Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Reflection (origin) clc a=imread('lena.jpg'); tform = affine2d([-1 0 0;0 -1 0;0 0 1]) b = imwarp(a, tform) subplot(1,2,1) imshow(a) subplot(1,2,2) imshow(b) Dr. Mohanad Qusay Abbood 83Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Scale (immultiply) clc a=imread('lena.jpg'); b = immultiply(a, 0.5) c = immultiply(a, 2) subplot(1,3,1) imshow(a) subplot(1,3,2) imshow(b) subplot(1,3,3) imshow(c) Dr. Mohanad Qusay Abbood 84Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Add (imadd) clc a = imread('p1.jpg'); b = imread('p2.jpg'); c = imadd(a,b) subplot(1,3,1) imshow(a) subplot(1,3,2) imshow(b) subplot(1,3,3) imshow(c) Dr. Mohanad Qusay Abbood 85Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Image Subtract (imsubtract) clc a = imread('p1.jpg'); b = imread('p2.jpg'); c = imsubtract(a,b) subplot(1,3,1) imshow(a) subplot(1,3,2) imshow(b) subplot(1,3,3) imshow(c) Dr. Mohanad Qusay Abbood 86Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Area of objects in binary image (bwarea) clc a = imread('r.jpg'); b = im2bw(a); c = bwarea(b) subplot(1,2,1) imshow(a) subplot(1,2,2) imshow(b) c= 3.7036e+04 Dr. Mohanad Qusay Abbood 87Page CAD/CAM Engineering – Computer Vision Systems – 4th Class Case Study (Edge Detection) a=imread('shape.jpg'); subplot (3,2,1); imshow(a); title('Input Image'); b=rgb2gray(a) subplot (3,2,2); imshow(b); title('Gray Image'); c=im2bw(a) subplot (3,2,3); imshow(c); title('Binary Image'); d=edge(c,'canny'); subplot (3,2,4); imshow(d); title('Canny edge detection'); e=edge(c,'sobel'); subplot (3,2,5); imshow(e); title('Sobel edge detection'); f=edge(c,'prewitt'); subplot (3,2,6); imshow(f); title('Prewitt edge detection'); Dr. Mohanad Qusay Abbood 88Page