/ Abhishek Paudel

Basic Image Manipulation

This post is a part of assignment of my CS682 (Computer Vision) course taught by Prof. Zoran Duric in Spring 2020. I demonstrate a few basic image manipulation techniques using my 1000x1000 color image and its grayscale version as examples.

Color image Color image

Grayscale image from color image Grayscale image from color image

Swapping color channels

The green channel in the color image was swapped with blue channel to produce the following result.

RGB to RBG RGB to RBG

Gaussian blur

A Gausian filter of size 13x13 was applied to both color and grayscale images.

Gaussian blur (Color) Gaussian blur (Color)

Gaussian blur (Grayscale) Gaussian blur (Grayscale)

Cropping

The images were cropped from coordinates (200,700) to (250,650).

Cropped image (Color) Cropped image (Color)

Cropped image (Grayscale) Cropped image (Grayscale)

Thresholding

The pixel values above 100 were set to 0, and the rest were set to 255. For color image, this was done across the three color channels producing weird colors as shown.

Thresholded image (Color) Thresholded image (Color)

Thresholded image (Grayscale) Thresholded image (Grayscale)

Inverting

All the pixel values were subtracted from 255 to produce the inverted images.

Inverted image (Color) Inverted image (Color)

Inverted image (Grayscale) Inverted image (Grayscale)

Changing contrast

All the pixel values in color image were scaled by 0.5 to decrease contrast. Similarly, for grayscale image, all pixel values were scaled by 1.8 to increase contrast. Pixel values exceeding the range of [0,255] were thresholded to lie at the boundary, and the resulting floating values were truncated to integers of type uint8.

Decreased contrast (Color) Decreased contrast (Color)

Increased contrast (Grayscale) Increased contrast (Grayscale)

Changing brightness

All the pixel values in color image were increased by 50 to increase brightness. Similarly, for grayscale image, all pixel values were decreased by 100 to decrease brightness. Pixel values exceeding the range of [0,255] were thresholded to lie in the boundary.

Increased brightness (Color) Increased brightness (Color)

Decreased brightness (Grayscale) Decreased brightness (Grayscale)

Adding Gaussian noise

Gaussian noise with mean 0 and standard deviation 50 was added to the images. The strategy I applied to add noise in the image is as follows.

  1. Generate normally distributed noise of random floating numbers as an array with the same shape as the image.

  2. Add the noise to image.

  3. Threshold the pixel values exceeding the range of [0,255] to lie at the boundary.

  4. Truncate floating pixel values to integers of type uint8.

Adding Gaussian noise (Color) Adding Gaussian noise (Color)

Adding Gaussian noise (Grayscale) Adding Gaussian noise (Grayscale)

Image gradients

Sobel filters of size 5x5 was applied on grayscale image to produce image gradients along horizontal and vertical direction of image. The magnitude of gradients were also computed to produce image that contained gradients along both directions.

Image gradient along x-axis Image gradient along x-axis

Image gradient along y-axis Image gradient along y-axis

Image gradient magnitude along both axis Image gradient magnitude along both axes

Gaussian pyramid

The following figure shows the Gaussian pyramid of depth 9. At each level, the image from the earlier level is smoothed using Gaussian filter and is scaled down by half. Images generated at each level of the pyramid were combined to form one image.

Gaussian pyramid Gaussian pyramid

The algorithm I implemented to combine images from multiple levels of pyramid into one large image is as follows.

  1. Generate an ordered list of n images from all levels of pyramid in descending order of size.

  2. Assign the smallest image at level n as the result_image.

  3. Stack the result_image along the smaller lengthed axis of image at level n-1, and fill remaining locations in the image as black.

  4. Assign the image generated in step 3 as the result_image.

  5. n ← n-1

  6. Repeat step 3 to 5 until n=0.

Since images are stacked along the smaller of the two axes in step 3, this resulting image always fitted in the smallest possible rectangle. For example, since my original image size is 1000x1000, the size of smallest possible rectangle is 1500x1000, and so is the size of the final combined image. The space requirement for the combined image of pyramid is 1500*1000*3 = 4500000 bytes ≈ 4.29 MB.

A slightly different stacking strategy produces the following results.

Gaussian pyramid Gaussian pyramid with slightly different stacking strategy