Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 171 - 2615_KEC
P. 171

    Program 7: To darken the whole image.

                         Program7.py
                      File  Edit  Format   Run    Options   Window    Help

                      import cv2
                      # Read the image
                      image = cv2.imread("Flower.jpg")
                      # Darken the entire image by reducing brightness
                      dark_image = cv2.subtract(image, 50)   # 50 decreases brightness
                      # Display the result
                      cv2.imshow("Darkened Image", dark_image)

                     The output of the preceding code would be as follows:

                         Output

                          REVISIT

                       ▶   A computer works with images in a very different way from humans.
                       ▶   OpenCV is widely used in various real-world applications that involve image and video processing.
                       ▶   A value of 0 represents black, 255 represents white and values in between represent different shades of grey.
                       ▶   Reading an image means loading it from a file into a program so that it can be processed.
                       ▶   The dimensions of an image describe its size in terms of pixels.
                       ▶   Converting an image to grayscale means removing its colour and changing it into shades of grey.
                       ▶   Cropping an image means selecting and keeping only a specific portion of the image while removing the rest.
                       ▶   Cropping helps focus on an important area, remove unwanted parts or highlight a specific object.
                       ▶   Shading a portion of an image in OpenCV means modifying the brightness of a selected area.

                                                                                                            OpenCV    169

| 166 167 168 169 170 171 172 173 174 175 176 |