Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Lab 1 – INT 302: Image Processing

Start Date: 2026-03-24
Deadline: 2026-04-02 (11:59pm)
15% of the final marks
AI is forbidden.

Late Submission Policy: 5% of the total marks available for the assessment shall be deducted from the assessment mark for each working day after the submission date, up to a maximum of five working days.

Learning Outcomes

Students completing the module should be able to:

A. Critically evaluate and discuss the basic principles of digital image processing, including key concepts such as image resolution, and quantization, histogram.

B. Compare various techniques used in digital image processing and assess their strengths and weaknesses.

C. Analyze the application areas of different image processing techniques, such as image enhancement, image transformation, image compression, and morphological operations.

Objectives:
1- Introducing the image processing capabilities of Matlab and its Image Processing Toolbox.
2- Learn to read and display different images.
3- Learn basic image processing steps.
4- Master different image enhancement techniques
Download:

Download the files of lab1-Material.zip from the Learning Mall, unzip the file into a folder lab1- Material, which contains “cameraman.tif”, and “lenna512.bmp”.

Tasks:

1. Task1 (15’)

Given any grayscale image “cameraman.tif,” complete pixel neighborhood analysis and implement a simple neighborhood-based image operation, with in-depth theoretical explanation and result visualization.

(a) Read the grayscale image cameraman.tif, convert it to double-precision format (to avoid integer overflow), obtain the image size (rows and columns), and randomly select
(3’):
(1) non-boundary pixel p(x,y) (ensure 2≤x≤rows−1 and 2≤y≤cols−1)
(2) A corner pixel r(x2,y2) (e.g., top-left corner, bottom-right corner)
(3) An edge (non-corner) boundary pixel q(x1,y1) (e.g., middle of the first row)

Output the coordinates and grayscale values of the three pixels in the command window.

You can use im2double(I) to convert grayscale images to double-precision format (range [0,1])

(b) Define the function getNeighbors(I, x, y, method), where: Inputs: grayscale image I, target pixel coordinates (x,y), method (optional parameter, default='nan', alternative='replicate'). Outputs: 4-neighborhood (coordinate/grayscale matrix), 8- neighborhood (coordinate/grayscale matrix) of the target pixel (3’)

Function logic: When method='nan', mark missing neighborhood pixels as NaN; when method='replicate', use the target pixel's grayscale value to fill missing neighborhood pixels (replication padding).

Replication padding logic: For a boundary pixel (1,1), its upper/left neighborhood pixels are filled with the value of (1,1)

(c) Use the above function (both nan and replicate methods) to solve the 4- neighborhood and 8-neighborhood of pixels p, q, and r respectively: (2’)

Output the neighborhood coordinates and grayscale values in the MATLAB command window

Visualize results: Display the original image and three subplots (marked with p, q, r and ,their neighborhoods). Mark rules: target pixel (red circle), 4-neighborhood (green ,square), diagonal neighborhood in 8-neighborhood (blue triangle). Add legends, titles, and coordinate labels for each subplot. 

(d) Based on the 8-neighborhood function, implement a simple 3×3 neighborhood average filtering function ‘neighborhoodAverageFilter(I)’: (1’)

Traverse each pixel in the image, replace the pixel's grayscale value with the average of its 8-neighborhood pixels (use replicate method for boundary pixels)

Display the original image and filtered image side by side, and calculate the mean square error (MSE) between the two images to quantify the filtering effect.

(e) Compare and analyze the experimental results in detail:

(1) Analyze the differences in neighborhood pixel quantity and grayscale value distribution among non-boundary pixel p, edge boundary pixel q, and corner pixel r under both nan and replicate methods and explain the advantages and disadvantages of the two padding methods. (3’)

(2) Combined with the results of neighborhood average filtering, explain how pixel neighborhood relationships support local image operations (e.g., filtering). Taking edge detection as another example, describe the role of 4-neighborhood/8- neighborhood in gradient calculation for edge detection. (3’)

2. Task2 (5’)
Write a function to measure the Peak Signal to Noise Ratio (PSNR) between two gray images in dB. For the peak value use 255.
The PSNR is giv

Where mse is the mean square error, and it is evaluated as:
3. Task 3 (30’)
In this task, we use the monochrome image Lenna (i.e., lenna512.bmp ) to do the following sub tasks, and let’s call the original image Lenna as I0.
(a) I0-> down-sampling to I1with 1/4 size of I0 (both horizontally and vertically) using nearest neighbor interpolation (implement it by yourself). Explain your implementation. You need to show clearly how do you design the programming for nearest neighbor interpolation. Display it and compare to the original image. Explain your founding in the report; (10’)
(b) I1-> up-sampling to I1’ with the same size of I0 using bilinear interpolation (implement it by yourself). Explain your implementation. You need to show clearly how do you design the programming for bilinear interpolation. Display it and compare to the original image. Explain your founding in the report. (10’)
(c) Calculate the PSNR between the original image I0 and the up-sampled images, i.e., nearest, bilinear, and bicubic, respectively. Compare the results of different interpolation methods. Explain your founding in the report. (10’) (Note: for bicubic interpolation, you can use the matlab function directly).

Image
nearest
bilinear
bicubic
PSNR (dB)



4. Task 4 (50’)

In this task, we use the monochrome image Lenna (i.e., lenna512.bmp ) to do the following sub tasks, and let’s call this reference image Lenna as im.

a) Add Gaussian white noise with zero mean and variance 25 to the image im and display the noisy image. Name it as im_wn. Please write one function to generate this image instead of calling matlab function directly (you can use Matlab function to generate Gaussian random numbers, e.g., randn()). (8’)

b) Add salt & pepper noise with noise density 15% to the image im and display the noisy image. Name it as im_SP. Please write one function to generate this image instead of calling matlab function directly (you can use Matlab function to generate uniform random numbers, e.g., rand()). (8’)

c) Add one new noise image by combination of both Gaussian noise and salt &pepper noise. Firstly, you randomly select 15% positions of the original image to change thepixel value, Second, you randomly  set a Gaussian value for this selected position. The Gaussian distribution is the same as the task (a), i.e., zero mean and variance 25. Please write one function to generate this image. (8’)

d) Apply the median filter with a 3X3 window and a 5X5 window on the image im_SP (you can use Matlab function medfilt2). Display and evaluate the PSNR of the obtained images. For each window size, comment on how effectively the noise is reduced while sharp edges and features in the image are preserved. (8’)

e) Implement the mean filter 3X3 to filter the image im_SP by yourself (you are not allowed to use Imfilter and fspecial directly). Compute the PSNR and display the filtered image. You can use zero padding for the boundary pixels. (8’)

f) As you experimented with the mean and median algorithms, what different “performance” did you notice? Which one is better for removing salt & pepper noise? and why? (10’)

Lab Report

Write a short report which should contain a concise description of your results and observations. Include listings of the Matlab scripts that you have written. Describe each of the images that you were asked to display.

Answer each question completely:

– Do not attach the code at the end of the report, just put the useful code under each question
– The results maybe contain some figures, please add some index and title of each figure
Report format: Single column; Fond size: #12; Page number: no more than 15;

Submission before 2026-04-02 11:59pm.

– Electrical version to LM with a ZIP of all files
• Rar file name: INT302-Lab1-Name-studentID. zip
• One file with same file name of zip File: Report ( with studentID, name, Lab title on the homepage)
• One folder: codes and other materials. (I can run it directly)
Marking scheme

80%-100% Essentially complete and correct work.

60%-79% Shows understanding, but contains a small number of errors or gaps.

40%-59% Clear evidence of a serious attempt at the work, showing some understanding, but with important gaps.

20%-39% Scrappy work, bare evidence of understanding or significant work omitted.

<20% No understanding or little real attempt made.