Added some text to the Jupyter Notebooks

parent 185065e2
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
 ... ... @@ -6,6 +6,14 @@ "source": [ "# Introduction to Image Processing\n", "\n", "Image processing refers to a set of operations done on an image in order to efficiently extract information. In this class, we shall understand some of the basic concepts which are relevant, through many Interactives. \n", "\n", "In the first section, we understand how a 1-D signal can be reconstructed by adding sinusoidal waves. Later we explore the concepts of frequency spectrum and Fourier Transform. We apply these concepts for 2-D signals, a.k.a Images. Finally, we learn about convolution and the convolution theorem.\n", "\n", "To begin everything, let us first look at the simplest signal we can imagine. \n", "\n", "## Sinusoidal Waves\n", "\n", "The simplest signal is a sinusoidal wave. Sinusoidal waves have three independant parameters. They are: \n", "* Amplitude, $A$\n", "* Frequency, $f$\n", ... ... @@ -29,7 +37,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "068c9312a466412d8e1b6dc582b9e587", "model_id": "7391fc05a5f043ca87ed4b23169844a5", "version_major": 2, "version_minor": 0 }, ... ... @@ -71,8 +79,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ "Processing any piece of data would require a mathematical way to describe these signals. Given that real life data are not simple sinusoids, it would require near infinite amounts of parameters to describe such data mathematically. Fortunately, as we shall see in this course, $all$ data can be expressed as a sum of simple sinusoids. Thus, you learn a powerful way to process real life data with arbitrary precision through this course! " "Processing any piece of data would require a mathematical way to describe these signals. Given that real life data are not simple sinusoids, it would require near infinite amounts of parameters to describe such data mathematically. Fortunately, as we shall see in this course, $all$ data can be expressed as a sum of simple sinusoids. Thus, you learn a powerful way to process real life data with arbitrary precision through this course! \n", "\n", "\n", "[Next: How can any signal be made up of sinusoids?](ip_basics_part2.ipynb#section_id2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { ... ... @@ -91,7 +109,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" "version": "3.6.12" } }, "nbformat": 4, ... ...
This diff is collapsed.
 ... ... @@ -6,20 +6,9 @@ "source": [ "## Frequency Spectrum\n", "\n", "As we learnt in the last section, any 1-D signal can be split into arbitrary number of sinusoidal waves. We could see in the last graphic the amplitude, frequency and phase of these sinusoidal waves. But, the graphic could only help visualise a small number of waves. For large numbers, it becomes cluttered. \n", "As we learnt in the last section, any 1-D signal can be split into arbitrary number of sinusoidal waves. In this section, we shall see how to analyse these signals in terms of its frequency. \n", "\n", "It is generally preferred to see the strengths of these different frequency components, which is measured by the amplitude. Hence a \"frequency spectrum\" is plotted. This is a graph of amplitude and frequency, leaving out the phase term. As we shall see later on, the phase term is also very important, which is important to remember. \n", "\n", "For now, let's consider a simple sine wave\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from misc import *" "Again, let's consider a simple sine wave having an amplitude 1, frequency 10 and zero initial phase. Run the following code to get the plot\n" ] }, { ... ... @@ -51,6 +40,8 @@ } ], "source": [ "from misc import *\n", "\n", "amp,freq,phase = 1,10,0\n", "w1 = [(amp,freq,phase)]\n", "signal1,time = addwaves(w1,const=5,tot_time=1,numpoints=1000)\n", ... ... @@ -63,13 +54,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ "This is the simplest signal that we can analyse. This is a cosine wave. The signal is recorded for 1s and has 10 cycles through it, thus it has a frequency of 10 Hz. The average value of the signal is around 5, so this is the DC component of our signal. To find the \"frequency spectra\" of this we can use a \"Discrete Fourier Transform\", which is a mathematical operation given by\n", "The signal is recorded for 1s and has 10 cycles through it, thus it has a frequency of 10 Hz. The average value of the signal is around 5, so this is the DC component of our signal. To find the \"frequency spectra\" of this we can use a \"Discrete Fourier Transform\", which is a mathematical operation given by\n", "\n", "\\n", " F_k = \\sum\\limits_{m=0}^{P-1} b(k) \\cdot e^{-2 \\pi i k \\cdot m/P}\n", " F_k = \\sum\\limits_{m=0}^{P-1} b(k) \\cdot e^{i \\cdot \\frac{-2 \\pi k \\cdot m}{P}}\n", "\\n", "\n", "This gives the $complex$ fourier coefficient of the $k^{th}$ frequency. The magnitude and phase of the wave can be extracted directly from this complex coefficient. Let's see what we get when we plot this:" "This gives the $complex$ fourier coefficient of the $k^{th}$ frequency. The magnitude and phase of the wave can be extracted directly from this complex coefficient. Run the following code to get the amplitudes at different frequencies. To increase or decrease the frequency range displayed in the x-axis, change the 'flimit' parameter. By default, it is set at 80. " ] }, { ... ... @@ -98,9 +89,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ "Clearly, we see that there is peak at 0 Hz, with a value of 5. The reason for the symmetry is from the mathematics of the DFT process. This results in the 'negative frequencies'. For the purpose of analysis the positive frequencies can be considered only. \n", "We see that there is peak at 0 Hz, with a value of 5. This is the average value we get by integrating over the whole time period. Integral of a sine wave over full time period is zero, thus the amplitude of frequency spectra at 0 Hz is it's DC power. \n", "\n", "We also see that the plot has a symmetry around the 0 Hz line. The reason for this stems from the complex nature of the DFT signal. So the two peaks are the complex conjugates of one another - they have the same amplitude, but opposite phase. \n", "\n", "We see a peak at 10 Hz and -10 Hz with a value of 0.5. Together they have a value of 1. This means there is one full cycle of 10 Hz frequency present in our signal, which can be verified easily from above. \n", "\n", "The positive frequency at 10 Hz is because the 10 Hz frequency signal is the most dominant. Suppose we add a 20 Hz and 40 Hz signal to the original wave, this is what we get" "Suppose we add a 20 Hz and 40 Hz signal to the original wave, this is what we get" ] }, { ... ... @@ -130,9 +125,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ "Now we see peaks at 10 Hz, 20 Hz and 40 Hz as well! \n", "Now the signal looks complicated. We can't know which frequencies are present in the signal just by looking at it's time varying plot. The frequency spectrum on the other hand, clearly show distinct peaks at 10 Hz, 20 Hz and 40 Hz! \n", "\n", "An important point to consider while using the DFT is the relation between co-ordinate index of the frequency spectra and it's frequency. Each co-ordinate index in the frequency spectra corresponds to a specific frequency. The mapping between the index and frequency must be well understood. \n", "\n", "\n", "The fourier transform operation gives the output as an array. The array indices must be mapped on to the correct frequency values. This is done using the sampling frequency and the total number of samples. \n", "\n", "sample spacing = time/number of samples\n", "\n", ... ... @@ -145,7 +142,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ "Now try changing frequencies of the waves and see how they shift! " "Now try changing these amplitudes and frequencies yourself and observe how the frequency spectrum changes!" ] }, { ... ... @@ -156,7 +153,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "947bbafc03df4312bc3846f57a781e41", "model_id": "332e129a045c44879ffa61f170b2d12c", "version_major": 2, "version_minor": 0 }, ... ... @@ -183,11 +180,14 @@ ] }, { "cell_type": "code", "execution_count": null, "cell_type": "markdown", "metadata": {}, "outputs": [], "source": [] "source": [ "In the next section, we dive into 2D signals, or Images. We shall apply these concepts for such signals as well. \n", "\n", "[Prev: Fourier Series](ip_basics_part2.ipynb#section_id2) \n", "[Next: 2-D Fourier Analysis](ip_basics_part4.ipynb#section_id2)" ] }, { "cell_type": "code", ... ... @@ -213,7 +213,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" "version": "3.6.12" } }, "nbformat": 4, ... ...
 ... ... @@ -4,31 +4,23 @@ "cell_type": "markdown", "metadata": {}, "source": [ "## 2-D Image Processing\n", "## 2-D Fourier Analysis\n", "\n", "Now that we considered 1-D signals and how the Fourier Transforms of those look like, let us move to signals which vary across two dimensions. An image taken by a digital camera is the most common example of a 2D signal. \n", "\n", "What do we mean when we say that an image is a 2-D signal? It means, essentially that an image is nothing but a matrix of numbers. We can actually see this matrix in any data management software like Python, Excel or Matlab. \n" "### Image as a 2D Signal\n", "What do we mean when we say that an image is a 2-D signal? It means, essentially that an image is nothing but a matrix of numbers. We can actually see this matrix in any data management software like Python, Excel or Matlab. Run the following interactive to see the numbers yourself. Move the small rectangle around and check the variation of the numbers. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from misc import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "efd53eb1622941d7b0296342a172f422", "model_id": "bc75c90f3ea54246b8e161d0ee67f274", "version_major": 2, "version_minor": 0 }, ... ... @@ -45,12 +37,14 @@ "" ] }, "execution_count": 2, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from misc import *\n", "\n", "I = rgb2gray(plt.imread('cameraman.bmp'))\n", "get_pixel_values(I)" ] ... ... @@ -59,17 +53,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ "Have a look at this image. Move the black rectangle around and see the numbers which form the image at this location. " "Each number in this matrix represents a 'pixel value'. When recording an image, photons excites several pixels in a detector and the resulting pattern is what we call an image. For image analysis, the pixel size is important as we shall see later. \n", "\n", "Next, we shall try to understand the concepts of spatial frequency and how the 1D analysis we did before applies to images. \n", "\n", "[Prev: Frequency Spectrum](ip_basics_part3.ipynb#section_id2) \n", "[continue: 2-D Fourier Analysis](ip_basics_part5.ipynb#section_id2)" ] }, { "cell_type": "markdown", "cell_type": "code", "execution_count": null, "metadata": {}, "source": [ "Each number in this matrix represents a 'pixel value'. When recording an image, photons excites several pixels in a detector and the resulting pattern is what we call an image. For image analysis, the pixel size is important as we shall see later. \n", "\n", "Next, we shall try to understand the concepts of spatial frequency and how the 1D analysis we did before applies to images. " ] "outputs": [], "source": [] } ], "metadata": { ... ... @@ -88,7 +85,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" "version": "3.6.12" } }, "nbformat": 4, ... ...