Skip to content

Commit f932268

Browse files
committed
All codes
1 parent ea07b03 commit f932268

File tree

112 files changed

+1973
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1973
-0
lines changed

Project 1/Problem1.pdf

20 KB
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
clc;clear;
2+
%% Write a computer program for computing the histogram of an image.
3+
fig1 = imread('data/Fig1.jpg');
4+
fig2 = imread('data/Fig2.jpg');
5+
figure('Name', 'Original Histogram');
6+
set(gcf, 'position', [0 0 1024 512]);
7+
subplot(1, 2, 1);
8+
[L1 D1] = myImhist(fig1);
9+
title('Fig 1');
10+
subplot(1, 2, 2);
11+
[L2 D2] = myImhist(fig2);
12+
title('Fig 2');
13+
14+
%% Implement the histogram equalization technique.
15+
figure('Name', 'Transformation of Fig. 1');
16+
set(gcf, 'position', [0 0 960 512]);
17+
subplot(1, 2, 1);
18+
imshow(fig1, []);
19+
R1 = myEqualization(L1, D1);
20+
for i = 1:size(fig1, 1)
21+
for j = 1:size(fig1, 2)
22+
fig1(i, j) = R1(fig1(i, j) + 1);
23+
end
24+
end
25+
subplot(1, 2, 2);
26+
imshow(fig1, []);
27+
28+
figure('Name', 'Transformation of Fig. 2');
29+
set(gcf, 'position', [0 0 1024 512]);
30+
subplot(1, 2, 1);
31+
imshow(fig2, []);
32+
R2 = myEqualization(L2, D2);
33+
for i = 1:size(fig2, 1)
34+
for j = 1:size(fig2, 2)
35+
fig2(i, j) = R2(fig2(i, j) + 1);
36+
end
37+
end
38+
subplot(1, 2, 2);
39+
imshow(fig2, []);
40+
41+
figure('Name', 'Transformation Function');
42+
subplot(1, 2, 1);
43+
plot(R1);
44+
subplot(1, 2, 2);
45+
plot(R2);
46+
47+
figure('Name', 'Equalized Histogram');
48+
set(gcf, 'position', [0 0 1024 512]);
49+
subplot(1, 2, 1);
50+
[L1 D1] = myImhist(fig1);
51+
%title('Fig 1');
52+
subplot(1, 2, 2);
53+
[L2 D2] = myImhist(fig2);
54+
%title('Fig 2');

Project 1/src/data/Fig1.jpg

47.9 KB
Loading

Project 1/src/data/Fig2.jpg

84.9 KB
Loading

Project 1/src/myEqualization.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function [ output_distribution ] = myEqualization( L, distribution )
2+
%MYEQUALIZATION equalizes the histogram
3+
% It returns a mapping that equalizes the original distribution
4+
5+
output_distribution = distribution;
6+
for i = 2:size(distribution);
7+
output_distribution(i) = output_distribution(i-1) + distribution(i);
8+
end
9+
output_distribution = output_distribution * (L - 1) / sum(distribution(:));
10+
11+
12+
end
13+

Project 1/src/myImhist.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function [ L, distribution ] = myImhist( fig )
2+
%MYIMHIST creates the histogram of a given image.
3+
% The function returns the number of pixels for each gray level,
4+
% and draws a figure automatically.
5+
L = 8;
6+
if L <= max(max(fig))
7+
L = 256;
8+
end
9+
distribution = zeros(L, 1);
10+
for i = 1:size(fig, 1)
11+
for j = 1:size(fig, 2)
12+
distribution(fig(i, j) + 1, 1) = distribution(fig(i, j) + 1, 1) + 1;
13+
end
14+
end
15+
% distribution = table(:, 2);
16+
distribution = distribution ./ size(fig, 1) ./ size(fig, 2)
17+
s = size(distribution);
18+
b = bar(distribution,'FaceColor', 'blue', 'EdgeColor', 'blue','LineWidth',0.6);
19+
set(gca,'XLim',[0 L]);
20+
set(gca,'XTick',[0:L/4:L]);
21+
set(gca,'XTickLabel',[0:L/4:L]);
22+
ylabel('Occurance');
23+
colormap(gray);
24+
c = colorbar('Location', 'southoutside', 'FontSize',10, 'Ticks', 0:64:256, 'TickLabels', {'0', '64', '128', '192', '256'});
25+
c.Label.String = 'Intensity';
26+
27+
28+
end
29+

Project 2/problem2.pdf

19.9 KB
Binary file not shown.
162 KB
Loading
169 KB
Loading
110 KB
Loading

0 commit comments

Comments
 (0)