← All posts
Tag

image-processing

39 posts · browse all tags

Fundamentals
·15 min read Intermediate

Boundary Detection: Finding Lines and Circles with the Hough Transform

How to find straight lines and circles in an image without being told where they are, and why the same method works for any shape you can write as an equation. One pipeline, from image to grey to edges to votes to the best shapes, run on the lane markings of a highway and the balls on a pool table, and checked against what a person drew by hand.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·14 min read Intermediate

The Hough Circle Transform: Finding Pool Balls with HoughCircles

The Hough circle transform finds round things by letting every edge pixel vote for the centres a circle through it could have. On three photos of a pool table with 41 hand-labelled balls, OpenCV's HoughCircles finds 27 with one false alarm, and 17 of 26 on the two photos it was not tuned on. Built from scratch at one radius and checked against OpenCV on the biggest ball.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·8 min read Intermediate

What Is the Hough Transform? Finding Lines by Voting

The Hough transform finds straight lines by letting every edge pixel vote for every line that could pass through it. On a dashcam highway frame, 1,749 edge pixels cast 314,820 votes and the 15 strongest lines all lie on painted lane markings, but on only two of them. A from-scratch accumulator matches cv2.HoughLines vote for vote.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·8 min read Intermediate

Fitting a Line to Points: Least Squares vs Total Least Squares

The line you fit to a set of points depends on how you measure the distance to it. Worked by hand on eight pixels of a painted lane dash: least squares y on x gives 18.5°, x on y gives 32.7°, total least squares 20.2°. Over 473 lane markings, the two least-squares lines differ by more than 1° on a third of them.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·8 min read Intermediate

Probabilistic Hough Transform: Lane Segments with OpenCV's HoughLinesP

The full Hough vote reports lines that are not lanes. On a hard dashcam frame it gives 72 lines, 18 of them on paint; dropping near-horizontal lines and voting within ±5° of each pixel's gradient leaves 13, all on paint. Over 299 frames that takes the median share of lines on paint from 50% to 100%, and leaves 108 frames with no line at all.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·8 min read Beginner

Find Every Ball on a Pool Table with OpenCV

The second OpenCV in Practice project: find the balls on a pool table by the one colour they are not, the cloth, and score the result ball by ball against a hand count on three photos. 29 of 41 found with 2 false alarms; 9 of the 12 misses are touching another ball.

opencvimage-processing
Read more →
Fundamentals
·6 min read Beginner

Fix a Badly Exposed Photo with OpenCV

The first OpenCV in Practice project: open a photo taken two stops too dark, read its histogram, try five ways to fix it, and measure each against a longer, better-exposed shot of the same scene (the target). Multiplying lands closest; the automatic fixes land furthest.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Brightness and Contrast in OpenCV

Brighten an underexposed photo two ways, adding a constant with cv2.add or multiplying with cv2.convertScaleAbs, and measure which lands closer to the target exposure: 18.0 against 9.1.

opencvimage-processing
Read more →
Fundamentals
·6 min read Beginner

Where Color Detection Fails in OpenCV

Score a colour-mask pipeline against a hand count on three pool table photos, fix the pockets and the shadows, and see what colour cannot fix: 27 of 41 balls found at first, 29 after the fixes, 9 of the 12 misses touching another ball.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Crop, Resize and Save an Image in OpenCV

Finish the fix: crop the colour chart with array slicing, shrink the photo with cv2.resize and INTER_AREA, and save it with cv2.imwrite, where the same picture is 54 KB as a JPEG and 276 KB as a PNG.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Gamma Correction in OpenCV with a Lookup Table

Build a 256-entry lookup table and apply it with cv2.LUT to brighten dark tones more than bright ones. Two stops dark, multiplying wins (9.1 against 10.7); three stops dark, gamma wins (13.9 against 15.1).

opencvimage-processing
Read more →
Fundamentals
·4 min read Beginner

Find the HSV Range of an Object in OpenCV

Read pixels of a pool table in HSV with cv2.cvtColor and find the range its cloth takes: its green value falls almost tenfold between the lit end and a shadow while its hue stays between 86 and 90.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Histogram Equalization and CLAHE in OpenCV

Try OpenCV's automatic contrast fixes, cv2.equalizeHist and CLAHE, on a dark photo with a bright lamp in it, and measure why they land further from the target exposure (30.6 and 35.5) than a plain multiplier (9.1).

opencvimage-processing
Read more →
Fundamentals
·4 min read Beginner

Find, Measure and Filter Contours in OpenCV

Find the outline of every blob in a mask with cv2.findContours, measure its area and roundness, and keep the ones shaped like a ball. On the pool table 11 of 14 blobs pass and the cue is rejected at roundness 0.12.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Image Histograms in OpenCV

Count how many pixels sit at each brightness with cv2.calcHist, draw the histogram, and read from it that the dark photo has 79.3% of its pixels in the bottom quarter and 7.8% burnt out.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Make a Color Mask with cv2.inRange in OpenCV

Turn an HSV range into a black-and-white mask with cv2.inRange, flip it with bitwise_not and apply it with bitwise_and. On the pool table one call marks 79.3% of the photo as cloth.

opencvimage-processing
Read more →
Fundamentals
·4 min read Beginner

Erode, Dilate, Open and Close a Mask in OpenCV

Clean a colour mask with morphology: erosion shrinks white areas, dilation grows them, opening removes specks and closing fills holes. On the pool table the mask goes from 59 blobs to 14.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Open an Image and Read Its Pixels in OpenCV

Load a photo with cv2.imread, see that it is a grid of numbers with a shape and a type, and read one pixel and the mean brightness of a photo taken two stops too dark.

opencvimage-processing
Read more →
Fundamentals
·7 min read Beginner

An Image Is an Array: Shape, dtype, and Why OpenCV Hands You BGR

Lesson 1 of The Image as Data. One photograph, held three ways: a 24.7 MB mosaic of 12-bit counts, a 74.2 MB 16-bit development, and the 37.1 MB 8-bit array imread would give you. Two thirds of the numbers in that last one were never measured, adding 60 to a value of 207 gives 11, and a slice you write into changes the original.

image-processingopencvfundamentals
Read more →
Fundamentals
·9 min read Intermediate

From Photons to Counts: What a Raw Number Means

A photosite collects electrons, a converter turns them into an integer, and that integer is all any algorithm ever sees. Measured on eighteen exposures of one scene: the count doubles with the shutter to within a few percent, then sticks near 3875 DN, and the ceiling the file declares is not the ceiling the sensor has.

image-processingsensorsfundamentals
Read more →
Fundamentals
·9 min read Intermediate

High Dynamic Range: Merging a Bracket, Then Checking It Against a Meter

Eighteen exposures of a 17-stop scene, merged into one radiance map, calibrated with a single scale factor fitted on one patch, then compared with the colorimeter readings taken in the room. Across all 48 patches (the anchor included) the median error is 0.198 stops, 0.109 across the neutral patches, and every large error is at the dark end.

image-processingsensorsfundamentals
Read more →
Fundamentals
·8 min read Intermediate

How Close Is Your Colour to the Real Thing?

Lesson 5 of The Image as Data. Converting between colour spaces is exact arithmetic; deciding what the numbers mean physically is a fit. Checked against a colorimeter on 22 chart patches: treating the developed file as sRGB lands 9.54 ΔE*ab from the light in the room, the camera's own published matrix does no better, and a 3x3 fitted here and scored on patches it never saw reaches 2.41.

image-processingcolor-spacesfundamentals
Read more →
Fundamentals
·9 min read Beginner

File Formats: What the Encoder Did Before You Read the Pixels

Lesson 6 of The Image as Data. A JPEG quality sweep costs almost nothing in PSNR and takes Canny's edge agreement from 0.949 to 0.895. Chroma subsampling saves 40% of the bytes for 0.09 of ΔE. And OpenCV and Pillow decode every JPEG here bit-for-bit identically; the disagreement is a 16-bit PNG, which Pillow silently opens as 8-bit.

image-processingopencvfundamentals
Read more →
Fundamentals
·10 min read Beginner

Image Sensing: What the Number in a Pixel Actually Counts

The unit overview: how a photon becomes an integer, why that integer is a random variable, what the tone curve did to it before you saw it, and how eighteen exposures merge back into light you can put a unit on. Measured on one scene: gain 0.294 DN per electron, a full well near 13,200 e⁻, and a merged bracket that lands 0.109 stops from a colorimeter across the neutral patches.

image-processingsensorsfundamentals
Read more →
Fundamentals
·7 min read Beginner

Quantization: How Many Bits a Pixel Deserves

Lesson 3 of The Image as Data. Rounding to fewer levels costs Δ/√12 of error, and on this camera's mid-tones the formula predicts the measurement to within 6% at 10 bits and within 2% from 8 bits down. Set that error equal to the read noise unit 1.2 measured and the crossing lands at 9.3 to 9.5 bits, so a 12-bit file on this sensor carries about two and a half bits of nothing.

image-processingsensorsfundamentals
Read more →
Fundamentals
·9 min read Beginner

Sampling: What One Pixel Covers, and What Falls Between

Lesson 2 of The Image as Data. One photosite on this camera is 5.527 µm and covers 1.056 arcminutes of the room. The table in the frame is ribbed at 7.4 pixels per cycle; keep every 8th pixel and it comes back at 96 pixels per cycle, thirteen times too coarse, in the frequency bin that folding predicts.

image-processingfundamentals
Read more →
Fundamentals
·6 min read Intermediate

Sensing Colour: The Bayer Mosaic, and What Interpolation Costs

A silicon photosite is colourblind, so a mosaic of filters gives each one a single colour: a quarter red, a quarter blue, half green. Two thirds of every colour image is therefore interpolated, and measured against photosites that actually exist, that guess costs 4.7 DN on a flat patch and 129.9 DN at an edge, twenty-eight times worse where it shows.

image-processingsensorsfundamentalscolor-spaces
Read more →
Fundamentals
·9 min read Intermediate

Sensor Noise and Dynamic Range: Measuring the Gain You Were Never Told

Read the same photosite three times and you get three numbers. Plotting the variance of a count against its mean gives a straight line whose slope is the sensor's gain: 0.294 DN per electron on this camera, R² = 0.986, a full well of 13,199 electrons and at least 11.21 stops of dynamic range, none of which appears anywhere in the file.

image-processingsensorsfundamentals
Read more →
Fundamentals
·8 min read Intermediate

The Camera Response Curve: Why Your JPEG Is Not Proportional to Light

Raw counts are proportional to the light that arrived. The developed file is not: on six neutral patches, a 42:1 ratio of light comes out as 187 against 14 code values. Measured here, the file sits a mean 9.6 code values off the sRGB curve, and the BT.709 curve the developer applied by default accounts for most of that.

image-processingsensorscolor-spacesfundamentals
Read more →
Fundamentals
·8 min read Beginner

The Image as Data: The Grid, the Integers, the Axes, and the File

The unit overview: what an array actually holds, where its samples sit, how finely each one is written down, what its three numbers mean, and what the encoder did before you read any of it. Measured on one photograph: two thirds of a colour image is interpolated, a 7.4-pixel ribbing returns as 96-pixel banding when you decimate by eight, bit depth stops buying anything at 9.4 bits, and the naive route from file to colour lands 9.54 ΔE from the light in the room.

image-processingopencvfundamentals
Read more →
Fundamentals
·9 min read Intermediate

Canny: Non-Maximum Suppression and Hysteresis, Taken Apart

Canny is two independent mechanisms. NMS collapses a five-pixel ridge to one pixel by comparing along the gradient; hysteresis keeps a weak chain because it touches a strong seed. Worked on nine numbers: a single threshold gives either 1 pixel or 9, and hysteresis gives the 6 that belong to a real contour. Measured on a photo, that is 204 contours averaging 18.68 px against 393 averaging 9.69 px at the same pixel budget.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·10 min read Intermediate

Corners: The Structure Tensor, Harris, Shi-Tomasi and Förstner

A contour says where a boundary runs but not where you are along it. Two eigenvalues of a 2x2 matrix fix that: measured on a real photo, flat background scores 0.001/0.000, an edge 0.411/0.019 and a corner 0.442/0.318. Harris, Shi-Tomasi and Förstner all read that same matrix, and on the edge patch Harris comes out positive at k = 0.04 and negative at k = 0.06, so k decides the answer rather than the data.

image-processingedge-detectionfeaturesfundamentals
Read more →
Fundamentals
·14 min read Beginner

Edge Detection: Finding Where One Thing Stops and Another Begins

How to find, in any photo, the places where one thing stops and another begins, and turn them into a clean black-and-white edge map. One pipeline, from grey to smoothed to the change at every pixel to thin linked edges, with corners as a branch, measured on one photo and shown step by step on another.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·10 min read Intermediate

Image Gradients: Central Differences, Prewitt and Sobel

Three operators compute the same derivative and behave differently on a noisy photo. Worked by hand on a 3x3 patch: Sobel gives Gx = Gy = 1.80, a magnitude of 2.55 and an orientation of 45 degrees, while Prewitt gives 1.20 and 1.70 on identical pixels. Measured across a noise sweep, Prewitt beats Sobel at every level, and the reason is that its normalised weights have a smaller sum of squares.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·9 min read Intermediate

The Laplacian, LoG and Zero-Crossings

The second derivative crosses zero at an edge instead of peaking, and interpolating between two samples places a step edge at x = 3.5. The naive Laplacian has no smoothing in it: nine pixels disturbed by 0.03 produce four sign changes where there should be one. Measured on a photo, noise multiplies the zero-crossing pixels by 2.76x at sigma = 1.0 and 1.02x at sigma = 3.0, and only 33% of the clean-image contours are closed.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·9 min read Beginner

What Is an Edge? Step, Ramp and Roof, and the Two Derivatives That Find Them

An edge is a peak in the first derivative and a sign change in the second. Worked by hand on nine pixels: the peak lands on column 4 and the second difference is exactly zero there. Add noise of at most 0.03 and the zero-crossing moves by 0.05 px, which is small; the real cost of the second derivative is the sign changes noise makes on its own, with no size attached to threshold, which is why Canny is built on the first derivative.

image-processingedge-detectionfundamentals
Read more →
Fundamentals
·14 min read Beginner

Image processing, computer vision, and computer graphics: one picture, three directions of the arrow

Three fields, one shared object: the digital image. Graphics turns a model into an image (forward), vision turns an image into a model (inverse), and image processing turns an image into a better image. Worked on a single red-ball scene, with a 1957→2026 timeline of how they split apart and re-merged.

image-processingfundamentals
Read more →
Fundamentals
·8 min read Beginner

How 2D Convolution Works on Images: Kernels, Filters, and the Math, Interactively

2D convolution is the operation behind blur, sharpening, edge detection, and every CNN. Slide a kernel, multiply, sum: see it happen step by step in an interactive demo, apply real kernels to a live image, and get the math plus runnable OpenCV in Python and C++.

image-processingopencvfundamentals
Read more →
Fundamentals
·9 min read Beginner

Colour Spaces: Choosing Axes You Can Threshold

Lesson 4 of The Image as Data. A colour space is a choice of axes for the same three numbers, and the choice is what makes a question easy or impossible. Worked on one measured chart patch: RGB (149.8, 58.3, 34.0) becomes luma 82.8, hue 12.6 degrees stored as 6, and Lab (36.9, 37, 34), plus the five-line red detector that is brittle in RGB and robust in HSV.

image-processingopencvcolor-spacesfundamentals
Read more →