## Pseudocolor Image Processing in a Nutshell

First, let’s take care of the pleasantries. I’m ok. Are you ok? That’s fine. How’s the missus? Oh, she is thinking about suicide? No worries, just chock a handful of Zoloft at her! How’s the kid? You don’t have a kid? Why? Because you take Risperidone? No comments!

I haven’t talked about DIP, for like, ever. I talked about DSP in one of my opi, but that was mostly about DSP rather than DIP. So it’s time dive into Gonzalez and Woods 4th edition, chapter 6, and learn about Pseudocolor Image Processing – Something I always wanted to learn about. Let’s hope this is going to be a short post because I wanna watch muh Veronica Mars1.

Pseudocolor image processing consists of assigning colors to gray values based on a specified criterion. The term pseudo or false color is used to differentiate the process of assigning colors to achromatic images from the process associated with true color images, a topic which I’m going to learn, and “teach” in the near future.

The principal use of pseudocolor is for human visualization and interpretation of grayscale events in a single image, or a sequence of images. But why do we want to convert a grayscale image to color? Are we all affected by the disease aptly called Ted Turneritus? No, we do this because humans can discern thousands of color shades, as compared to less than two dozen shades of gray.

The techniques of intensity slicing, and color coding are the simplest and earliest examples of pseudocolor processing of digital images. If an image is interpreted as a 3D function, like this:

the method can be viewed as one of placing planes parallel to the coordinate plane of the image; each plane then “slices” the function in the area of intersection. In the image below you see an example of using a plate at to slice the image intensity function into two levels.

If a different color is assigned to each side of the plane, any pixel whose intensity level is above the plane will be coded with one color, and any pixel below the plane will be coded with another. Levels that lie on the plane itself may be arbitrarily assigned one of the two colors, or they could be given a third color to highlight all the pixels at that level. The result is between two to three color images whose relative appearance can be controlled by moving the slice plane up and down in the intensity axis.

A simple but practical use of intensity slicing is shown below, with the grayscale image on the left and the pseudocolor image on the right:

This is an image of the Picker Thyroid Phantom, a radiation test pattern. Regions that appear of constant intensity in the grayscale image are actually quite variable, as shown by the various colors in the intensity image. For instance, the left lobe is a dull gray in the grayscale image, but has various colors of red, yellow and green in the intensity image. Below you see the representation of one of the grayscale intervals and its slicing:

In the preceding simple example the grayscale was divided into intervals, and a different color was assigned to each, with no regard for the meaning of the gray levels in the image. Interest in that case was simply to view the different gray levels constituting the image. Intensity slicing assumes a much more meaningful and useful role when subdivision of the grayscale is based on the physical characteristics of the image. For instance, in this image:

We see an X-ray image of a weld, containing several cracks and porosities. When there is porosity or crack in the weld, the full strength of the X-rays going through the object saturates the image sensor on the other side of the object. Thus, intensity values of 255, white, in an 8-bit image coming from such a system automatically imply a problem with the weld. If the human visual analysis is used to inspect welds, a simple color coding assigns one color to 255, and one color to the rest. Thus helping the inspectors to assess the problem better.

One of the things that interests geologists is measuring rainfall levels, especially in tropical regions of Earth. Tropical Rainfall Measuring Missions, TRMM satellite utilizes among others, three sensors especially designed to detect rain: a precipitation radar, a microwave imager, and a visible and infrared scanner. The results from the various rain sensors are processed, resulting in estimates of average rainfall over a given time period in the area monitored by the sensors. From these estimates, it is not difficult to generate grayscale images whose intensity values correspond directly to the rainfall, with each pixel representing a physical land area whose size depends on the resolution of the sensors. Such an intensity image is shown below:

Visual examination of such picture is prone to error. However, suppose that we code intensity levels from 0 to 255 using the colors shown here:

Which results in:

Thus making it easier for the scientists to meter up the rainfall levels.

There are other methods that are more general, and thus are capable of achieving a wider range of pseudocolor enhancement results than the simple slicing techniques discussed is the preceding section. Below you see an approach that is particularily attractive. Basically, the idea underlying this approach is to perform three independent transformations on the intensity of input levels. The three results are then fed separately into the red green, and blue channels of a color monitor. This method produces a composite image whose color content is modulated by the nature of the transformation function.

Now, look at this image:

It shows two monochrome images of a luggage obtained from an airport X-ray scanning system. The image on the left contains ordinary articles. The image on the right contains the same articles, as well as a block of simulated plastic explosives. The purpose of this example is to illustrate the use of intensity to color transformations to facilitate detection of explosives.

Look at this image:

It shows the transformation functions used. These sinusoidal functions contain regions of relatively constant value around the peaks as well as regions that change rapidly in the valleys. Changing the phase and frequency of each sinusoid can emphasize ranges in the grayscale. For instance, if all three transformations have the same phase and frequency, the output a grayscale image. A small change in the phase between the three transformations produces little change in pixels whose intensity correspond to peaks in the sinusoids, especially if the sinusoids have broad profiles (low frequencies). Pixels with intensity values in the steep section of the sinusoids are assigned a much stronger color content as a result of significant differences between amplitudes of the three sinusoids caused by the phase displacement between them.

The pseudocolored image of the luggage was obtained using the transformations we just saw in the above on the left, which shows the gray-level bands corresponding to the explosive, garment back, and background, respectively. Note that the explosive and background have quite different intensity levels, but they were both coded with approximately the same color as a result of the periodicity of the sine waves. The second pseudocolored image of the luggage was obtained with the transformation on the right. In this case, the explosives and garment bag intensity bands were mapped by similar transformations, and thus received essentially the same color assignment. Note that this mapping allows and observer to “see” through explosives.

It is often in our interest to combine several grayscale images, and then transform them to pseudocolor. Frequent use of this approach is in multispectral image processing, where different sensors produce individual grayscale images, each in a different spectral band.

Ok, that shall be it for tonight! I will be back tomorrow with a post about machine learning… Deep learning, perhaps? I’m not sure. There’s a lot to learn. There’s a lot to process.

My brother broke my hookah, and beat up my mom. I think, just like me, he’s got bipolarity. But well, he’s a proud 5th semester psychology student and there’s no way in hell we could get him to take medication for his mental handicap. We get bipolarity from our father’s side, and he gets it from his mother’s side. Both my uncles are bipolar, my youngest brother has Lithium deficiency with a wee bit of bipolarity, but my middle broter is… Kinda fucked up. The symptoms are showing. I don’t know why he’s so proud. Our second cousin once removed – my father’s cousin, has bipolarity. So do both my uncles, and they’re being medicated for it. Not many women get bipolarity. It’s just not in the evolution of our species. We’re bipolar because nature wanted us to hibernate during the winter, but it fucked up, so based on seasonal changes, bipolar people like me and many people in my family get depressed, it gets harder and harder for them to step out of their dwelling, they get depressed, and after depression passes, they become manic. It’s HELL.

Anyways, if you’re bipolar, I hope you’re getting the medication and the help you deserve. Many people in developing countries suffer for the cheapest of psych meds, even Lithium. This is bad.

Well, to the books!

## 2-D Discrete Fourier Transform

IN: 01

Subject: 2-Dimensional Fourier Transform

Written by Chubak Bidpaa

The source for this episode is Gonzalez and Woods’ Chapter 04 Page 240 onward. We’ll also use a few other sources, which will be highlighted in the blog post.

Have you watched the movie Tron? Some of you may, some of you may have not. Well, let’s not fret over it. The sujet of this movie is that a ragtag group of individuals transform themselves into a video game world, to fight a battle. Keyword here, at least for us, is transform. A Fourier transform is something akin to this: Signals are transformed from their cozy spatial domain into a cryptic frequency domain. By the way of this transformation, we can apply operations that are impossible to think of in the spatial domain.

But pray tell, what is this Fourier transform you speak of? Well, it basically a complex function, don’t forget, complex, in which we use Euler’s Formula to generate a sinusoidal periodic value for our analogue function. But that’s just it – Analgoue. Analogue signals are continuous, meaning they are infinite, however, the digital signals we deal with in computers everyday are discrete. So how to compensate for this difference?

It all boils down to the difference between integration, and summation. Integrals are basically the area under the curve of a function, so they are infinite, and continuous, however, summations are finite, and discrete. So by replacing the integral symbol with sigma symbol, we can have ourselves a nice and dandy equation for calculating discrete Fourier transform in 2-D. Refer to the blog post to see this equation, equation 1-1.

Equation 1-1:

To revert this transformation back into the spatial domain, we’ll use Inverse Discrete Fourier Transform. Refer to equation 1-2 to get a grasp of what IDFT holds in the sack. As you may notice, the inverse DFT is the average of the opposite of the Euler’s Formula.

Equation 1-2:

But what is this Euler’s Formula you speak of? Well, refer to equation 1-3 to see the complex interpretation of Euler’s Formula. We talk about complex numbers as if knowing about them is rite of passage. No. it would, however, be my privilege to talk about complex numbers, for those who are otherwise unaware!

Equation 1-3:

Well, let me start off by saying that there are basically two sorts of numbers. Real, and Complex. Complex numbers have two sections, a real section, and an imaginary section. Refer to equation 1-5 (1-4) to find out what an “imaginary” number is.

Equation 1-5 (1-4):

Let’s ask ourselves this question: We have a frequency interval, and then we have an spatial interval. How are these two related? Well, easy! You can see their relation in formula 1-5 and 1-6, in which we have captured the separation between samples, in the divisor or the quotient, and delta u and v being the separation between the frequencies.

Equations 1-5 and 1-6:

Another property of DFT is the fact that you can rotate and translate the domain easily as one, two three. Another property of it is its periodicity. Meaning that both DFT and IDFT are infinitely periodic in both u and v directions, as you can see in figure 1-1 in the blog post.

In equations 1-7 through 1-8, you can see the definition of phase spectrum. This is what we in the signal processing simply call Fourier spectrum. What’s the use? Visualization, my fam! And if you remember Winamp, an audio player from the early Aughts in which we used to play music files we downloaded off Limewire, you’d remember power spectrum. Power Spectrum is Fourier Spectrum squared. But what is it, really? Let’s not fret, it’s basically the Fourier transform in polar coordinates. In equation 1-9 you see equation for phase angle. And in figure 1-2 you can see it in action.

Equations 1-7, 1-8, and 1-9:

Let’s talk about convolution. We have two very different sorts of convolutions in signal processing, one is convolution in the spatial domain, one is convolution in the frequency domain. We’re not concerned with the spatial domain right now, so let’s talk about the frequency domain. In frequency domain, the convolution is just the result of multiplying two Fourier functions together. Referring to equation 1-10, we’ll realize that convolution in the frequency domain equates the circular convolution in the spatial domain. But whilst you’re there, take a look at equation 1-11. Looks familiar? Yes, the multiplication of two signals in the spatial domain equals something close to IDFT of a circular convolution. But what is this circular convolution? Refer to equation 1-12.

Equation 1-10, 1-11, and 1-12:

Correlation is another one of DFT properties. We denote correlation with a hallow star. Correlation is similar to convolution, except correlation is used to compare the two signals.

What’s important about DFT is that it’s separable. Pray tell mister man, what does it mean? It simply means that you can do certain operations on the rows, and certain operations on the columns ,and then mix and match them together.

But how do you apply DFT? The formula shows that it sums up a complex operation on all rows, and on all columns. So how does it get to be so fast, insomuch as it has been in practice for ages, and I can apply a DFT on a large image, or an audio file? The answer lies in Fast Fourier Transform, or FFT. We’ll discuss FFT soon.

I hope you’ve enjoyed the first episode of my podcast plus blog post. I’ve spent a lot of time on it, and remember that I make these podcasts episodes plus blog posts to learn, more than to teach. So if there are inaccuracies, please forgive me. If you have any corrections to this podcast episode or blog post, just tell me, and I’ll add it to the addendum.

Let’s hope Partly Shaderly podcast slash blog takes off!