-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetting-started-with-image-processing.html
62 lines (61 loc) · 7.63 KB
/
getting-started-with-image-processing.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<html>
<head>
<title>Napster's Experiments with Freedom</title>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/xt256.min.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="stylesheet" type="text/css" href="css/post.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-20813670-9', 'auto');
ga('send', 'pageview');
</script>
</head>
<body><h1 id="getting-started-with-image-processing">Getting Started with Image Processing</h1>
<p>I have been working on digital image processing for sometime now, and I was learning a lot of stuff recently. I thought I should put together a very basic getting started guide on image processing, which could help a lot of enthusiasts. This aritcle is greatly borrowed from the <a href="https://codewords.recurse.com/issues/six/image-processing-101">Image Processing - 101 Sher Minn Chong</a>. This article, as I have planned, will be multi-part, and will be as detail as possible from my own understanding of the concepts.</p>
<h2 id="digital-image">Digital Image</h2>
<p>Digital images are fundamentally a finite number of pixels distributed in X and Y axis, and are stored on the disk as a two (or more) dimentional array of integers or more complex datastructers, in rows and columns. Any 2D digital image can be viewed as a matrix of size NxM. Each element in the matrix represents a pixel. A <a href="https://en.wikipedia.org/wiki/Pixel">pixel</a>, and its definition, and how a pixel is displayed on a screen or even how it is printed on a paper, are out of the context of this article. Following is a hypothetical representation of a flower as a digital image.</p>
<p><img src="images/digital-image-rep.png"></p>
<p>There are a few points to be noted here.</p>
<ul>
<li>The image is grayscale - which means, there are only different shades of grey, in the palette of colors, a pixel in the image can take.</li>
<li>All the colors in the palette are indexed - ie, the shades of grays are indexed from 0 to 9.</li>
<li>The index of the color of a particular pixel is the value of the corresponding element in the matrix.</li>
<li>The display system, reads this value, and look for the color in the color palette using the said number as the index in the palette.</li>
</ul>
<p>Now, if you think about it, an absolute minimum palette should have at least two colors in it. Suppose my palette of colors have only black and white. Here is an image, that I can represent using this palette.</p>
<p><img src="images/bit_depth_1bit.jpg"></p>
<p>Now, for indexing two colors, we need a minimum of one-bit of storage. If the bit is <code>0</code> —> the color is black, and if it is <code>1</code> —> the color is white. Such images are commonly referred to as <a href="https://en.wikipedia.org/wiki/Monochrome">monochrome</a> images. Every pixel in a monochrome image is either 1 or 0.</p>
<p>But what if I need more colors to realistically reproduce an image? Basically, I need more bits to represent each pixel. That’s it! Suppose instead of just 1 bit, I use 2 bits to represent each pixel. I can now show 4 different colors. Take a look at my new palette.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode cpp"><code class="sourceCode cpp"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="bn">00</span> --> Black</a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="bn">01</span> --> Dark Gray</a>
<a class="sourceLine" id="cb1-3" data-line-number="3"><span class="dv">10</span> --> Light Gray</a>
<a class="sourceLine" id="cb1-4" data-line-number="4"><span class="dv">11</span> --> White</a></code></pre></div>
<blockquote>
<p>Note : You <em>don’t</em> have to limit your palette to shades of gray only. I can use any four colors to build my palette. We will cover such palettes down the line. I just use these colours for simplicity sake.</p>
</blockquote>
<p>Now, just by adding one more bit, I have gratly improved the quality of the image. The image below shows the difference.</p>
<p><img src="images/bit_depth_2bit.jpg"></p>
<p>The number of bits used to represent a pixel is called the <a href="https://en.wikipedia.org/wiki/Color_depth">bit depth or color depth</a> in digital image processing. Most images we now find on the web has 8-bit or higher depth. Using just 8 bits, you can display 256 different colors.</p>
<h2 id="multi-channel-images-color-images">Multi-Channel Images (Color Images)</h2>
<p>So far we have discussed only single channel indexed images, where each pixel in the image is represented by a single number. This brings one limitation as the number of shades (or colors basically) we want to have in an image increases. Suppose you have an image with some pixels with colors wide apart in the spectrum of colors. This will cause a memory access problem since the direct address space need to display an image on a screen will be large. The concept of planar graphics brings a solution to this problem. Each image is represented as multiple planes. Each plane would represent a part of the pixel data (and not the entire pixel data).</p>
<h2 id="color-models">Color Models</h2>
<p>There are various methods to make use of the planar model of graphics. One is to adopt the physical nature of light and colours. There are three primary colours in nature, namely Red, Green and Blue. All other colours are basically composition of these three colours by various amounts. For example Red and Green without blue will give us Yellow. This concept brings us a RGB colour model, where each plane will represent either the Red, Green or Blue component of the image.</p>
<h2 id="mode-13h">Mode 13h</h2>
<p>While this is an unrelated topic, I think this is worth mentioning about the non-planar graphics mode in VGA. The VGA hardware included a <a href="https://en.wikipedia.org/wiki/Mode_13h">special graphics mode</a> where each pixel drawn on the screen was represented by 8-bits in the graphics memory. There were 256 indexed predefined colors in the palette, and this mode was enabled when the <code>AL</code> value is <code>0x13</code> and <code>AH</code> value is <code>0x00</code> and BIOS interrupt <a href="https://en.wikipedia.org/wiki/INT_10"><code>10h</code></a> is executed. Even before this, BBC Micro had a smaller palette of 8 colors using its 3-bit color graphics adapter. Read more about different color depths <a href="https://en.wikipedia.org/wiki/Color_depth">here</a>. The default 256-color VGA palette is shown below.</p>
<p><img src="images/vga_palette_13h.png"></p>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'subinsebastien';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</body>
</html>