You are on page 1of 6

Color Image Processing

Color Fundamentals:

Color fundamentals involve understanding the basic principles of how colors are perceived,
represented, and manipulated. Here are key concepts related to color fundamentals:

1. Additive Color Model

In the additive color model, colors are created by combining different intensities of red,
green, and blue light. The combination of full intensities in all three channels results in white
light.

Example: In a computer monitor, colors are displayed using the RGB model.

2. Subtractive Color Model:

In the subtractive color model, colors are created by subtracting light wavelengths. This
model is commonly used in color printing and involves cyan, magenta, yellow, and black
(CMYK).

Example: In color printing, the CMYK model is used to produce a wide range of colors by
combining these ink colors.

Color Models:

1. RGB Model:

Standard for electronic displays and digital imaging.

Example - RGB Model:

In the RGB model, a pixel is represented as a combination of red, green, and blue intensities.
A pixel with full intensity in all three channels (255, 255, 255) results in white color.

2. CMYK Model:

Used in color printing and represents colors using cyan, magenta, yellow, and black.

Example - CMYK Model:

In CMYK used for printing, a pixel with no ink in any channel (0, 0, 0, 0) results in white,
while full ink in all channels (100, 100, 100, 100) produces black.
3. HSV Model:

Describes colors in terms of hue, saturation, and value.

Example - HSV Model:

In the HSV model, a color can be represented as (120, 100, 100), where 120 is the hue
(green), 100 is the saturation, and 100 is the value (brightness).

Color Transformation:

1. RGB to Grayscale:

The luminance (intensity) information is retained, while color information is discarded.

2. RGB to HSV:

Represents colors using Hue, Saturation, and Value, which can be more intuitive for certain
applications.

Conversion involves mathematical transformations based on RGB values.

3. RGB to CMYK:

Useful for color printing. Each channel in CMYK represents the amount of cyan, magenta,
yellow, and black ink required.

Conversion involves mathematical transformations based on RGB values.


Example - RGB to HSV Transformation:

import cv2

import numpy as np

# Read an image in RGB

image_rgb = cv2.imread("example_image.jpg")

# Convert RGB to HSV

image_hsv = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2HSV)

# Display the original and transformed images

cv2.imshow("Original Image", image_rgb)

cv2.imshow("HSV Image", image_hsv)

cv2.waitKey(0)

cv2.destroyAllWindows()

Smoothing and Sharpening:

1. Smoothing Techniques:

Reducing noise and details using filters like Gaussian or mean filter.

2. Sharpening Techniques:

Enhancing edges and fine details using filters like Laplacian or unsharp mask.

Color Segmentation:

1. Thresholding:

Dividing an image into regions based on intensity or color thresholds.

2. Region Growing:

Merging pixels into regions based on similarity criteria.


Wavelet and Multi-Resolution Processing

Image Pyramids:

1. Gaussian Pyramid:

Reducing image resolution using convolution with a Gaussian filter.

2. Laplacian Pyramid:

Representing image details at different scales.

Multi-Resolution Expansion:

1. Image Scaling:

Changing the resolution of an image for different purposes.

2. Aliasing:

Undesirable artifacts when downsampling without proper filtering.

Wavelet Transform:

1. Wavelet Basics:

Representing signals as a sum of scaled and shifted versions of a mother wavelet.

2. Wavelet Decomposition:

Decomposing an image into approximation and detail coefficients at different scales.

Applications:

1. Image Compression:

Efficiently representing and transmitting image information.

2. Feature Extraction:

Identifying important features at different scales for analysis.


Program

First, you need to install the PyWavelets library if you haven't already:

pip install PyWavelets

Now, let's create a basic example for a 1D signal using wavelet transform and multi-
resolution analysis:

import numpy as np

import matplotlib.pyplot as plt

import pywt

# Generate a simple 1D signal

signal_length = 512

t = np.linspace(0, 1, signal_length, endpoint=False)

signal = np.sin(2 * np.pi * 7 * t) + np.cos(2 * np.pi * 20 * t)

# Wavelet Transform

wavelet = 'db1'

level = 4

coeffs = pywt.wavedec(signal, wavelet, level=level)

# Multi-Resolution Analysis

fig, axs = plt.subplots(level + 2, 1, figsize=(10, 8))

# Plot the original signal

axs[0].plot(t, signal, 'b-', label='Original Signal')

axs[0].set_title('Original Signal')

# Plot the wavelet coefficients

for i in range(1, level + 2):

axs[i].plot(coeffs[i - 1], label=f'Level {i}')


if i == level + 1:

axs[i].set_title('Approximation Coefficients')

else:

axs[i].set_title(f'Detail Coefficients - Level {i}')

plt.tight_layout()

plt.show()

You might also like