-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram1.m
57 lines (44 loc) · 1.33 KB
/
program1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
% Clear the command window, workspace, and close all figures
clc;
clear all;
close all;
% Load an image (replace '.png' with the actual image file path and name)
img = imread('night.png');
I = rgb2gray(img);
% Display the original image
subplot(2, 3, 1);
imshow(img);
title('Original Image');
% Create a disk-shaped structuring element with a radius of 15 pixels
se = strel('disk', 5);
% Perform erosion on the original image
er = imerode(I, se);
% Display the result after erosion
subplot(2, 3, 2);
imshow(er);
title('Image after Erosion');
% Perform dilation on the eroded image
d1 = imdilate(I, se);
dl = imdilate(er, se);
% Display the result after dilation
subplot(2, 3, 3);
imshow(d1);
title('Image after Dilation');
% Calculate the top-hat transform by subtracting the dilated image from the original
eg = I - dl;
% Display the result after the top-hat transform
subplot(2, 3, 4);
imshow(eg);
title('Image after Top-Hat Transform');
% Convert the original image to a binary image
binaryI = imbinarize(I);
% Display the binary image
subplot(2, 3, 5);
imshow(binaryI);
title('Binary Image from Original Image');
% Convert the top-hat transformed image to a binary image
binaryEg = imbinarize(eg);
% Display the binary image from the top-hat transformed image
subplot(2, 3, 6);
imshow(binaryEg);
title('Binary Image from Top-Hat Transformed Image');