-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
574 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function res = bhp(F, d0, order) | ||
|
||
[m, n] = size(F); | ||
|
||
d = zeros(m, n); | ||
H = zeros(m, n); | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
d(i,j) = sqrt( (i-(m/2))^2 + (j-(n/2))^2); | ||
end | ||
end | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
H(i,j) = 1 / (1+ (d0/d(i,j))^(2*order) ) ; | ||
end | ||
end | ||
|
||
|
||
for i = 1:m | ||
for j = 1:n | ||
res(i,j) = (H(i,j)) * F(i,j); | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function res = blp(F, d0, order) | ||
|
||
[m, n] = size(F); | ||
|
||
d = zeros(m, n); | ||
h = zeros(m, n); | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
d(i,j) = sqrt( (i-(m/2))^2 + (j-(n/2))^2); | ||
end | ||
end | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
h(i,j) = 1 / (1 + (d(i,j)/d0)^(2*order) ) ; | ||
end | ||
end | ||
|
||
|
||
for i = 1:m | ||
for j = 1:n | ||
res(i,j) = (h(i,j)) * F(i,j); | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function res = ghp(F, d0) | ||
|
||
% inputs | ||
% im is the fourier transform of the image | ||
% thresh is the cutoff circle radius | ||
|
||
%outputs | ||
% res is the filtered image | ||
|
||
[m,n] = size(F); | ||
|
||
d = zeros(m,n); | ||
H = zeros(m,n); | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
d(i,j) = sqrt( (i-(m/2))^2 + (j-(n/2))^2); | ||
end | ||
end | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
H(i,j) = 1- exp ( -( (d(i,j)^2)/(2*(d0^2)) ) ); | ||
end | ||
end | ||
|
||
|
||
for i = 1:m | ||
for j = 1:n | ||
res(i,j) = (H(i,j)) * F(i,j); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function res = glp(F, d0) | ||
|
||
[m, n] = size(F); | ||
|
||
d = double(zeros(m,n)); | ||
h = double(zeros(m,n)); | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
d(i,j) = sqrt( (i-(m/2))^2 + (j-(n/2))^2); | ||
end | ||
end | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
h(i,j) = exp( -( (d(i,j)^2)/(2*((d0)^2)) ) ); | ||
end | ||
end | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
res(i,j) = h(i,j) * F(i,j); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function res = ihp(F, d0) | ||
|
||
[m, n] = size(F); | ||
|
||
d = zeros(m,n); | ||
H = zeros(m,n); | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
d(i,j) = sqrt( (i-(m/2))^2 + (j-(n/2))^2); | ||
end | ||
end | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
if d(i,j) <= d0 | ||
H(i,j) = 0; | ||
else | ||
H(i,j) = 1; | ||
end | ||
end | ||
end | ||
|
||
|
||
for i = 1:m | ||
for j = 1:n | ||
res(i,j) = (H(i,j)) * F(i,j); | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function res = ilp(F, d0) | ||
|
||
[m, n] = size(F); | ||
|
||
d = zeros(m,n); | ||
H = zeros(m,n); | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
d(i,j) = sqrt( (i-(m/2))^2 + (j-(n/2))^2); | ||
end | ||
end | ||
|
||
for i = 1:m | ||
for j = 1:n | ||
if d(i,j) <= d0 | ||
H(i,j) = 1; | ||
else | ||
H(i,j) = 0; | ||
end | ||
end | ||
end | ||
|
||
|
||
for i = 1:m | ||
for j = 1:n | ||
res(i,j) = (H(i,j)) * F(i,j); | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
clear; | ||
|
||
%Importing image | ||
img = imread('2.JPG'); | ||
[m, n, k] = size(img); | ||
MN = m*n; | ||
|
||
%Computing Histogram Equalization for three channels | ||
hImg = histEqu(img(:,:,1), m, n, MN); | ||
hImg(:,:,2) = histEqu(img(:,:,2), m, n, MN); | ||
hImg(:,:,3) = histEqu(img(:,:,3), m, n, MN); | ||
|
||
|
||
%Displaying the result for three channel | ||
figure, | ||
subplot(2,3,1), | ||
imshow(hImg(:,:,1)); | ||
title('Red Image'); | ||
|
||
subplot(2,3,2), | ||
imshow(hImg(:,:,2)); | ||
title('Green Image'); | ||
|
||
subplot(2,3,3), | ||
imshow(hImg(:,:,3)); | ||
title('Blue Image'); | ||
|
||
subplot(2,3,4), | ||
histogram(hImg(:,:,1)); | ||
title('Red Image'); | ||
|
||
subplot(2,3,5), | ||
histogram(hImg(:,:,2)); | ||
title('Green Image'); | ||
|
||
subplot(2,3,6), | ||
histogram(hImg(:,:,3)); | ||
title('Blue Image'); | ||
|
||
|
||
%Displaying the Histogram Equalized image | ||
figure, | ||
subplot(2,2,1), | ||
imshow(img); | ||
title('Original Image'); | ||
|
||
subplot(2,2,2), | ||
histogram(img); | ||
title('Original Image'); | ||
|
||
subplot(2,2,3), | ||
imshow(hImg); | ||
title('Equalized Image'); | ||
|
||
subplot(2,2,4), | ||
histogram(hImg); | ||
title('Equalized Image'); | ||
|
||
|
||
function hImg = histEqu(Img, m, n, MN) | ||
hImg=uint8(zeros(m, n)); | ||
freq=zeros(256,1); | ||
probf=zeros(256,1); | ||
probc=zeros(256,1); | ||
cum=zeros(256,1); | ||
output=zeros(256,1); | ||
|
||
for i=1:m | ||
for j=1:n | ||
value=Img(i,j); | ||
freq(value+1)=freq(value+1)+1; | ||
end | ||
end | ||
probf=freq/MN; | ||
|
||
sum=0; | ||
no_bins=255; | ||
|
||
for i=1:size(probf) | ||
sum=sum+freq(i); | ||
cum(i)=sum; | ||
probc(i)=cum(i)/MN; | ||
output(i)=round(probc(i)*no_bins); | ||
end | ||
|
||
for i=1:m | ||
for j=1:n | ||
hImg(i,j)=output(Img(i,j)+1); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
clear; | ||
|
||
%Importing image | ||
img = imread('2.JPG'); | ||
[m, n, k] = size(img); | ||
|
||
%Computing gamma transformation for three different gamma. | ||
gamma = 5; | ||
gamma1 = 2; | ||
gamma2 = .5; | ||
fimg = img; | ||
fimg1 = img; | ||
img2 = double(img); | ||
fimg2 = img; | ||
for i = 1:3 | ||
fimg(:,:,i) = img(:,:,i) .^ gamma; | ||
fimg1(:,:,i) = img(:,:,i) .^ gamma1; | ||
fimg2(:,:,i) = img2(:,:,i) .^ gamma2; | ||
end | ||
|
||
|
||
%Displaying the result | ||
figure, | ||
subplot(2,2,1), | ||
imshow(img); | ||
title('Original Image'); | ||
|
||
subplot(2,2,2), | ||
imshow(fimg); | ||
title('Transform Image(Gamma=5)'); | ||
|
||
subplot(2,2,3), | ||
imshow(fimg1); | ||
title('Transform Image(Gamma=2)'); | ||
|
||
subplot(2,2,4), | ||
imshow(fimg2); | ||
title('Transform Image(Gamma=.5)'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
clear; | ||
|
||
% Importing gray scale image | ||
imgg = imread('3.JPG'); | ||
img = imgg(:,:,1); | ||
[m, n] = size(img); | ||
sImg = img; | ||
%sImg1 = img; | ||
|
||
% Filter definitation | ||
w = [1 2 1 2 4 2 1 2 1]; | ||
%w = [1 1 1 1 1 1 1 1 1]; | ||
weight = sum(w); | ||
|
||
%Filtering the original Image | ||
for i = 1:m | ||
for j = 1:n | ||
z = [getPixel(img, i-1, j-1, m,n), getPixel(img, i-1, j, m,n), getPixel(img, i-1, j+1, m,n), getPixel(img, i, j-1, m,n), getPixel(img, i, j, m,n), getPixel(img, i, j+1, m,n), getPixel(img, i+1, j-1, m,n), getPixel(img, i+1, j, m,n), getPixel(img, i+1, j+1, m,n)]; | ||
sImg(i, j) = round(sum(int8(w) .* int8(z)) / weight); | ||
end | ||
end | ||
|
||
|
||
|
||
|
||
|
||
|
||
%Filtering the original Image | ||
for i = 1:m | ||
for j = 1:n | ||
z = [getPixel(img, i-1, j-1, m,n), getPixel(img, i-1, j, m,n), getPixel(img, i-1, j+1, m,n), getPixel(img, i, j-1, m,n), getPixel(img, i, j, m,n), getPixel(img, i, j+1, m,n), getPixel(img, i+1, j-1, m,n), getPixel(img, i+1, j, m,n), getPixel(img, i+1, j+1, m,n)]; | ||
sImg1(i, j) = median(uint8(z)); | ||
end | ||
end | ||
|
||
|
||
%Printing the Image and the histogram | ||
figure, | ||
subplot(2,2,1), | ||
imshow(img); | ||
title('Original Image'); | ||
|
||
subplot(2,2,2), | ||
histogram(img); | ||
title('Original Image'); | ||
|
||
subplot(2,2,3), | ||
imshow(sImg); | ||
title('Smoothen Image'); | ||
|
||
subplot(2,2,4), | ||
imshow(sImg1); | ||
title('Smoothen Image using Median filter'); | ||
|
||
|
||
function pixl = getPixel(img, x, y, m, n) | ||
if x < 1 || y < 1 || x >= m || y >= n | ||
pixl = 0; | ||
else | ||
pixl = img(x, y); | ||
end | ||
|
Oops, something went wrong.