Posts

Showing posts from April, 2025

Wavelet Transform for Feature Extraction and Image Compression using Python and OpenCV

Wavelet Transform for Feature Extraction & Image Compression In this tutorial, we explore three important applications of the Discrete Wavelet Transform (DWT) using Python. You will learn how to: Extract features from an MRI image using wavelet decomposition. Perform image compression using DWT and hard thresholding. Compare compression results between FFT and DWT methods. This tutorial is based on the experiment documented in ​:contentReference[oaicite:0]{index=0} . Task 1: Feature Extraction using Wavelet Transform We first load an MRI image in grayscale and then apply a 2D Discrete Wavelet Transform (DWT) using the Haar wavelet. We also extract 1D signals from the approximation coefficients and display the wavelet decomposition components. Import Required Libraries import numpy as np import pywt import cv2 import matplotlib.pyplot as plt Load Image and Apply DWT # Load MRI image in grayscale de...

Texture Classification with GLCM and LBP Features in Python

Texture Classification with GLCM & LBP Features In this tutorial, we demonstrate how to perform texture classification using a combination of GLCM (Gray-Level Co-occurrence Matrix) and LBP (Local Binary Pattern) features. We’ll download a dataset, extract features from images, and then train a Random Forest classifier to predict texture categories. This tutorial is based on the experiment documented in ​:contentReference[oaicite:0]{index=0} . Step 1: Download and Extract the Dataset We use Python's requests and tarfile libraries to download and extract the Describable Textures Dataset (DTD). The dataset is stored as a compressed tar.gz file. import requests import tarfile import os # Download the dataset if not already downloaded url = "https://www.robots.ox.ac.uk/~vgg/data/dtd/download/dtd-r1.0.1.tar.gz" filename = "dtd-r1.0.1.tar.gz" if not os.path.exists(filename): print("Downloading dataset...") ...

Image segmentation Techniques in Python

Image
Image Segmentation Tutorial: Watershed & Graph Cut This tutorial demonstrates two powerful image segmentation techniques using Python and OpenCV. In the first part, you'll learn how to segment an image using the Watershed algorithm – a process that includes grayscale conversion, Gaussian blurring, thresholding, and distance transformation. In the second part, the Graph Cut algorithm is applied to segment an image by separating the foreground and background using a cost function based on edge weights. This tutorial is based on the experiment documented in ​:contentReference[oaicite:0]{index=0} . Task 1: Watershed Algorithm Segmentation The Watershed algorithm is used to separate overlapping objects in an image. In this example, we perform the following steps: Load the image using OpenCV Preprocess the image by converting it to grayscale, applying Gaussian blur, and thresholding Compute the distance transform and segmen...

Histogram Equalization & Edge Detection techniques using Python and OpenCV

Image
Histogram Equalization & Edge Detection Tutorial This tutorial walks you through two important tasks in image processing. In Task 1, you will learn how to implement histogram equalization from scratch to enhance the contrast of a grayscale image. Task 2 compares the performance of Sobel and Canny edge detection methods on images with simple and complex edges using OpenCV. Task 1: Histogram Equalization from Scratch This task enhances the contrast of a grayscale image by redistributing its intensity values without using OpenCV's built-in functions. Step 1: Import Required Libraries import matplotlib.pyplot as plt import numpy as np import time import cv2 Step 2: Define Helper Functions These functions load the image, compute its histogram, the cumulative distribution function (CDF), normalize the CDF, and finally perform histogram equalization. def load_image(path): """Load image using matplotlib"...

Contrast Enhancement Techniques in Image Processing using Python

Image
Image Processing Tutorial: Contrast Enhancement & Smoothing Methods In this tutorial, we will walk through two essential tasks in image processing. The first task demonstrates how to perform contrast enhancement without using OpenCV, and the second compares different smoothing methods using OpenCV. Both sections include detailed code explanations and visual results using Python libraries. Contrast Enhancement without OpenCV This task covers loading an image, converting it to grayscale manually, and then applying contrast enhancement through histogram stretching. Step 1: Import Required Libraries from PIL import Image import numpy as np import matplotlib.pyplot as plt Step 2: Load and Display the Original Image # Load the image using PIL img_pil = Image.open('/content/img2.jpg') plt.figure(figsize=(6, 6)) plt.imshow(img_pil) plt.title('Original Image (Task 1)') plt.axis('off') plt.show() Step 3: Convert...