Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture: Image manipulations (1)

Similar presentations


Presentation on theme: "Lecture: Image manipulations (1)"— Presentation transcript:

1 Lecture: Image manipulations (1)
Alireza Akhavan Pour CLASS.VISION سه شنبه - ۲۴ بهمن ۱۳۹۶

2 Image Manipulations (Part 1)
1. Transformations, affine and non affine 2. Translations 3. Rotations 4. Scaling, re-sizing and interpolations 5. Image Pyramids سه شنبه - ۲۴ بهمن ۱۳۹۶

3 Transformations Transformations – are geometric distortions enacted upon an image. We use transformations to correct distortions or perspective issues from arising from the point of view an image was captured. Types: • Affine • Non-Affine سه شنبه - ۲۴ بهمن ۱۳۹۶

4 Affine Transform تبدیل همگر یا تبدیل آفین یا Affine transformation نوعی تبدیل ریاضی است که هم ‌خطی‌بودن و نسبت فاصله‌ها در آن حفظ می‌شود. بدین ترتیب در نتیجه یک تبدیل همگر، تمامی نقاط روی یک خط در ورودی، در خروجی نیز روی یک خط خواهند ماند. با این وجود در تبدیل‌های همگر طول و زاویه بین خط‌ها لزوماً حفظ نمی‌شود. انتقال، تجانس، تشابه و چرخش نمونه‌هایی از تبدیل‌های همگر هستند. همچنین هر تبدیل خطی یک تبدیل همگر است، با این وجود هر تبدیل همگری خطی نیست. مثلث‌ها آفین یکدیگر هستند، به این معنی که هر مثلثی را می‌توان با استفاده از یک تبدیل آفین به هر مثلث دیگری تبدیل کرد. fa.wikipedia.org/wiki/تبدیل_آفین fa.wikipedia.org/wiki/تبدیل_آفین سه شنبه - ۲۴ بهمن ۱۳۹۶

5 Affine vs Non Affine Theory
Scaling Rotation Non-Affine or Projective Transform and also called Homography Translation سه شنبه - ۲۴ بهمن ۱۳۹۶

6 Vector A column vector where A row vector where
denotes the transpose operation سه شنبه - ۲۴ بهمن ۱۳۹۶

7 Vector We’ll default to column vectors in this class
You’ll want to keep track of the orientation of your vectors when programming in python You can transpose a vector V in python by writing V.t. (But in class materials, we will always use VT to indicate transpose, and we will use V’ to mean “V prime”) سه شنبه - ۲۴ بهمن ۱۳۹۶

8 Vectors have two main uses
Data (pixels, gradients at an image keypoint, etc) can also be treated as a vector Such vectors don’t have a geometric interpretation, but calculations like “distance” can still have value Vectors can represent an offset in 2D or 3D space Points are just vectors from the origin سه شنبه - ۲۴ بهمن ۱۳۹۶

9 Matrix A matrix is an array of numbers with size by , i.e. m rows and n columns. If , we say that is square. سه شنبه - ۲۴ بهمن ۱۳۹۶

10 = Images Python represents an image as a matrix of pixel brightnesses
Note that the upper left corner is [y,x] = (0,0) سه شنبه - ۲۴ بهمن ۱۳۹۶

11 Color Images Grayscale images have one number per pixel, and are stored as an m × n matrix. Color images have 3 numbers per pixel – red, green, and blue brightnesses (RGB) Stored as an m × n × 3 matrix = سه شنبه - ۲۴ بهمن ۱۳۹۶

12 Matrix Operations Addition Scaling
Can only add a matrix with matching dimensions, or a scalar. Scaling سه شنبه - ۲۴ بهمن ۱۳۹۶

13 Vectors Norm More formally, a norm is any function that satisfies 4 properties: Non-negativity: For all Definiteness: f(x) = 0 if and only if x = 0. Homogeneity: For all Triangle inequality: For all Definiteness: دارای حد مشخص wiki/نرم_(ریاضیات) سه شنبه - ۲۴ بهمن ۱۳۹۶

14 Matrix Operations Example Norms General norms: سه شنبه - ۲۴ بهمن ۱۳۹۶

15 Matrix Operations Inner product (dot product) of vectors
Multiply corresponding entries of two vectors and add up the result x·y is also |x||y|Cos( the angle between x and y ) سه شنبه - ۲۴ بهمن ۱۳۹۶

16 Matrix Operations Multiplication example:
Each entry of the matrix product is made by taking the dot product of the corresponding row in the left matrix, with the corresponding column in the right one. سه شنبه - ۲۴ بهمن ۱۳۹۶

17 Matrix Operations The product of two matrices سه شنبه - ۲۴ بهمن ۱۳۹۶

18 Matrix Operations Powers
By convention, we can refer to the matrix product AA as A2, and AAA as A3, etc. Obviously only square matrices can be multiplied that way سه شنبه - ۲۴ بهمن ۱۳۹۶

19 Matrix Operations Transpose – flip matrix, so row 1 becomes column 1
A useful identity: سه شنبه - ۲۴ بهمن ۱۳۹۶

20 Special Matrices Identity matrix I Diagonal matrix
Square matrix, 1’s along diagonal, 0’s elsewhere I ∙ [another matrix] = [that matrix] Diagonal matrix Square matrix with numbers along diagonal, 0’s elsewhere A diagonal ∙ [another matrix] scales the rows of that matrix سه شنبه - ۲۴ بهمن ۱۳۹۶

21 Transformation Matrices can be used to transform vectors in useful ways, through multiplication: x’= Ax Simplest is scaling: (Verify to yourself that the matrix multiplication works out this way) سه شنبه - ۲۴ بهمن ۱۳۹۶

22 Rotation How can you convert a vector represented in frame “0” to a new, rotated coordinate frame “1”? سه شنبه - ۲۴ بهمن ۱۳۹۶

23 Rotation How can you convert a vector represented in frame “0” to a new, rotated coordinate frame “1”? Remember what a vector is: [component in direction of the frame’s x axis, component in direction of y axis] سه شنبه - ۲۴ بهمن ۱۳۹۶

24 Rotation So to rotate it we must produce this vector: [component in direction of new x axis, component in direction of new y axis] We can do this easily with dot products! New x coordinate is [original vector] dot [the new x axis] New y coordinate is [original vector] dot [the new y axis] سه شنبه - ۲۴ بهمن ۱۳۹۶

25 Rotation Insight: this is what happens in a matrix*vector multiplication Result x coordinate is: [original vector] dot [matrix row 1] So matrix multiplication can rotate a vector p: سه شنبه - ۲۴ بهمن ۱۳۹۶

26 2D Rotation Matrix Formula
Counter-clockwise rotation by an angle  P’ y’ y P x’ x سه شنبه - ۲۴ بهمن ۱۳۹۶

27 سه شنبه - ۲۴ بهمن ۱۳۹۶

28 2D Translation P’ P t سه شنبه - ۲۴ بهمن ۱۳۹۶

29 Homogeneous system In general, a matrix multiplication lets us linearly combine components of a vector This is sufficient for scale, rotate, skew transformations. But notice, we can’t add a constant!  سه شنبه - ۲۴ بهمن ۱۳۹۶

30 Homogeneous system The (somewhat hacky) solution? Stick a “1” at the end of every vector: Now we can rotate, scale, and skew like before, AND translate (note how the multiplication works out, above) This is called “homogeneous coordinates” سه شنبه - ۲۴ بهمن ۱۳۹۶

31 Homogeneous system In homogeneous coordinates, the multiplication works out so the rightmost column of the matrix is a vector that gets added. Generally, a homogeneous transformation matrix will have a bottom row of [0 0 1], so that the result has a “1” at the bottom too. سه شنبه - ۲۴ بهمن ۱۳۹۶

32 2D Translation P’ P t سه شنبه - ۲۴ بهمن ۱۳۹۶

33 2D Translation using Homogeneous Coordinates
P x y tx ty P’ t P سه شنبه - ۲۴ بهمن ۱۳۹۶

34 2D Translation using Homogeneous Coordinates
P x y tx ty P’ t P سه شنبه - ۲۴ بهمن ۱۳۹۶

35 2D Translation using Homogeneous Coordinates
P x y tx ty P’ t P سه شنبه - ۲۴ بهمن ۱۳۹۶

36 2D Translation using Homogeneous Coordinates
P x y tx ty P’ t P سه شنبه - ۲۴ بهمن ۱۳۹۶

37 2D Translation using Homogeneous Coordinates
P x y tx ty P’ t t P سه شنبه - ۲۴ بهمن ۱۳۹۶

38 سه شنبه - ۲۴ بهمن ۱۳۹۶

39 Scaling P’ P سه شنبه - ۲۴ بهمن ۱۳۹۶

40 Gray-level interpolation
Nearest Neighbor Bilinear Interpolation Bicubic interpolation & Using Transformation matrix سه شنبه - ۲۴ بهمن ۱۳۹۶

41 Zooming and Shrinkage Zooming: increasing the resolution (size) of an image Shrinkage: decreasing the resolution of an image Example of zooming: we have an image of 500x500 pixels and we want to enlarge it to 750x750 Zooming has two steps: creation of new pixel locations and the assignment of gray levels to those locations. A simple way of zooming which works for increasing the size of an image by integer numbers is pixel replication. Gray level of each pixel in the enlarged image is set to the gray-level of its nearest pixel in the original image سه شنبه - ۲۴ بهمن ۱۳۹۶

42 Interpolation of Data Given a function at 4 points, how to “guess” values at other points? X’i are new points Guessing at the function values within the known range is called interpolation. Interpolation has great significance in general image/video processing. سه شنبه - ۲۴ بهمن ۱۳۹۶

43 Interpolation: Nearest Neighbor
1-D We assign f (xi’ )=f (xj) xj is the original point closest to xi’ The original function values The interpolated values 2-D x’ y’ Original point Interpolated point setting the pixel value on interpolated point to the pixel of closet image point 43 سه شنبه - ۲۴ بهمن ۱۳۹۶

44 Bilinear Interpolation
سه شنبه - ۲۴ بهمن ۱۳۹۶

45 bicubic interpolation
در روش برآورد مکعبی علاوه بر پیكسل‌های 4 طرف به 4 پیکسل اریب پیکسل مورد نظر نیز توجه می‌كند و حدس می‌زند كه مقدار پیكسل‌های جدید چه چیزی باید باشد. این الگوریتم بیشتر برای مواقعی مناسب است كه قصد بزرگ‌كردن یك تصویر را دارید. سه شنبه - ۲۴ بهمن ۱۳۹۶

46 Scaling Equation P’ sy y P y x sx x سه شنبه - ۲۴ بهمن ۱۳۹۶

47 Scaling Equation P’ sy y P y x sx x سه شنبه - ۲۴ بهمن ۱۳۹۶

48 Scaling Equation P’ sy y P y x sx x سه شنبه - ۲۴ بهمن ۱۳۹۶

49 Scaling & Translating P’=S∙P P’’=T∙P’ P’’=T ∙ P’=T ∙(S ∙ P)= T ∙ S ∙P
سه شنبه - ۲۴ بهمن ۱۳۹۶

50 منابع http://vision.stanford.edu/teaching/cs131_fall1718/
سه شنبه - ۲۴ بهمن ۱۳۹۶


Download ppt "Lecture: Image manipulations (1)"

Similar presentations


Ads by Google