Skip to content

Computer vision cookbook

From problem to pixels23 runnable recipes

Combine a few algorithms into something useful. Bring your images, select a region, tune the controls and inspect every step.

Start with tracking a region between two frames, counting objects or flattening a document. Each recipe explains its assumptions and links to the algorithms behind it.

Categories
Choose individual algorithms 23 selected

Uncheck an algorithm to hide it. Category filters and the search above still apply.

Motion and matching

Measure regional motion vectors

Measure delta vectors between a before frame and an after frame. See how far each region translated during a camera pan, inspect dense dx/dy values, or subtract the dominant image motion.

Compensate for the initial pan → Estimate dense displacement → Check texture and summarize regions
Motion and matching

Track a selected region

Upload a before frame and an after frame, then draw a region on the first image. Track its corners and estimate where that region moved.

Find corners in the region → Track forwards and backwards → Fit a robust transform
Motion and matching

Find a patch in another image

Draw a patch on the first image and locate its best matching position in the second image.

Crop the selected patch → Search the next image → Mark the strongest response
Motion and matching

Align two overlapping images

Match ORB features, reject inconsistent correspondences with RANSAC, then warp the second image into the first image’s coordinates.

Describe both images → Keep consistent matches → Warp to the reference
Motion and matching

Visualize verified feature matches

See which ORB descriptor matches agree with one estimated projective transform.

Extract ORB features → Match descriptors → Verify geometry
Motion and matching

Find changed regions between frames

Compare two frames, suppress noise, clean the difference mask and draw connected changed regions.

Suppress image noise → Threshold frame differences → Group changed pixels
Motion and matching

Highlight structural image differences

Compute a local SSIM map, threshold low similarity and highlight contiguous differences on the second image.

Measure structural similarity → Select low-similarity pixels → Draw difference regions
Regions and masks

Count separated objects

Separate bright objects from a dark background, clean the mask and count connected regions that pass an area filter.

Create a foreground mask → Remove small noise → Count components
Regions and masks

Separate touching objects

Use peaks in the foreground distance map as seeds for watershed segmentation.

Threshold the foreground → Find interior seeds → Flood from the seeds
Regions and masks

Measure contour geometry

Threshold a silhouette, simplify its outline, and report each retained shape’s area, perimeter, circularity and centroid.

Extract silhouettes → Find and simplify contours → Measure geometry
Regions and masks

Select and group a colour

Select an HSV colour range, close small holes and outline matching colour regions.

Convert BGR to HSV → Select the colour interval → Clean and group the selection
Regions and masks

Crop the largest foreground object

Threshold and clean a mask, find the largest external contour, then crop its bounding box with padding.

Build a clean mask → Find the largest object → Crop its bounding rectangle
Regions and masks

Create a transparent cutout

Draw a rectangle around the subject, refine its foreground mask with GrabCut, then export the cutout as RGBA.

Initialize foreground models → Refine the mask → Build an alpha channel
Photography

Keep a subject sharp

Select the subject, separate it with GrabCut, then blend it over a blurred version of the image.

Separate the subject → Blur the surroundings → Blend with the mask
Photography

Blur a selected region

Draw an area to blur while preserving the rest of the image.

Make a region mask → Blur the image → Copy through the mask
Photography

Denoise and restore local contrast

Reduce colour noise, then enhance luminance contrast without applying separate histogram equalization to each colour channel.

Remove similar-patch noise → Work in Lab luminance → Enhance local lightness
Photography

Sharpen edges with an unsharp mask

Subtract a smoothed image to isolate detail, then add a controlled amount of that detail back.

Estimate the smooth image → Extract signed detail → Add the detail back
Photography

Inspect local sharpness

Compute a Laplacian response, square it and average locally to visualize high-frequency energy.

Measure second derivatives → Measure local energy → Visualize the field
Documents

Find and flatten a document

Find the largest convex quadrilateral in the edge map, correct its perspective, then produce a locally thresholded document view.

Detect document outlines → Choose four corners → Flatten and binarize
Documents

Clean uneven document lighting

Estimate the background illumination, divide it out, then apply local thresholding.

Estimate illumination → Normalize the page → Separate ink
Documents

Straighten a tilted page

Estimate a dominant near-horizontal line angle and rotate the page to make those lines level.

Find strong edges → Estimate the tilt → Rotate around the centre
Geometry

Estimate depth from rectified stereo

Compute disparity, reject invalid matches and convert positive disparities into depth using the supplied focal length and camera baseline.

Match rectified rows → Reject invalid disparities → Convert disparity to depth
Photography

Simplify an image into colour regions

Smooth small colour fluctuations, cluster colours with k-means and render the reduced palette.

Smooth within colour regions → Learn a palette → Recolour the image