官术网_书友最值得收藏!

Introduction

In order to build computer vision applications, you need to be able to access the image content and eventually modify or create images. This chapter will teach you how to manipulate the picture elements (also known as pixels). You will learn how to scan an image and process each of its pixels. You will also learn how to do this efficiently, since even images of modest dimensions can contain hundreds of thousands of pixels.

Fundamentally, an image is a matrix of numerical values. This is why, as we learned in Chapter 1, Playing with Images, OpenCV 2 manipulates them using the cv::Mat data structure. Each element of the matrix represents one pixel. For a gray-level image (a black-and-white image), pixels are unsigned 8-bit values where 0 corresponds to black and 255 corresponds to white. In the case of color images, three primary color values are required in order to reproduce the different visible colors. This is a consequence of the fact that our human visual system is trichromatic; three types of cone cells on our retinae convey the color information to our brain. This means that for a color image, three values must be associated to each pixel. In photography and digital imaging, the commonly used primary color channels are red, green, and blue. A matrix element is, therefore, made of a triplet of 8-bit values in this case.

Note that even if 8-bit channels are generally sufficient, there are specialized applications where 16-bit channels are required (medical imaging, for example).

As we saw in the previous chapter, OpenCV also allows you to create matrices (or images) with pixel values of other types, for example, integer (CV_32U or CV_32S) and floating point (CV_32F) numbers. These are very useful to store, for example, intermediate values in some image-processing tasks. Most operations can be applied on matrices of any type; others require a specific type or work only with a given number of channels. Therefore, a good understanding of a function's or method's preconditions is essential in order to avoid common programming errors.

Throughout this chapter, we use the following color image as the input (refer to the book's graphics PDF to view this image in color):

Introduction
主站蜘蛛池模板: 万州区| 色达县| 琼结县| 兴业县| 张家界市| 北碚区| 根河市| 平安县| 城口县| 来安县| 乌鲁木齐县| 轮台县| 德钦县| 亳州市| 墨脱县| 湛江市| 南华县| 临洮县| 水富县| 泽普县| 调兵山市| 遵义市| 同仁县| 通州区| 喀喇沁旗| 翁源县| 益阳市| 济宁市| 南漳县| 定安县| 科技| 大港区| 普定县| 突泉县| 塔城市| 房产| 汕头市| 图们市| 舒兰市| 韩城市| 安仁县|