|
|
COMP2720 – Lab 2
– Week 4 (8th and 15th August 2008)
Advanced picture manipulation
IMPORTANT
You must read relevant slides of
continuous colour interpolation in the Lecture 4,
otherwise you will waste
your time when doing part 2 of the lab!
You must read sections 4.5 and 4.6 (four pages only!)
in the text book to be able to do
Further programming ideas, Ex. 3,
of the lab.
Objectives
The objectives of this lab are to become more familiar with JES,
to understand and modify more complex programs (which can include
if, nested loops, functions, etc.), and to do more
complicated image manipulations (like copying and resizing pictures,
blurring and edge detection). This lab is an important preparation
for assignment 1!
Marks and submission
- You will get one mark if you attend this lab, and another mark
when you show and demonstrate your working to your tutor.
- The mark for your lab workings will only be awarded in the lab. You
can show your workings in this lab as well as the following lab
3 in week 7. You will not receive a mark for this lab if you
show it to your tutor after the lab in week 7, unless you have a
medical certificate (or similar document) stating that you were
unable to attend the normal lab.
- Please do NOT e-mail your lab workings to your tutor — we will
NOT mark e-mailed lab workings. You can only get the mark for
workings in the labs.
Preliminaries
- Once logged onto a computer, create a sub-folder called
lab2 in your folder comp2720.
- Download the lab-template.txt
and save it in your lab2 folder under the name
lab-2-diary.txt.
Please only save your lab diary as simple text file, not in RTF
or DOC format (as you will have to include your lab diaries into
your portfolio, and we will not be looking at RTF or DOC files
when assessing your
portfolio).
- Open this file lab-2-diary.txt with a text editor, and
complete the header with your details. Keep this file open and
continue writing down your workings and paste your programs
into it.
- Now copy the following files into your lab2 folder:
Part 1: Picture scaling and copying
You should spend around 50 minutes on this part of the lab.
- Start JES, and load the program halfAndCopy.py. Run the program,
and select your lab2 folder as the media folder.
- See what happens when you run the program, then read it and try to
understand how the program works. Ask your tutor if you have
difficulties with understanding it. Describe the program in your lab
diary (for example by adding comments to it - to every line of the
program).
- Is it a good idea to have the function setMediaPath() within
the function halfAndCopy()? Describe in your lab diary why or
why not.
- First you should modify this program so that the original picture is
copied twice into the new picture, both copies half the size (in each
dimension), and next to each other. Save your program as
halfAndDouble.py. Once it works correctly copy the program
into your lab diary and describe how it works.
- Next you should modify the original halfAndCopy.py program so
that it scales the original picture by a factor of four (i.e. four
times smaller in each dimension). Save the modified program under
the name quarterAndCopy.py. Once the program is producing the
correct results, save it into your lab diary, describe how it works,
and also describe how the resulting picture looks like (are you happy
with the quality of the new picture - or does it look strange?).
Is there anything in this program that could be improved (describe
in your lab diary)?
- The last program in this part aims to half the original picture and
copy it into the centre of an empty 400x400 picture.
Modify the original halfAndCopy.py program accordingly, and
save the new program as halfAndCentre.py.
- What happens if you apply the halfAndCentre.py program twice
on the same picture? You might have to modify the program a little bit
so it takes a picture as input, applies the half-and-centre manipulation,
and then returns the modified picture.
(Hint: This will be useful for assignment 1).
- Finally, add the JES function writePictureTo(picture,
pathAndFilename) to your halfAndCentre.py program, so that
the centred picture is saved into a JPEG file.
Part 2: Making simple "slide" transitions
You should spend around 40 minutes on this part of the lab.
Choose a colour image, not too large (around 300 by 300 pixels)
Use the Python function greyScale.py or the function
greyScaleNew.py to convert
the original colour image into black-and-white.
Now, modify
the GreyScale.py (or, if you have chosen,
GreyScaleNew.py) so instead of changing the
original picture object, your "greying" function returns the
new grey picture object (the original and the returned images must be
of the same size). Write a simple program which will load
an image file, display the original colour picture, and then
redisplay the grey version of it.
The next step is to modify the GreyScale.py
(GreyScaleNew.py) further by introducing a second
function parameter, a non-integer number between 0 and 1,
which can be regarded as "grey fraction". So, when called
greyScale(picture, frac), the function will return
a colour-modified version of the original picture,
which is a continuous interpolation between the full colour
(frac = 0) and complete black-and-white
(frac = 1) versions of the same image. It is
important, that the luminosity of every pixel, for any value of
frac, was always kept the same as it was in the
original picture, just as it is done in the
original functions GreyScale.py
(GreyScaleNew.py).
Now write a function which will run a loop over the value of
the parameter frac.
Redisplay the modified at the end
of every step to create an effect of the continuous colour erasure.
This is your first transition effect! (added later:
This time do not multilpy return the modified image, instead create a single
copy at the beginning, before the loop, and repaint it
at the end of every colour erasure step; this way all modification will take
place in the same frame.)
Consider a similar exercise of gradually converting a genuine
black-and-white image into a Sepia-tinted version,
imitating the "aging of a photograph" effect. As a starting point
you may use sepiaTint.py
Python program.
Part 3: Show your workings to your tutor
You should spend around 10 minutes on this part of the lab.
- Explain and show to your tutor what you have done in parts 1 and 2
of the lab, the resulting pictures created, and the programs you
have developed.
- Please also show your tutor your lab diary.
|
In each lab we will provide a last section that contains ideas
for people who want to dig deeper, who are hooked on
Python or media programming. This section is not part
of the assessable lab material, but rather provides some more
problems for students who love a programming 'challenge'.
|
- For part 1 of this lab, write a program that creates a sequence of
new pictures, each time halving and copying the original picture,
as done in step 4 of part 1 in the program halfAndDouble.py.
Can you repeat this process until the size of the original picture
becomes 1 x 1?
- Also for part 1 of this lab, with more and more down-scaling
(reducing the size) the number of pixels copied into the new smaller
picture becomes less and less. This down-scaling of the original
picture obviously affects the quality of the smaller picture.
Can you think of (and implement) a way of keeping colour information
for all pixels when down-scaling? Discuss this issue with your tutor.
-
Blurring and edge detection (previously used as the main
exercise)
- Load the program blur.py into the JES editor (it's the
program from the text book, page 107). Run the program and try
to understand it. Apply the blurring to several pictures, and
see how the effect looks like.
- Now you should create two modifications of blur.py. Have a
look at the diagram below. The original blur works by combining
the colour values from five pixels (in a cross form). You should
modify blur.py according to the middle and right part of
the diagram (and save the resulting programs as blurSquare.py
and blurLargeCross.py). Hint: You might also have to change
the starting and ending index values within the loops!
- Run the three versions of blur on the same picture, and compare the
results. Which one gives you the best results? Examine the
different blurred pictures in the JES MediaTools (use maximum zoom).
Try to explain why.
- Add the command to save (write) a picture into a file to your
favourite blur program, and save one or more of your blurred pictures.
You will need them for your
portfolio.
- Now open the linedetect.py program into the JES editor, run it
and try to understand it (maybe add more comments to it describing
what each block of code is doing).
- Change the threshold values (currently 2 for both down and right
direction). What happens if you increase them? What happens if you set
them to different values? What happens if you set one of them to zero?
Play around with this and describe your findings in your lab diary. What
happens if you change the down and right direction to
upper and/or left? What happens if you only consider one
direction (for example, only down, but not right?)
- Once you have found threshold values you find appropriate, add the
command to save a picture into a file, and save one or more of your
edge detected pictures (as well as the original ones you used as
input). You will need them for your
portfolio.
- Think about how to modify your blurring
programs so that pixels closer to the centre pixel are
weighted more in the blurring calculation than pixels further
away from the centre pixel. Will that improve the blurring, or not?
- Also for the blurring part, can you come up with a blurring program
that has an input variable radius, and then calculates the
necessary pixels that are need for blurring? For example, the larger
the blurring radius the more pixels will be involved in the blurring
calculation.
Last modified: 23/08/2008, 00:42
|