DIP Lab Task 10

docx

School

COMSATS Institute of Information Technology, Islamabad *

*We aren’t endorsed by this school

Course

502

Subject

Electrical Engineering

Date

Nov 24, 2024

Type

docx

Pages

5

Uploaded by AdmiralParrot373

Report
Digital Image Processing Lab Task 10 Submitted To : Mam Sobia Yousaf Submitted By : Roll No : Class : Date : Department of Software Engineering Lab Task 10: Task: 01 Take the images “noisy1.png” and “noisy2.png” from the attachment. In MATLAB, load the image using the MATLAB command imread. Subsequently, filter each of the images using the Gaussian and the Median filters. The MATLAB functions fspecial, padarray, conv2 and medfilt2 can be useful. For the Gaussian filter, try using different values for the standard deviation of the kernel. Find the standard deviation which gives the minimum mean squared error (the original image required to calculate the mean squared error can be taken from the attachment). Remember to change the size of the filter according to the standard deviation of the kernel. Similarly, try different size of the median filter to get the minimum mean squared error. Display the resulting images and compute the mean squared error for the best scenario in each case. Code :
% Reading Images I1 = imread( 'noisy01.png' ); I2 = imread( 'noisy02.png' ); % Gaussian Filter Gaussian_Filter = fspecial( 'gaussian' , 3, 0.8); % Applying Gaussian Filter to Images Output01 = imfilter(I1,Gaussian_Filter); Output02 = imfilter(I2,Gaussian_Filter); % Applying Median Filter to Images Output03 = medfilt2(I1); Output04 = medfilt2(I2); subplot(3, 2, 1); imshow(I1); title( 'Original Image (noisy01.png)' ); subplot(3, 2, 2); imshow(I2); title( 'Original Image (noisy02.png)' ); subplot(3, 2, 3); imshow(Output01); title( 'Gaussian Filtered Image (noisy01.png)' ); subplot(3, 2, 4); imshow(Output02); title( 'Gaussian Filtered Image (noisy02.png)' ); subplot(3, 2, 5); imshow(Output03); title( 'Median Filtered Image (noisy01.png)' ); subplot(3, 2, 6); imshow(Output04); title( 'Median Filtered Image (noisy02.png)' ); Output :
Task: 02 Write a program to threshold the images flower.pgm using Otsu’s method and adaptive threshold. Compare the result of your own program with built-in method. Show the resulting binary images. Code : I = imread( 'flower.pgm' ); % Adaptive Thresholding Manual mean_image = imfilter(I, fspecial( 'average' ,[15,15]), 'replica' );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
subtract = I - (mean_image+15); black_white = im2bw(subtract,0); % Adaptive Thresholding Using Built-In Function T = adaptthresh(I,0.3); BW01 = imbinarize(I,T); % Otsu's Thresholding [counts,x] = imhist(I,16); OT = otsuthresh(counts); BW02 = imbinarize(I,OT); subplot(2, 2, 1); imshow(I); title( 'Original Image' ); subplot(2, 2, 2); imshow(black_white); title( 'Adaptive Threshold Image' ); subplot(2, 2, 3); imshow(BW01); title( 'Adaptive Threshold Image Using Built-In Function' ); subplot(2, 2, 4); imshow(BW02); title( 'Otsu Threshold Image' ); Output :