Homography and Textures in Image Processing

Rafael Madrigal
3 min readSep 14, 2022

--

In computer vision, any two images of the same planar surface in space are related by a homography. It is usually represented by a 3x3 transformation matrix that can be a combination of rotation, translation, scaling, or skew operations.

Basically, we use homography to perform operations on the images that would allow us to stretch, skew, or align in the way we wanted to. In the example below, we marked the corners of the chessboard and used homography transforms to rotate (and skew) it such that the corners we identified are located in the destination points.

chess = imread('chess.png')# Location of Corners
src = np.array([391, 100,
14, 271,
347, 624,
747, 298,
]).reshape((4, 2)
# Destination/ Orientation Desireddst = np.array([100, 100,
100, 650,
650, 650,
650, 100,
]).reshape((4, 2))
# Transform Operationfrom skimage import transform
tform = transform.estimate_transform('projective', src, dst)
tf_img = transform.warp(chess, tform.inverse)

Noticed that in the projective transform, the corners of the chessboard are now located in the destination corners. The red dots in the image refer to the original location of each of the corners. In the transform, we did not only rotate the image but also conducted a stretching in the horizontal and vertical directions to “straighten” the image.

With this example, we can immediately think of document scanner applications on our phones that automatically straightens the image before saving it as a pdf. Another would be in shooting panoramic images. Our cameras connect similar components or portions of the image and perform homography transforms to connect and align them.

Texture Metrics

We use texture metrics when we want to consider the spatial arrangement of intensity values. We resort to this in cases where the image has inconsistent color information which may be from the way it was generated. The general approach in computing for texture is as follows:

  1. Define a moving window across the image
  2. Compute for the occurrence histogram of the gray levels in the window
  3. Compute the probability array given the window
  4. Compute for corresponding Texture Metric given the probability array

One approach is to use entropy as a metric. Entropy detects variations in the intensity values in grayscale and allows us to look beyond the texture present in the image. A simple demonstration of this is using a simple structural element with a noise mask

import matplotlib.pyplot as plt
import numpy as np
from skimage import data
from skimage.util import img_as_ubyte
from skimage.filters.rank import entropy
from skimage.morphology import disk
# Structural Element with some random noise
img_mask = np.full((128, 128), 28, dtype=np.uint8)
img_mask[32:-32, 32:-32] = 30
orig_image = (img_mask * np.random.random(img_mask.shape) - 0.5 *
img_mask).astype(np.uint8)
# Accentuating the Noise present in the image
noisy_image = orig_image + 128

# See beyond the texture/ noise by detecting variations in intensity values
entr_img = entropy(img, disk(10)

Wrapping Up

In this brief article, we learned about how we can use homography to reorient images and to use texture metrics to characterize our images. Next, we look at how we can use templates to locate objects in an image.

--

--

Rafael Madrigal

Data Scientist and Corporate Strategist. Can’t function without Coffee