CS519 Assignment 4: Image Processing and Compression, Assignments of Computer Science

A programming assignment for a signal and image processing course (cs519). Students are required to write functions for median filtering, hsv color conversion, and image compression using predictive encoding and huffman coding. They must also provide write-ups detailing their implementation and learning outcomes. The assignment includes tasks such as filtering an image to remove speckles, rotating the hue of an image using a mask, and compressing grayscale images.

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-ocq
koofers-user-ocq 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS519 — Signal and Image Processing
Program #4
Due date: Monday, June 2, 2003
A) Write a function that computes the median filter for an n×n neighborhood (where n is a parameter to
the function). Apply the median filter to the image
/usr/local/classes/cs/cs519/images/blemish_crop.pgm
Use the smallest filter size that removes the speckles and display the resulting median-filtered image.
Also, use the image
/usr/local/classes/cs/cs519/images/blemish_mask.pgm
as a mask to create a third image that is a combination of the original image (where the mask is zero)
and the median-filtered image (where the mask is non-zero). Display all three images side-by-side.
(15 pts).
B) Write a function that converts a color RGB triplet to the HSV color space. Given an (r,g,b) color
triplet where each component is in the range 0 to 1 and if cmax =max(r,g,b), cmin = min(r,g,b), and
=cmax -cmin then the conversion to an (h, s, v) color triplet is defined as
if > 0 and h=s=0 if = 0 (while v=cmax still). (Note: technically, h is undefined if = 0 but
often it is represented as 0 when the color has no chromaticity—i.e., when it is a shade of gray). When
the conversion is complete, the values of h, s, and v should range between 0-2π, 0-1, and 0-1, respec-
tively. (For processing purposes, you may want to scale these values to some other range). Also, write
the inverse conversion (from HSV to RGB). However, it is left up to you to figure out how to imple-
ment the conversion from HSV to RGB. (Hint, if you get stuck, try the internet for ideas—but do not
copy code).
Once you have the conversion routines, load the following two images:
/usr/local/classes/cs/cs519/images/bird_left.ppm
/usr/local/classes/cs/cs519/images/bird_mask.ppm
and rotate the hue of the bird by using the mask image to determine which pixels in the original (bird)
image to are to be affected. You are to extract the bird’s pixels, convert them to HSV, rotate the hue by
a certain amount (to be determined interactively by the user), convert the hue-shifted pixels back to
RGB, and then recombine them with the original (again using the mask image to determine how to
h
π
3
---
gb
------------ if rg> and r
b
>
2br
----------- if gr> and g
b
>+
4rg
----------- otherwise+
=
s
cmax
----------
=
v
cmax
=
pf2

Partial preview of the text

Download CS519 Assignment 4: Image Processing and Compression and more Assignments Computer Science in PDF only on Docsity!

CS519 — Signal and Image Processing

Program # Due date: Monday, June 2, 2003

A) Write a function that computes the median filter for an n × n neighborhood (where n is a parameter to the function). Apply the median filter to the image /usr/local/classes/cs/cs519/images/blemish_crop.pgm

Use the smallest filter size that removes the speckles and display the resulting median-filtered image. Also, use the image /usr/local/classes/cs/cs519/images/blemish_mask.pgm

as a mask to create a third image that is a combination of the original image (where the mask is zero) and the median-filtered image (where the mask is non-zero). Display all three images side-by-side. (15 pts).

B) Write a function that converts a color RGB triplet to the HSV color space. Given an ( r , g , b ) color triplet where each component is in the range 0 to 1 and if cmax = max( r , g , b ), cmin = min( r , g , b ), and ∆ = c (^) max - c (^) min then the conversion to an ( h , s , v ) color triplet is defined as

if ∆ > 0 and h = s = 0 if ∆ = 0 (while v = cmax still). (Note: technically, h is undefined if ∆ = 0 but often it is represented as 0 when the color has no chromaticity—i.e., when it is a shade of gray). When the conversion is complete, the values of h , s , and v should range between 0-2π, 0-1, and 0-1, respec- tively. (For processing purposes, you may want to scale these values to some other range). Also, write the inverse conversion (from HSV to RGB). However, it is left up to you to figure out how to imple- ment the conversion from HSV to RGB. (Hint, if you get stuck, try the internet for ideas—but do not copy code).

Once you have the conversion routines, load the following two images: /usr/local/classes/cs/cs519/images/bird_left.ppm /usr/local/classes/cs/cs519/images/bird_mask.ppm

and rotate the hue of the bird by using the mask image to determine which pixels in the original (bird) image to are to be affected. You are to extract the bird’s pixels, convert them to HSV, rotate the hue by a certain amount (to be determined interactively by the user), convert the hue-shifted pixels back to RGB, and then recombine them with the original (again using the mask image to determine how to

h π 3

gb

------------ (^) if r > g and r > b

br

+^ -----------^ if g > r and g > b

rg ∆ +^ -----------^ otherwise 

s

c (^) max

=^ ----------

v = c (^) max

recombine). Note that the mask image is not a binary on-off image but represents the alpha value at each pixel that determines how much of the changed pixel colors to use when replac- ing pixels (20 pts).

C) Write a image compression routine that uses predictive encoding routine to compress a gray- scale image using the 4 neighboring pixels that it has already seen (as discussed in the class notes on compression). Assume that the image is padded with 0. The difference between the predicted value and the actual value is to be encoded using Huffman coding by sending the signed 16-bit difference image to the constructor (or to the encode function) of the Huffman class that is provided for you in the prog4 directory.

The compression routine should also take, as a parameter, a number n that indicates the num- ber of gray-levels that the image is to be quantized to prior to compression. Given a gray-level g , the new gray-level g should be

For example, if n = 255, then no further quantization occurs, however, if n = 3, then the pixel gray-levels will be rounded to the nearest of the following values: 42, 127, and 212 (with 0- being rounded to 42, 85-169 rounded to 127, and 170-255 rounded to 212, thus dividing the grayscale range so as to reduce the quantization error). Allow the compression algorithm to be applied to any grayscale (pgm) image by specifying the image file name on the command line. Also, n (the number of quantization levels) is to be optionally specified on the command line after the image file name where n defaults to 255 if it is not specified on the command line.

Finally, write the decompression routine that restores the original image from the compressed result and displays the decompressed result. (You will need to call the decode function in the Huffman class). Compute and output/display/print the compression ratio. (Note: you do not need to save the compressed image to disk) (25 pts).

Write-up: Submit a write-up describing how you implemented this programming assignment and what you learned. What happens to the speckles in the blemish image? What advantage does the masked median-filtered image have over the unmasked one? What happens if a larger- than-necessary filter size is used? How convincing is the color of the hue-shifted bird? How are the black and white portions of the bird affected? What about the shaded color portions, is the shading maintained? Apply the compression algorithm to the following two images: /usr/local/classes/cs/cs519/images/peppers.ppm /usr/local/classes/cs/cs519/images/garmisch.ppm

What are the resulting compression ratios? Why would some images compress better than others? As with the previous assignments, the write-up is to be turned in online as a separate submission (20 pts).

gg n

gmax 2 n