Representation of an Image as a Matrix
Sampling and Quantization
Effect of Sampling Rate on Image Quality
Effect of Quantization on Image Quality
MRI Brain Scan (et01.jpg)
CT Scan of Spleen (sl00.gif)
The above two images are both 256x256 images, already in digital
format. Since we don't have a way to use the actual images and scan
them at different sampling rate, for now, we assume that the above two
images are the original images and we sample them instead. Thus,
we will try to store the images with different number of pixels
(meshes). Basically, we will trick ourselves.
Assuming the above images are the original images both of 256x256 in
size. If these images were sampled at 1/2 of the existing rate,
then we would have 1/2 of the 256 pixels on each row and 1/2 of the 256
pixels on each column. In a sense, if we wanted to keep the same
appearance, pixels would become twice as big on each dimension.
Does this give you a clue on how to reduce the sampling rate by
Well, one easy way to do this is to copy a pixel on the pixel next to and below it. This way the pixel appears twice as big, and we have removed (replaced) every other pixel in reality. This creates an image of the original image that is sampled at 1/2 sample rate.
If you wish to sample by 4, then you would copy the first pixel over its immediate three pixels, both on rows and columns. By the way, this process is called pixel replication. Following is the result of 1/4 sampling for et01.jpg image.
Suppose original matrix was:
f = [2 4 6 8
8 10 12 16
20 20 0 8
6 8 4 2]
This matrix sampled by 1/2 may look like this (4 is replaced by 2 so
as 8 and 10, and so forth):
f = [2 2 6 6
2 2 6 6
20 20 0 0
20 20 0 0]
As you may have noticed, we have represented the original f (image)
with 4 pixels. This matrix sampled by 1/4 may look like this:
f = [2 2 2 2
2 2 2 2
2 2 2 2
2 2 2 2]
Now the entire image is represented with one pixel only.
Use MATLAB to read the above two images then sample them by 1/2, 1/4, 1/8, 1/16, and 1/128 of the original image. This creates 5 images for each of the above images. Can you (subjectively) tell which one of these two images were most affected by the reduction in sample rate?
To represent an image in digital form, the intensity (amplitude) must be digitized too. In order to do this, we will break the intensity to some levels called gray levels (for a gray scale image). The quantization is commonly done based on the power of 2. Thus, we represent the gray scale as a number that is a power of two. A pixel in an 8 bit image ( 28 = 256 gray levels) may have 256 shades of gray, the value 255 for white and 0 for black. Any intensity value between these two is considered as gray.
To see the effect of quantization, once again we use the et01.jpg and sl00.gif images as the original images and we will quantized them at different quatization levels. Both of these two images have (28) = 256 shades of gray. If we quantize these images at a 1/2 of that intensity, then we would have (27) = 128 shades of gray, i.e., 0 for black and 127 for white. Thus, in that case 0-255 would map to 0-127. Did this give you a clue on how to quantize by 1/2?
To quantize the above image with 127 gray levels, we map every two
shades of gray to one. Thus, 254 and 255 will be mapped to 127, 252-253
will be mapped to 126, ..., 1 and 0 will be mapped to 0. Similarly, you
can quantize with 64, 32, 16, 8, ... levels.
Following is the et01.jpg image quantized at 1/4 of the original
Quantize the two original images by 1/2, 1/4, 1/8, 1/16, and 1/128 of the original gray level. This creates 5 images for each of the above images. Can you tell which one of these two images were most effected (subjectively) by the reduction in quantization levels?
At what quantization level do you start seeing inconstancies?
You will complete some exercises during the lab. Those are in-lab work. Create a file in MS Word and cut and paste the required commands and the resulting images in that file. Make sure to mark the activity number and have your name on that file. Once you are done with the in-class activities, e-mail me the file as an attachment. Please send only one file for the entire in-lab. Write in-lab in the subject line of your e-mail.
Similarly, you have to complete a post-lab and e-mail me the file as an attachment. Write post-lab on the subject line of that e-mail.
It is best that you create a lab3 directory on the machine you are using for your work. Try to use the same machine every time you come to the lab. Transfer your files (FTP) on cs so you have backup copies in case you need them.
Intensity Transformation Functions
The intensity transform functions, T, depends only on intensity values
and not explicitly on the spatial location (x,y). This type of
transformation functions can be written as:
where r denotes the
intensity of a pixel and s
the intensity of the output image, both at any corresponding point (x,y) in the image.
In MATLAB a function imadjust is
the basic IPT tool for intensity transformations of gray scale
images. It has the syntax:
|gamma values (fill out to match your
closer to the min intensity became smaller
||Values closer to the max intensity became larger||Overall
image become brighter
image became darker
Post-Lab - Due Wednesday September 27
Include all our MATLAB files in your submission and the images you have created in your MS Word file.
Question (1) - Use the imadjust MATLAB command to solve the Exercise 2.3 problem above. Please include the images and use the whos command to create a table for the size of the images (in bytes or bits) after each stage.
Question (2) - Use either the nearest neighbor interpolation or pixel replication (whichever you find most suitable or easier to use), the concepts introduced in this lab, and the material in Chapter (3) and Chapter (4) of the textbook to:
a) Shrink the above images by 2
b) Shrink the above image by 4
c) Zoom in (enlarge) by 2
d) Zoom in by 4
Question (3) - Implement
the Bit-Plane Slicing for Image (1), which is an 8-bit image.
Thus, first use the procedure I have given in the Quiz (4) and in the
worksheet to create 8 images for each of the Bit Planes. Note
that I haven's ask for reconstruction.
Question (4) - Reconstruct the image using 4th Bit-Plane
Question (5) - Reconstruct
using 7th Bit Plane