Image Processing Lab PDF
Document Details
Uploaded by Deleted User
Eng. Eman Salem
Tags
Summary
This document is a presentation on the fundamental concepts of image processing, covering various aspects such as image basics, color spaces, transformations, filtering, and morphological operations. It provides a detailed overview of different image processing techniques and applications demonstrating their practical relevance. The presentation also highlights using the OpenCV library for implementation of these methods.
Full Transcript
Introduction To Image Processing Eng. Eman Salem Outlines what is Image processing. Image Processing Applications. Digital Image Basics. Types of Images. Image Formats. Image Processing Basic Operations. Coloer Spaces...
Introduction To Image Processing Eng. Eman Salem Outlines what is Image processing. Image Processing Applications. Digital Image Basics. Types of Images. Image Formats. Image Processing Basic Operations. Coloer Spaces. Image Transformation. Image Filtering. Image processing is a method to perform operations on an image to extract meaningful information, enhance its quality, or transform it into a desirable format. It is essential for analyzing visual data, what is Image improving image quality, and facilitating machine processing understanding of images. image processing helps computers or systems "understand" and make decisions based on visual information. Image Processing Applications Medical Imaging: MRI, CT scans, X-rays, segmentation for diagnosis Computer Vision: Autonomous vehicles, facial recognition, object detection Remote Sensing: Satellite image analysis, environmental monitoring Robotics: Machine vision, object tracking in industrial robots Biometrics: Face, fingerprint, iris, and voice recognition AR/VR: Augmented reality, virtual reality experiences Photography and Film: Enhancing photos, compression, noise reduction Forensics: Image enhancement for forensic analysis Optical Character Recognition (OCR): Extracting text from scanned documents or images Gaming: Real-time rendering in gaming, player tracking What is a Digital Image A digital image represents a real image as a set of numbers that can be stored and handled by a digital computer. To translate the image into numbers, it is divided into small areas called pixels (picture elements). For each pixel, the imaging device records a number, or a small set of numbers, that describes some property of this pixel, such as its brightness (the intensity of the light) or color. The numbers are arranged in an array of rows and columns corresponding to the vertical and horizontal positions of the pixels in the image. Digital Image Basics 1. Pixels A pixel is the smallest unit of a digital image or display. It is the basic building block of any image, representing a single point in a raster image or a single dot in a display. Digital Image Basics Representation: Each pixel has a specific color value, which is usually represented in terms of its red, green, and blue (RGB) components in color images. In grayscale images, a pixel's value corresponds to its brightness level. Grayscale: An image where each pixel represents a shade of gray, typically ranging from 0 (black) to 255 (white). RGB: Represents an image using Red, Green, and Blue channels, where each pixel contains three values corresponding to these colors. Digital Image Basics Image Resolution: The number of pixels in the width and height of an image. Higher resolution means more detail. Bit Depth: Refers to the number of bits used to represent the color of a single pixel. A higher bit depth allows more shades of colors (e.g., 8-bit per channel allows 256 shades). Types of Images Binary: Each pixel is either black (0) or white (1). Used in simple image analysis, like document scanning. Grayscale: Images that contain shades of gray without any color. Each pixel has an intensity value. Color Images: Typically represented in RGB format, each pixel contains color information from three channels red, green, and blue. Image Formats PNG: Lossless image format that supports transparency. Suitable for web graphics and images requiring high quality. PEG: Lossy format optimized for photographs with reduced file size at the cost of some quality. TIFF: Lossless format, often used in professional imaging, such as medical or publishing industries. BMP: Uncompressed image format with large file sizes but retaining high image quality. Often used in Windows applications. OpenCV Library OpenCV (Open-Source Computer Vision Library) is an open-source computer vision and machine learning software library. The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. Install OpenCV in python: pip install opencv-python Basic Operations Loading, Saving, and Displaying Images using OpenCV: Loading: Reading an image file from disk into memory. Saving: Writing an image from memory back to disk in a specified format. Displaying: Showing an image in a graphical window for viewing. Color Spaces Converting between RGB, HSV, and Grayscale: RGB (Red, Green, Blue): Standard color model used in digital images. HSV (Hue, Saturation, Value): Alternative representation of color, where hue defines the color, saturation defines the intensity, and value defines the brightness. Grayscale: Converts color images to shades of gray by averaging the RGB values, effectively reducing the image to one channel. Image Transformation Resizing: Changing the dimensions of an image by scaling it up or down. Useful for adjusting image size for different uses. Cropping: Extracting a region of interest (ROI) from an image by cutting out a specific area. Rotating the image around its center by a certain angle (e.g., 90 degrees clockwise). Flipping: Mirroring the image horizontally (left to right) or vertically (top to bottom). Resizing Resizing an image means changing its dimensions, be it width alone, height alone, or both. Also, the aspect ratio of the original image could be preserved in the resized image. Resizing involves scaling an image from its original width and height, W×H, to a new size, W ′ ×H ′, by applying interpolation methods to calculate the pixel values in the new image based on the pixels in the original image. Examples of interpolation techniques : Nearest-Neighbor Interpolation. Bilinear Interpolation. Bicubic Interpolation. Transformation Matrix used to perform operations like rotation, scaling, and translation. mathematical tool that maps points from one coordinate system to another. helps in modifying the image geometrically. Rotation Transformation Matrix For a 2D image, a point (x,y)in the image can be rotated around the origin by an angle θ using the rotation transformation matrix: R cosθ and sinθ are trigonometric functions that account for how far the point should move in the horizontal and vertical directions when rotated. The matrix is multiplied by the original point's coordinates to get the new position. Negative sine ensures the direction of rotation follows the correct convention (counterclockwise). Image Filtering Blurring: Reducing image details and smoothing the image by averaging pixel values. Used to reduce noise or irrelevant details. Example of smoothing image methods is : Gaussian Blur: Weighted smoothing with a bell curve. Mean Filter: Simple averaging, but may blur. Median Filter: Noise reduction without blurring, good for salt-and-pepper noise. Bilateral Filter: Smoothing while preserving edges. LoG: Edge detection combined with smoothing. Image Filtering Sharpening: Enhancing edges and fine details in the image by amplifying the differences between neighboring pixels. Image Filtering Noise Reduction: Removing unwanted random variations (noise) from an image. Common techniques include Gaussian blur or median filtering. Image Filtering Edge Detection (Canny, Sobel): Canny: A multi-step algorithm for detecting edges based on gradient intensities and thresholds. Sobel: A simpler method for finding edges by calculating gradients in horizontal and vertical directions. Report task1 Prepare a report about: Interpolation techniques. Cany and Sobel algorithm. Write a simple Python program to apply Cany edge detector on a video. Image Processing in OpenCV (2D convolution) The 2D convolution is a simple operation at heart: you start with a kernel, which is simply a small matrix of weights. This kernel “slides” over the 2D input data, performing an elementwise multiplication with the part of the input it is currently on, and then summing up the results into a single output pixel. the kernel is called the image filter and the process of applying this kernel to the given image is called image filtering. The output obtained after applying the kernel to the image is called the filtered image. Image Thresholding Simple Thresholding: Here, the matter is straight-forward. For every pixel, the same threshold value is applied. If the pixel value is smaller than the threshold, it is set to 0, otherwise it is set to a maximum value. Adaptive Thresholding : the algorithm determines the threshold for a pixel based on a small region around it. So, we get different thresholds for different regions of the same image which gives better results for images with varying illumination. Adaptive Thresholding Image Histogram Histogram is a graph or plot, which gives you an overall idea about the intensity distribution of an image. It is a plot with pixel values (ranging from 0 to 255, not always) on the X-axis and the corresponding number of pixels in the image on the Y- axis. Histogram Terminology: Bins: The histogram shows the number of pixels for every pixel value, from 0 to 255. We used 256 values (bins) to show the histogram. It could be 8, 16, 32 etc. OpenCV uses histSize to refer to bins. Dims: It is the number of parameters for which we collect the data. In this case, we collect data regarding only one thing, intensity value. So here it is 1. Range: The range of intensity values you want to measure. Normally, it is [0,256], ie. all intensity values. Morphological Transformations Morphological operations are image processing techniques that process images based on their shapes. They are often used in binary images (black and white) but can also be applied to grayscale images. The main idea behind these operations is to probe an image with a small shape or structuring element and modify the pixels accordingly. Two basic morphological operators are Erosion and Dilation. Then its variant forms like Opening, Closing, Gradient, etc. also come into play. Erosion: Removes pixels on object boundaries. It erodes the boundaries of Erosion foreground objects (makes objects smaller). The kernel slides through the image (as in 2D convolution). A pixel in the original image (1 or 0) will be considered 1 only if all the pixels under the kernel are 1, otherwise, it is eroded (made to zero). Effect: Useful for eliminating small white noises and separating connected objects. Dilation: Adds pixels to the boundaries of Dilation objects, essentially expanding or "dilating" them (makes objects larger). It is just the opposite of erosion. Here, a pixel element is ’1’ if at least one pixel under the kernel is ’1’. So, it increases the white region in the image or size of the foreground object. Effect: Useful for closing small holes within objects or joining broken parts of an object. Normally, in cases like noise removal, erosion is followed by dilation. Because, erosion removes white noises, but it also shrinks our object. So, we dilate it. Since noise is gone, they won’t come back, but our object area increases. It is also useful in joining broken parts of an object. Opening Opening: A combination of erosion followed and Closing by dilation. Effect: Used to remove small objects or noise while keeping the shape of larger objects intact. Closing: A combination of dilation followed by erosion. Effect: Used to fill small holes or gaps inside objects. Gradient Gradient is the difference between dilation and erosion of an image. The result will look like the outline of the object. Contours Contours are a powerful tool in image processing used to detect objects, shapes, and their boundaries. Contours represent the outline or the curve joining all the continuous points along a boundary of the same intensity. Contour detection is useful in various applications like object detection, shape analysis, and image segmentation. How Contour Detection Works: Contours Thresholding or Edge Detection: Contour detection usually starts by converting the image to a binary image using thresholding or edge detection (e.g., using the Canny edge detector). Contour Extraction: Once the binary image is obtained, the contours are extracted using algorithms like Suzuki and Abe’s algorithm, implemented in OpenCV as findContours(). Hierarchy Information: Contours can be organized into hierarchies (nested contours within each other), which is useful for complex object detection. Report2: Count number of Object To find the count of objects we follow the steps: 1. Read the image and convert it to grayscale 2. Blur image 3. Detect edges 4. Dilate image to connect the opening edges 5. Find contours (using cv2.findContours function) 6. Print the count of object