Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 166 - 2615_KEC
P. 166

    Once the image is read, it can be displayed on the screen using the imshow() function. This
                      function creates a window and shows the image as visual output. The program usually waits for a
                      key press before closing the window, which allows the user to view the image properly.

                      In simple terms, reading an image allows the computer to access its pixel data, and displaying the
                      image allows the user to see the result. These steps form the basic foundation of image processing
                      in OpenCV.

                      Program 1: To read and display an image.

                          Program1.py

                       File  Edit  Format    Run   Options   Window    Help

                       import cv2
                       image = cv2.imread("Flower.jpg")
                       cv2.imshow("Flower", image)

                          Output

                      DIMENSIONS OF AN IMAGE

                      The dimensions of an image describe its size in terms of pixels. Every digital image has a height
                      and a width. The height refers to the number of rows of pixels, and the width refers to the number
                      of columns of pixels. For example, if an image has dimensions of 800 × 600, it means the image

                      is 800 pixels wide and 600 pixels tall.

                      In a grayscale image, the dimensions are represented by two values: height and width. This is
                      because each pixel stores only one brightness value. Therefore, the image can be represented as
                      a two-dimensional array, where rows and columns define the structure.

                      In a colour image, the dimensions include an additional value called channels. Since each pixel

                      contains  three  values, Red, Green  and  Blue,  the  image  is  represented  as  height  × width  × 3.

                      164   Premium Edition-VIII

| 161 162 163 164 165 166 167 168 169 170 171 |