Implement (i) filtering/denoising with a mask, (ii) a
thresholding algorithm using the following logic:
**A good threshold value is at a value where the number connected
regions in an image do not change as much.**
Thus your thresholding algorithm steps are:
1. For each candidate threshold value (from 0 to 255), calculate
the number of connected regions in your binary image (use MATLAB's
builtin code for number of connect regions)
2. Based on these values of number of connected regions, pick an
optimum T value.
For testing:
1. Take the photograph of a text image (black text on white
background).
2. Add artificial noise to this image with varying noise level 1.
salt and pepper noise, 2. Gaussian noise
3. Denoise this image using smoothing filters, sharpening filters,
median filters (write your own code for filtering)
4. Test a bunch of these combinations and see observe the effect on
the quality of thresholding.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all,
clear all,
clc,
ProjectPath = pwd;
TextImage = strcat(ProjectPath,'\TextImage.jpg');
Orig = imread(TextImage);
Gray = rgb2gray(Orig);
Thresh = graythresh(Gray);
BW = im2bw(Gray,Thresh);
subplot(3,3,1); imshow(BW);
[L,NUM] = bwlabeln(~BW,8);
disp(['No. of Connected Regions in Original Image = ', num2str(NUM)]);
Salt_n_pepper_NoiseImg = imnoise(Gray,'salt &
pepper',0.01);
subplot(3,3,4); imshow(Salt_n_pepper_NoiseImg);
title('Salt-n-Pepper Noise Image');
K = medfilt2(Salt_n_pepper_NoiseImg);
subplot(3,3,5); imshow(K); title('Filtered Image');
Thresh = graythresh(K);
BW = im2bw(K,Thresh);
subplot(3,3,6); imshow(BW); title('Filtered Image after
Thresholding');
[L,NUM] = bwlabeln(~BW,8);
disp(['No. of Connected Regions in Noisy Image after Thresholding =
', num2str(NUM)]);
mean=0.01; variance = 0.02;
Gaussian_NoiseImg = imnoise(Gray,'gaussian',mean,variance);
subplot(3,3,7); imshow(Gaussian_NoiseImg); title('Gaussian Noise
Image');
K = medfilt2(Gaussian_NoiseImg);
subplot(3,3,8); imshow(K); title('Filtered Image');
Thresh = graythresh(K);
BW = im2bw(K,Thresh);
subplot(3,3,9); imshow(BW); title('Filtered Image after
Thresholding');
[L,NUM] = bwlabeln(~BW,8);
disp(['No. of Connected Regions in Noisy Image after Thresholding =
', num2str(NUM)]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Matlab Output:
No. of Connected Regions in Original Image = 22
No. of Connected Regions in Salt-n-pepper Noisy Image after
Thresholding = 22
No. of Connected Regions in Gaussian Noisy Image after Thresholding
= 22
>>
Implement (i) filtering/denoising with a mask, (ii) a thresholding algorithm using the following logic: **A good thresh...