Posts

Playing Music with Images

Image
For our last activity of the semester, we did something interesting -- as the title mentions, we played music with images. To do this, we used the technique known as template matching. As the name of the technique implies, template matching involves determining which part of an image follows or is similar to particular template[1], and there are many ways to do it. In this activity, this was done by convolving an image of interest with a template image. Notice that since we are matching templates, the template in the template image should look exactly like the things similar to it in our image of interest. Further, since we are convolving both the image of interest and the template image, it should be noted that they are supposed to be of the same image size as if this condition is not met, then by the code used in doing this activity, we won't be able to achieve this. The code used to do template matching is shown below. Notice that in the code, we took the Fourier transform o...

Edge Detection and Image Segmentation

Image
Last lab session, we made programs that detected edges found in images and segmented others depending on a region we were interested in. In this activity, we defined edges to be local regions in an image where a significant shift in brightness occurs [1]. Having said that, we can consider images to be a scalar field having particular brightness value at every pixel. How do we then know when there is a significant shift in brightness, i.e. there is an edge? Since we consider an image to be a scalar field, then to know if there is a shift in brightness, we just take the gradient of that scalar field. How do we then take the gradient of an image? Simple, convolve the image with operators. In detecting edges, we made use of two operators, the Prewitt \(P\) and Sobel \(S\) edge operators, given as: \begin{equation}\begin{split}\text{Prewitt}\hspace{1.25cm}P_x=\begin{bmatrix}-1 & -1 & -1 \\ 0 & 0 & 0 \\ 1 & 1 & 1\end{bmatrix} \hspace{0.75cm} P_y=\begin{bmatrix}...

Restoring Color in Old Images

Image
Last week's activity was interesting -- we restored the color in old images digitally! This was interesting because finally I understood what the fancy jargon that came with it meant already. Apparently there are different ways to represent color in images and the one that we played around with were with the RGB and HSV representation of color in images. RGB represents the amount of red, green, and blue there is in an image [1] which is practical, because they are the primary colors of light [1] from which other colors may be made from. This kind of representation however, isn't practical for heavy color restoration because we do not describe colors like this. Rather we describe them through their hue, saturation, and lightness/value [1]. Thus we use HSV to do just that. Hue and saturation represents the purity of color and how much it is diluted by white light [1], and value is how far the color is from black, which may simply be its gray-level. In this activity, we mess...

Enhancing Images in Fourier Space

Image
Before I begin, I'd like to say that I was hoping this activity to be very fun -- but it was fun in a not-so-good way. To put it simply, it was just very long, and a lot had to be done just to finish one part! I'm just glad I'm already writing this one down so that I don't have to think about it and move on to the next 'short' activity. The activity was split into six parts. In the first part, we were tasked to take the Fourier transform of: a wide, and tall rectangle, and dots placed symmetrically and asymmetrically with respect to the image center. After doing so, we get Figure 1. Figure 1: Fourier Transform of tall and wide rectangle, and dots placed symmetrically and asymmetrically with respect to the image center. Looking at the figure we see that, as expected, the Fourier transform of either rectangles give out a pattern similar to the diffraction pattern through a single slit, which further was asserted in the previous post that Fourier trans...

Analyzing Images in Fourier Space

Image
Last activity, we played around with images in Fourier space. Given a periodic function \(f(t)\) with fundamental period \(T\) such that \(f(t+T)=f(t)\) that has a finite number of finite discontinuities and finite number of extreme values within the interval \([a,a+T]\) for all \(a\in\mathbb{R}\), then \(f(t)\) can be rewritten as: \begin{equation}\label{fseries}f(t)=\dfrac{a_0}{2}+\sum_{n=1}^\infty a_n\cos(nt)+\sum_{n=1}^\infty b_n\sin(nt)\end{equation} [1]. This means that any periodic function, or signal, can be decomposed as a sum of sines and cosines of different frequencies with different contributions. To get the contribution of each frequency of sines and cosines to get \(f(t)\), what we can do is to obtain its Fourier transform, \(\mathscr{F}\{f(t)\}=F(\omega)\) given by: \begin{equation}\label{1d_ft}F(\omega)=\int_{-\infty}^\infty f(t)\mathrm{e}^{-\mathrm{i}2\pi\omega t}\,\mathrm{d}t\end{equation} [2]. This can even be extended to work for functions dependent on two func...

Estimating Areas in Images

Image
Last lab session, we were told that we can estimate areas of shapes found in images - nice! To do so however, we had to make use of the consequence of a very mathematical thing - Green's Theorem. It's been very long since I last seen this kind of math so please let me do so here. Green's Theorem states that if you have two functions \(M(x,y)\) and \(N(x,y)\) which have continuous first partial derivatives on a region \(R\) in a plane, then if the curve \(C\) bounding \(R\) is a sectionally smooth simple closed curve in that plane, then: \begin{equation}\label{green}\iint_R\left(\dfrac{\partial N}{\partial x}-\dfrac{\partial M}{\partial y}\right)\,\mathrm{d}x\,\mathrm{d}y=\oint_C\left[M(x,y)\,\mathrm{d}x+N(x,y)\,\mathrm{d}y\right]\end{equation} [1] This meant that one way to evaluate the integral on the right hand side of \eqref{green} is to evaluate the integral on its left hand side, and vice versa - assuming the conditions on \(M(x,y)\) and \(N(x,y)\) are met. Looki...

Simple Image Enhancement Methods

Image
Last lab session, we were tasked to perform point transformation onto images - where one uses a transformation function \(\mathrm{T}[\ ]\) on an image \(f(x,y)\) to obtain another image \(g(x,y)\), or: \begin{equation}g(x,y)=\mathrm{T}\left[f(x,y)\right]\end{equation} [1]. Specifically, we were told to do the following transforms: image negative, logarithmic and gamma transform, contrast stretching and thresholding, and intensity-level slicing. From [1], we see that given that maximum gray value present in the image \(f(x,y)\) is \(L\), then for all gray level values in \(f(x,y)\) is \(r\), the resulting gray values for \(g(x,y)\) is \(s\), and the image's negative is obtained by: \begin{equation}s=L-r \label{nega}\end{equation} whereas for image's logarithmic transform is given by: \begin{equation}s=c\log(1+r) \label{log}\end{equation} and for gamma transform is: \begin{equation}s=cr^\gamma \label{gamma}\end{equation} To stretch the contrast of an image, we stretch c...