Practical Exercise 2: Image Colours Learning Outcomes Upon successful completion of this practical task you will be able to: • Apply a problem-solving methodology to create a computer solution that changes the colours in an RGB colour image. Become familiar with the structure and flow of conditional and iterative statements in MATLAB. Introduction to the practical Background of colour replacement: In photography and video applications colour replacement is a useful tool. In photography this technique could be used to change a colour in a photograph to another colour, for example changing the colour of a red chocolate wrapper to blue (below). In video applications similar techniques are used to replace a block of colour in a video stream (such as green or blue) to a completely different background or image, this is called chroma- keying or 'green-screening and is how the weather is often performed on the news; the weather presenter is usually standing in front of a green-screen and the green is replaced with a weather map, which is what you see on your television.
The RGB colour-space: To understand how this is possible we need to understand how colour is represented on a computer (and in MATLAB). The most common way colour is represented is using what's known as the RGB colour-space (R = red, G = green, B = blue). When looking at an image on a computer screen it will be made up of rectangular light elements called pixels (a portmanteau of 'picture elements), the colour of these pixels will be determined by the ratios of red, green and blue light being emitted by the screen. For example, a pure red pixel would be emitting red light only (red turned on), while the green and blue light would be turned off. Cyan (greeny-blue) would have red light turned off with roughly equal parts green and blue light being emitted. Below are the primary and secondary light colours and their RGB values; 255 represents 100% on, 0 represents completely off. Green Yellow White Black R=0 R=255 R=255 R = 0 G-255 G = 255 G - 255 o=0 BO B=0 B-0 B-255 Cyan R-O G=255 B-255 Red R - 255 G - 0 B=0 Blue R = 0 Magenta oo R = 255 B - 255 G-0 B = 255 Figure 1: Primary and secondary colour wheel and RGB values.
On top of this you also have shades, pixels are not just binary 'on' or 'off' elements but can be dimmed or brightened to emit more or less light to create many different colours and shades, this is shown below for pure red pixels. Figure 2: Pure red pixels. R value is increasing from 0 - 255 from left to right, Gand B values are set to zero throughout Part 1: Designing a colour change program For this prac you'll be designing a program that: a. Prompts a user to specify a colour they want to change in an image, b. Iterates through the image and changes all pixels of that colour to black, and c. Displays the resultant image in a new figure window. The image you will be using is shown in figure 3 and is an image of plastic chips called coloredChips.png. This image is an in-built image in MATLAB available through the Image Processing Toolbox Figure 3: 'colored Chips.png' image.
Task 4 - Write, run and test your algorithm in MATLAB Exercise: Now, in a new MATLAB script file write a program that will: - Ask your user what colour they want changed. A text menu type system may help you with this. - Iterates through the image to find all the appropriately coloured pixels and changes them to black. - Displays the resultant image to the user. Points to be addressed: - Compare the output image to what you would expect to get from your handworked algorithm in task 3. If this is not the case, troubleshoot your algorithm/script to find where the mistake is.
Practical Exercise 2: Image Colours Learning Outcomes Upon successful completion of this practical task you will be able
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Practical Exercise 2: Image Colours Learning Outcomes Upon successful completion of this practical task you will be able
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!