This commit is contained in:
Zheyuan Wu
2025-04-02 10:50:56 -05:00
parent b670a229f0
commit d459dfcf1c
5 changed files with 337 additions and 1 deletions

View File

@@ -0,0 +1,147 @@
# CSE332S Lecture 17
## Object Oriented Programming Building Blocks
OOP Building Blocks for Extensible, Flexible, and Reusable Code
Today: Techniques Commonly Used in Design Patterns
- **Program to an interface** (last time)
- **Object composition and request forwarding** (today)
- Composition vs. inheritance
- **Run-time relationships between objects** (today)
- Aggregate vs. acquaintance
- **Delegation** (later...)
Next Time: Design Patterns
Describe the core of a repeatable solution to common design problems.
### Code Reuse: Two Ways to Reuse a Class
#### Inheritance
Code reuse by inheriting the implementation of a base class.
- **Pros:**
- Inheritance relationships defined at compile-time - simple to understand.
- **Cons:**
- Subclass often inherits some implementation from superclass - derived class now depends on its base class implementation, leading to less flexible code.
#### Composition
Assemble multiple objects together to create new complex functionality, forward requests to the responsible assembled object.
- **Pros:**
- Allows flexibility at run-time, composite objects often constructed dynamically by obtaining references/pointers to other objects (dependency injection).
- Objects known only through their interface - increased flexibility, reduced impact of change.
- **Cons:**
- Code can be more difficult to understand, how objects interact may change dynamically.
### Example: Our First Design Pattern (Adapter Pattern)
**Problem:** We are given a class that we cannot modify for some reason - it provides functionality we need, but defines an interface that does not match our program (client code).
**Solution:** Create an adapter class, adapter declares the interface needed by our program, defines it by forwarding requests to the unmodifiable object.
Two ways to do this:
```cpp
class unmodifiable {
public:
int func(); // does something useful, but doesnt match the interface required by the client code
};
```
1. **Inheritance**
```cpp
// Using inheritance:
class adapter : protected unmodifiable {
// open the access to the protected member func() for derived class
public:
int myFunc() {
return func(); // forward request to encapsulated object
}
};
```
2. **Composition**
```cpp
class adapterComp {
unmodifiable var;
public:
int myFunc() {
return var.func();
}
};
```
### Thinking About and Describing Run-time Relationships
Typically, composition is favored over inheritance! Object composition with programming to an interface allows relationships/interactions between objects to vary at run-time.
- **Aggregate:** Object is part of another. Its lifetime is the same as the object it is contained in. (similar to base class and derived class relationship)
- **Acquaintance:** Objects know of each other, but are not responsible for each other. Lifetimes may be different.
```cpp
// declare Printable Interface
// declare printable interface
class printable {
public:
virtual void print(ostream &o) = 0;
};
// derived classes defines printable
// interface
class smiley : public printable {
public:
virtual void print(ostream &o) {
o << ":)";
};
};
// second derived class defines
// printable interface
class frown : public printable {
public:
virtual void print(ostream &o) {o << ":(";
};
};
```
1. **Aggregate**
```cpp
// implementation 1:
// Aggregate relationship
class emojis {
printable * happy;
printable * sad;
public:
emojis() {
happy = new smiley();
sad = new frown();
};
~emojis() {
delete happy;
delete sad;
};
};
```
2. **Acquaintance**
```cpp
// implementation 2:
// Acquaintances only
class emojis {
printable * happy;
printable * sad;
public:
emojis();
~emojis();
// dependency injection
void setHappy(printable *);
void setSad(printable *);
};
```

View File

@@ -0,0 +1,71 @@
# CSE559A Lecture 19
## Feature Detection
### Behavior of corner features with respect to Image Transformations
To be useful for image matching, “the same” corner features need to show up despite geometric and photometric transformations
We need to analyze how the corner response function and the corner locations change in response to various transformations
#### Affine intensity change
Solution:
- Only derivative of intensity are used (invariant to intensity change)
- Intensity scaling
#### Image translation
Solution:
- Derivatives and window function are shift invariant
#### Image rotation
Second moment ellipse rotates but its shape (i.e. eigenvalues) remains the same
#### Scaling
Classify edges instead of corners
## Automatic Scale selection for interest point detection
### Scale space
We want to extract keypoints with characteristic scales that are equivariant (or covariant) with respect to scaling of the image
Approach: compute a scale-invariant response function over neighborhoods centered at each location $(x,y)$ and a range of scales $\sigma$, find scale-space locations $(x,y,\sigma)$ where this function reaches a local maximum
A particularly convenient response function is given by the scale-normalized Laplacian of Gaussian (LoG) filter:
$$
\nabla^2_{norm}=\sigma^2\nabla^2\left(\frac{\partial^2}{\partial x^2}g+\frac{\partial^2}{\partial y^2}g\right)
$$
![Visualization of LoG](./images/Laplacian_of_Gaussian.png)
#### Edge detection with LoG
![Edge detection with LoG](./images/Edge_detection_with_LoG.png)
#### Blob detection with LoG
![Blob detection with LoG](./images/Blob_detection_with_LoG.png)
### Difference of Gaussians (DoG)
DoG has a little more flexibility, since you can select the scales of the Gaussians.
### Scale-invariant feature transform (SIFT)
The main goal of SIFT is to enable image matching in the presence of significant transformations
- To recognize the same keypoint in multiple images, we need to match appearance descriptors or "signatures" in their neighborhoods
- Descriptors that are locally invariant w.r.t. scale and rotation can handle a wide range of global transformations
### Maximum stable extremal regions (MSER)
Based on Watershed segmentation algorithm
Select regions that are stable over a large parameter range

View File

@@ -21,4 +21,5 @@ export default {
CSE559A_L16: "Computer Vision (Lecture 16)",
CSE559A_L17: "Computer Vision (Lecture 17)",
CSE559A_L18: "Computer Vision (Lecture 18)",
CSE559A_L19: "Computer Vision (Lecture 19)",
}

View File

@@ -1 +1,118 @@
# Lecture 29
# Math4121 Lecture 29
## Continue on Measure Theory
### Lebesgue Measure
Caratheodory's criterion:
$S$ is Lebesgue measurable if for all $A\subset S$,
$$
m_e(X) = m_e(X\cap S) + m_e(X\cap S^c)
$$
Let $\mathfrak{M}$ be the collection of all Lebesgue measurable sets.
1. $\phi\in\mathfrak{M}$
2. $\mathfrak{M}$ is closed under countable unions (proved last lecture)
3. $\mathfrak{M}$ is closed under complementation ($\mathfrak{M}$ is a $\sigma$-algebra) (goal today)
> Desired properties of a measure:
>
> 1. $m(I)=\ell(I)$ for all intervals $I$
> 2. If $\{S_n\}_{n=1}^{\infty}$ is a set of pairwise disjoint Lebesgue measurable sets, then
>
> $$ m\left(\bigcup_{n=1}^{\infty}S_n\right) = \sum_{n=1}^{\infty}m(S_n)$$
> 3. If $R\subset S$, then $m(S\setminus R) = m(S) - m(R)$
Recall the Borel $\sigma$-algebra $\mathcal{B}$ was the smallest $\sigma$-algebra containing closed intervals. Therefore $\mathcal{B}\subset\mathfrak{M}$.
Towards proving $\mathfrak{M}$ is closed under countable unions:
#### Theorem 5.9 (Finite union/intersection of Lebesgue measurable sets is Lebesgue measurable)
Any finite union/intersection of Lebesgue measurable sets is Lebesgue measurable.
Proof:
Suppose $S_1, S_2$ is a measurable, and we need to show that $S_1\cup S_2$ is measurable. Given $X$, need to show that
![Finite union cut](https://notenextra.trance-0.com/math4121/Finite_union_cut.png)
$$
m_e(X) = m_e(X_1\cup X_2\cup X_3)+ m_e(X_4)
$$
Since $S_1$ measurable, $m_e(X_1\cup X_2\cup X_3)=m_e(X_3)+m_e(X_1\cup X_2)$.
Since $S_2$ measurable, $m_e(X_3\cup X_4)=m_e(X_3)+m_e(X_4)$.
Therefore,
$$
\begin{aligned}
m_e(X) &= m_e(X_1\cup X_2\cup X_3) + m_e(X_4) \\
&= m_e(X_1\cup X_2) + m_e(X_3)+m_e(X_4) \\
&= m_e(X_1\cup X_2) + m_e(X_3\cup X_4) \\
&= m_e(X)
\end{aligned}
$$
by measurability of $S_1$ again.
QED
#### Theorem 5.10 (Countable union/intersection of Lebesgue measurable sets is Lebesgue measurable)
Any countable union/intersection of Lebesgue measurable sets is Lebesgue measurable.
Proof:
Let $\{S_j\}_{j=1}^{\infty}\subset\mathfrak{M}$. Definte $T_j=\bigcup_{k=1}^{j}S_k$ such that $T_{j-1}\subset T_j$ for all $j$.
And $U_1=T_1$, $U_j=T_j\setminus T_{j-1}$ for $j\geq 2$.
Then $\bigcup_{j=1}^{\infty}S_j=\bigcup_{j=1}^{\infty}T_j=\bigcup_{j=1}^{\infty}U_j$. Notice that $\{U_j\}_{j=1}^{\infty}$ are pairwise disjoint, and $\{T_j\}_{j=1}^{\infty}$ are monotone.
Let $X$ have finite outer measure. Since $U_n$ is measurable,
$$
\begin{aligned}
m_e(X\cap T_n) &= m_e(X\cap T_n\cap U_n)+ m_e(X\cap T_n\cap U_n^c) \\
&= m_e(X\cap U_n)+ m_e(X\cap T_{n-1}) \\
&= \sum_{j=1}^{n}m_e(X\cap U_j)
\end{aligned}
$$
Since $T_n$ is measurable and $T_n\subset S$, $S^c\subset T_n^c$. $m_e(X\cap T_n^c)\geq m_e(X\cap S^c)$.
Therefore,
$$
m_e(X)=m_e(X\cap T_n)+m_e(X\cap T_n^c)\\
\geq \sum_{j=1}^{n}m_e(X\cap U_j)+m_e(X\cap S^c)
$$
Take the limit as $n\to\infty$,
$$
\begin{aligned}
m_e(X) &\geq \sum_{j=1}^{\infty}m_e(X\cap U_j)+m_e(X\cap S^c) \\
&= m_e(\bigcup_{j=1}^{\infty}(X\cap U_j))+m_e(X\cap S^c) \\
&= m_e(X\cap S)+m_e(X\cap S^c) \\
&\geq m_e(X)
\end{aligned}
$$
Therefore, $m_e(X\cap S)=m_e(X)$.
Therefore, $S$ is measurable.
QED
#### Corollary from the proof
Every open or closed set is Lebesgue measurable.
(Every open set is a countable union of disjoint open intervals)

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB