Saturday Morning Mini Project: Coding for a video scope waveform in matlab

The task for today is to write code that’ll create a video scope of any given image.

Today I’m setting myself a little mini project to write a little bit of code in matlab to do something which I think should be pretty cool. Haven’t used matlab in a fair while and been pondering the best way to code this, so here we go…

The task for today is to write code that’ll create a video scope of any given image. A video scope or waveform monitor* is like a histogram’s older cooler brother, pretty similar in lots of ways, but more useful in many situations.

video scope image
video scope image created using matlab

A histogram (in imaging) takes all the pixel values in the image, arranges them in order and plots this on a graph, showing you how many pixels of each value there are in an image. This is useful for quickly assessing images, often on the back of a camera, for an objective measure of lightness/darkness within the image. Sometimes histograms are broken down to represent individual colour channels and these plots can be used for assessing colour balance.

However, histograms throw away all the spatial information within an image; you might be able to say ‘this image is predominantly dark’ but you couldn’t say where in the image it was dark. In the same way you could say that overall there was more reds in the highlights of an image, but it might require guesswork to say spatially where those bright reds were.

Video scopes in contrast retain some spatial information, and thus give you a greater understanding of the image. This added information does however make the plot more complicated to read, and this is probably the reason you don’t see them on the back of consumer cameras (or pro ones for that matter!).  

Video scopes generally retain the horizontal spatial information, meaning that it is much easier to work out which area of the plot corresponds to actual areas and objects in the original image. For this reason they can be used on a film/photography set to assess uniformity of lighting, both in terms of colour and intensity.

In post production they are particularly useful for the way in which they can be used to assess colour, they’re commonly used in the colour grading industry for exploring the relationships between coloured objects within an image, and can be used to study an image for signs of it’s post production history (e.g. Has it been jpeg compressed? Has it had a filter applied to it?).

Coding O’clock

OK onto the fun stuff. Like I said before, haven’t been in matlab for a few months so it took me quite a while to knock this code out. I’m not going to go too deep into every part of the code, if there’s any bits that you’d like to know more about leave a comment below or contact me. If you’d like to use it yourself, feel free to but please contact me first to ask for permission, I’m happy for it to get used but I’d be interested to see where it goes!

The bit that I will go into in slightly greater depth is the gooey bit about halfway through that does all the hard work, the ‘Populate Videoscope’ section. This took me a little while to get my head around, and as always when stuck in coding I chose to write out in english what exactly it was that I needed to do. For this section it was:

For every pixel in the original image, add the value of one to a pixel in the videoscope image, at a location that corresponds to the value and location of each pixel in the original image; the correspondence being that the x value is identical and that the y location is dependant on the original pixel value (0 at bottom and 255 at top).

 %Load Image
original_image=imread('mg2.tif');

%Measure image and create videoscope (vid)
[y,x,c]=size(original_image);
vid=zeros(256,x,3);

%Colour Channel Selection
for c=1:3  
    a=original_image(:,:,c);

%Populate Videoscope
    for j=1:x;
        for i=1:y 
            vid(256-(a(i,j)),j,c)=(vid(256-(a(i,j)),j,c))+1;
        end
    end

%Scaling
    maxvid=max(vid(:));
    vid_scaled=uint8(vid*(255/maxvid));
end

% Combine Orginal Image and Videoscope and display
b=original_image;
b(y+1:y+256,:,:)=vid_scaled;
imshow(b);

Video Scope Image Analysis

Now that we’ve written the code, let’s see how we can use the process to evaluate images!

cocktails and video scope
cocktails and video scope

There’s a couple of interesting bits in the above image, which should serve as an introduction to how to read a video scope and also show how useful and important they can be. If you’re new to video scopes it probably all looks like a mess of dots and lines at the moment, let’s check out a few different features.

Remember that at the bottom of the video scope is that black point and at the top the white point, with the left/right responding directly to the image above.

  • The feature that stands out strongest here is the green horizontal line in the bottom left of the image. It stands out because it is bright and of a single colour. It’s brightness refers to how many pixels there are that are the same in brightness in the original image, and it’s singular colour tells us that it is an object that is not the same brightness in all colour channels.
  • It’s low in the image, and this means it represents an area of that is dark in the green channel. This could either mean that it is dark and green, or that it is a different colour, which doesn’t contain much green. Above it we can see two similar width (through curving upwards and downwards) red and blue lines, so in this case we can tell that it’s a subject that is largely uniform, and composed primarily of blue and red… how about that purple bowl there!
  • Looking more widely at the image, we can see a general upwards trend towards the right, showing us that the image becomes brighter from left to right. Looking at the image itself I think we can agree on this.**
  • The final nice little feature here is the area of the video scope on the far left where red, green and blue lines converge as they travel steeply upwards into the image. As they converge they appear to wiggle up and down, representing the alternating pattern of the ridged souffle dish. Interesting to see that objectively, the the shadows on that dish are slightly redder than they are green, whereas the highlights are evenly spread.

Hopefully that’s provided some information on video scopes for the interested parties out there, comment below if you have any questions.

Danny Garside is a photographer and imaging scientist based in London, UK.

 

* Which I think are synonymous, call me up on it if I’m wrong cinephiles.

** This might seem a bit useless in this scenario, since we can easily see from the image itself that it gets lighter in this way, but imagine you were on a photo shoot and wanting a quick way to check you’d illuminated the background evenly? Visually, it’ll look all white, but using a video scope you’ll be able to see if there is any gradient at all and in which direction.

Author: Danny Garside

Colour and Imaging Scientist, based in London, UK.

Leave a Reply