Stuart Mathews
  • Home

    Latest

    • Functional XML (Game Development) 19-02-2023
    • Midnight in Paris (Blog) 04-01-2023
    • Christmas Run (Running) 26-12-2022
    • So far, it works (Game Development) 25-12-2022
    • Traveling Europe (Blog) 01-11-2022
    • Applying and Evaluating Pattern-Oriented Designs In Improving Code Quality In Complex Software (Code) 01-10-2022
    • Knoydart Peninsula, Scotland (Running) 01-10-2022
    • CppGameLib (Game Development) 12-09-2022
    • Thoughts on Multiplayer Game Co-operation and Distributed Computing (Game Development) 04-07-2022
    • The fading importance of ego and the utility of the checklist (Blog) 18-04-2022

    Most Read This Year

    • Thoughts on Multiplayer Game Co-operation and Distributed Computing (Game Development)
    • The fading importance of ego and the utility of the checklist (Blog)
    • Differential Calculus (Blog)
    • Traveling Europe (Blog)
    • Knoydart Peninsula, Scotland (Running)
    • CppGameLib (Game Development)
    • Applying and Evaluating Pattern-Oriented Designs In Improving Code Quality In Complex Software (Code)
    • So far, it works (Game Development)
    • Christmas Run (Running)
    • Midnight in Paris (Blog)

    Recently Featured

    • Functional XML (Game Development)
    • So far, it works (Game Development)
    • Thoughts on Multiplayer Game Co-operation and Distributed Computing (Game Development)
    • A software engineering process for delivering software (Code)
    • Encrypting strings at rest (Code)
    • ISO27001, Machine-Learning and Game dev (Blog)
    • Implementing a Vignette (Code)
    • Fixing the thunder in my feet (Running)
    • Sufficiently Complex (Blog)
    • Try Monad, Progress and Lockdown Rules (Blog)
    • Downloads
  • Blog

    Recent in Blog

    • Midnight in Paris 04-01-2023
    • Traveling Europe 01-11-2022
    • The fading importance of ego and the utility of the checklist 18-04-2022
    • Differential Calculus 14-04-2022
    • Fading importance and the utility of lists 29-12-2021
    • Abstractions and Patterns 11-10-2021
    • Mind Maps 02-10-2021
    • ISO27001, Machine-Learning and Game dev 23-04-2021
    • Sufficiently Complex 02-12-2020
    • Deadlocks and databases 19-10-2020

    Most Read In Blog This Year

    • The fading importance of ego and the utility of the checklist (Blog)
    • Differential Calculus (Blog)
    • Traveling Europe (Blog)
    • Midnight in Paris (Blog)

    Featured In Blog

    • ISO27001, Machine-Learning and Game dev (Blog)
    • Sufficiently Complex (Blog)
    • Try Monad, Progress and Lockdown Rules (Blog)
    • Rails, Euclid and Generating Mazes (Blog)
    • Set Theory, Ruby and Upgrades (Blog)
    • Time shifting, CS algorithms and Game Architecture (Blog)
    • The Fourier transform, math, malware and decoupling (Blog)
    • Encryption and network protocols (Blog)
    • Mazer Game Design and Network Security (Blog)
    • Changing object states and 3D transformations (Blog)
  • Code

    Recent in Code

    • Applying and Evaluating Pattern-Oriented Designs In Improving Code Quality In Complex Software 01-10-2022
    • Polynomial Calculator 16-03-2022
    • A software engineering process for delivering software 27-02-2022
    • Counting and Permutations 08-02-2022
    • Encrypting strings at rest 10-12-2021
    • Implementing a Vignette 26-01-2021
    • Functional programming paradigms and techniques 19-07-2020
    • Ruby RSpec let and let! diffirences 08-07-2020
    • Convolution, Running and Finite State Machines 08-03-2020
    • LanguageExt tutorial, games and timing 08-08-2019

    Most Read In Code This Year

    • Thoughts on Multiplayer Game Co-operation and Distributed Computing (Game Development)
    • CppGameLib (Game Development)
    • Applying and Evaluating Pattern-Oriented Designs In Improving Code Quality In Complex Software (Code)
    • So far, it works (Game Development)
    • Functional XML (Game Development)

    Featured In Code

    • Functional XML (Game Development)
    • So far, it works (Game Development)
    • Thoughts on Multiplayer Game Co-operation and Distributed Computing (Game Development)
    • A software engineering process for delivering software (Code)
    • Encrypting strings at rest (Code)
    • Implementing a Vignette (Code)
    • Protocols, Packets and Prototypes (Game Development)
    • Animated aliens and alternatives algorithms (Game Development)
    • Retro sounds, Event Manager and some running (Game Development)
    • Basic key frame animations, implicit casts and some other aspect (Game Development)
  • Running

    Recent in Running

    • Christmas Run 26-12-2022
    • Knoydart Peninsula, Scotland 01-10-2022
    • Winter running 09-12-2021
    • Itchy legs and tracksuit bottoms 03-09-2021
    • Heart rate inconsistency 26-04-2021
    • Chequered Leaves and the Yellow Runner 01-01-2021
    • Fixing the thunder in my feet 04-12-2020
    • Faster than usual 17-06-2020
    • The uncomfortable steady-state 03-06-2020
    • Hot weather running 31-05-2020

    Most Read In Running This Year

    • Knoydart Peninsula, Scotland (Running)
    • Christmas Run (Running)

    Featured in Running

    • Smashrun
    • Strava profile
  • Gaming

    Recent in Gaming

    • Functional XML 19-02-2023
    • So far, it works 25-12-2022
    • CppGameLib 12-09-2022
    • Thoughts on Multiplayer Game Co-operation and Distributed Computing 04-07-2022
    • Applying and Evaluating Functional Programming Paradigms and Techniques in Developing Games 19-02-2022
    • Christmas Period Tinkering 29-12-2021
    • Mazer Game Architecture Report 22-11-2020
    • Ruby Mazer 26-05-2020
    • Protocols, Packets and Prototypes 29-11-2019
    • Pleasure And the Execution of Thoughfulness 29-09-2019

    Most Read In Gaming This Year

    • Thoughts on Multiplayer Game Co-operation and Distributed Computing (Game Development)
    • CppGameLib (Game Development)
    • So far, it works (Game Development)
    • Functional XML (Game Development)

    Featured in Gaming

    • Game loop
    • Featured
  • Portfolio

    Featured in Portfolio

    • App-V (Citrix)
    • Citrix Fast Connect SDK
    • AppDNA
    • Cloud Copy and Paste
    • Software Audit Pro
    • Investment Manager
    • Meal tracker
    • Cross platform broker
  • About

Implementing a Vignette

Details
Stuart Mathews
Code
26 January 2021
Created: 26 January 2021
Last Updated: 05 February 2021
Hits: 1982

I recently had a task to create a vignette of a picture. This is a technique in Computer Vision or digital signal processing whereby as you move closer and closer towards the centre of the image, the pixel intensity increases:  

When first approaching this problem, I could not understand how, from a dense matrix of colour information, you could determine how far the pixel that you were processing was from the centre of the image. I confirmed, that no position information is available within the pixel itself (it just contains raw colour information). Finally, it dawned on me that you could use the coordinates of the image matrix to create a vector to represent the centre point, ie. the offset x and y from an origin.

But where is the origin?

I first thought I'd have to use the centre of the image as the origin, meaning all my pixels co-ordinates would need to be relative to that, which would have been a pain as I'd have to work out how, say each pixel in the matrix[x][y] would probably need to be represented differently when relative to not matrix[0][0] but the centre of the image!

Then I realised that it could keep the origin as [0][0] in the matrix ie image[0,0] for both the centre point and each respective pixel and then it could thus be represented by a vector displacement from that same origin. This was a breakthrough for me. Not only that, you could then generate a new vector for each pixel this way - all using [0,0] in the image matrix to represent a distance of that pixel from the same origin. 

So, now you have two 2D vectors from the same origin, one that points at the centre of the image ie [max_cols/2, max_rows/2] and you have a vector that is [x,y] for each pixel you are currently processing. You can now subtract the vector representing the centre point from the pixel vector you are currently at, ie this would result in the vector between the two, which if you can calculate the magnitude thereof, will be the distance between the pixel you are on and the centre of the screen - ie its the hypotenuse between the two sides (of the two vectors). 

The length of the resulting vector can be easily by passing in the vector to np.linalg.norm() - ie get the norm of the vector ie the (length or magnitude) and this the distance. I guess you could