Skip to content

Commit ce27dca

Browse files
add: new functions, gui
1 parent fb3ef41 commit ce27dca

16 files changed

+1301
-16
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# vectofil+
2-
A program to perform Basic Vector Directional Filtering for the noisy color images. This a project of Computer Vision and Image Processing course in West Pomeranian University of Technology.
2+
A program to perform Basic Vector Directional Filtering for the noisy colour images. This a project of Computer Vision and Image Processing course in West Pomeranian University of Technology.
33

4-
For the demostration, check out Results directory, or [see the GUI on YouTube](https://www.youtube.com/watch?v=pXBCrB0VlLY).
4+
For the demonstration, check out Results directory, or [see the GUI on YouTube](https://www.youtube.com/watch?v=pXBCrB0VlLY).
55

66
### What we will add?
7-
- Save the output functionality.
8-
- Save the process as a PDF and PNGs functionality
9-
- Choosing the Vector Median Filtering or Basic Vector Directional Filtering process. Comperasion between two filters.
10-
- Percentage addition between VMF and BVDF.
11-
- Much more pretty UI!
12-
- Documentation for every function. Especially lots of comments on the file of BVDF_FILTER.
7+
8+
- [ ] Save the output functionality.
9+
10+
- [ ] Save the process as a PDF and PNGs functionality.
11+
12+
- [x] Choosing the Vector Median Filtering or Basic Vector Directional Filtering process. Comperasion between two filters.
13+
14+
- [x] Percentage addition between VMF and BVDF.
15+
16+
- [x] Much more pretty UI!
17+
18+
- [ ] Documentation for every function. Especially lots of comments on the file of BVDF_FILTER.
1319

1420
### License
1521
This is a art of open source. Please make sure that you also create an open source for the public good.
22+
23+
License: GNU v2
24+
1.18 MB
Binary file not shown.
922 KB
Binary file not shown.

results/Lenna-VMF-BVDF-60.pdf

935 KB
Binary file not shown.

src/API/bvdf_plot_vectors.m renamed to src/API/3DVectorPlot.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function bvdf_plot_vectors(vectors, origin, ColorScheme)
2-
% BVDF_PLOT_VECTORS The function plots the 3D vectors in space.
1+
function 3DVectorPlot(vectors, origin, ColorScheme)
2+
% 3DVectorPlot The function plots the 3D vectors in space.
33
% Only and first parameter is the matrix which every column is a vector.
44

55
% Control if the optional arguments are given.
@@ -34,4 +34,4 @@ function bvdf_plot_vectors(vectors, origin, ColorScheme)
3434
end
3535

3636
hold off;
37-
end
37+
end

src/API/bvdf_add_noise.m renamed to src/API/AddPseudoNoise.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function noisy_img = bvdf_add_noise(image, perc, channel_size, assigned)
1+
function noisy_img = AddPseudoNoise(image, perc, channel_size, assigned)
22
noisy_img = image;
33

44
% Travel throught every pixel.
@@ -27,4 +27,4 @@
2727
end
2828
end
2929
end
30-
end
30+
end
File renamed without changes.

src/API/bvdf_filter.m renamed to src/API/BasicVectorDirectionalFilter.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function filtered_image = bvdf_filter(image, sample_dims)
1+
function filtered_image = BasicVectorDirectionalFilter(image, sample_dims)
22
% BVDF_FILTER Function to filter the image according the BVDF rule.
33
if nargin < 2
44
error("You have to give the image as uint8 matrix, and dimensions of the vectoral process.");
@@ -21,7 +21,7 @@
2121
area2filter = im2double(area2filter).*255;
2222

2323
vectors_list = reshape(area2filter , [], 3)';
24-
sorted_vectors = bvdf_sort_vectors(vectors_list);
24+
sorted_vectors = SortVectorsbyAngle(vectors_list);
2525
filtered_image(x_index, y_index, :) = sorted_vectors(:, 1);
2626
end
2727
end

src/API/ColorImageDifference.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
% COLORIMAGEDIFFERENCE
2+
3+
function [resultedImage, differentPixelCount] = ColorImageDifference(image1, image2)
4+
sizeImg1 = size(image1);
5+
sizeImg2 = size(image2);
6+
differentPixelCount = 0;
7+
8+
if (sizeImg1 - sizeImg2) ~= zeros(1, 3)
9+
error("Given input images' sizes are not matched.");
10+
end
11+
12+
resultedImage = zeros(sizeImg1);
13+
14+
for rowPixel = 1:sizeImg1(1)
15+
for colPixel = 1:sizeImg1(2)
16+
if min(...
17+
image1(rowPixel, colPixel, :) == image2(rowPixel, colPixel, :)...
18+
) == 0
19+
20+
resultedImage(rowPixel, colPixel, :) = [255, 255, 255]';
21+
differentPixelCount = differentPixelCount + 1;
22+
end
23+
end
24+
end
25+
end
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function filtered_image = DistanceDirectionalFilter(corrupted_image, window_size, BVDFratio, yValueVMF)
2+
image_X = size(corrupted_image, 1);
3+
image_Y = size(corrupted_image, 2);
4+
5+
filtered_image = zeros(size(corrupted_image));
6+
starting_points = [ceil(window_size/2), ceil(window_size/2)];
7+
choosing_distance = [floor(window_size/2), floor(window_size/2)];
8+
9+
for x_index = starting_points(1):(image_X-starting_points(1))
10+
for y_index = starting_points(2):(image_Y-starting_points(2))
11+
12+
area2filter = corrupted_image(x_index-choosing_distance(1):x_index+choosing_distance(2),...
13+
y_index-choosing_distance(2):y_index+choosing_distance(2), :);
14+
area2filter = im2double(area2filter).*255;
15+
vectors_list = reshape(area2filter , [], 3)';
16+
17+
% Sorting Process
18+
% In here, one array of vectors is created. First row will give
19+
% us the distances calculated with VMF, second row will give us
20+
% the angles calculated with BVDF. That's why there is "+2".
21+
calculations = zeros(size(vectors_list, 1) + 3, size(vectors_list, 2));
22+
calculations(4:end, :) = vectors_list;
23+
24+
for index = 1:size(vectors_list, 2)
25+
for jndex = 1:size(vectors_list, 2)
26+
27+
% For each pixel, we are choosing the window-size of
28+
% pixels, and calculate the angles and distances from
29+
% them.
30+
31+
vectA = vectors_list(:, index);
32+
vectB = vectors_list(:, jndex);
33+
34+
if vectA == vectB
35+
continue;
36+
end
37+
38+
% BVDF method for window-sized vectors.
39+
calculations(3, index) = calculations(2, index) + ...
40+
acosd(dot(vectA, vectB) / (norm(vectA) * norm(vectB)));
41+
42+
% VMF method for window-sized vectors with Euclodien distances.
43+
colorRed = (vectA(1) - vectB(1)).^(yValueVMF);
44+
colorGreen = (vectA(2) - vectB(2)).^(yValueVMF);
45+
colorBlue = (vectA(3) - vectB(3)).^(yValueVMF);
46+
VMF_distance = (colorRed + colorGreen + colorBlue).^(1/yValueVMF);
47+
calculations(2, index) = calculations(2, index) + VMF_distance;
48+
49+
end
50+
end
51+
52+
% Combination of VMF and BVDF: Distance Directional Filter
53+
calculations(1, :) = (calculations(3, :).^(BVDFratio)) .* (calculations(2, :).^(1-BVDFratio));
54+
55+
% Sorting the vectors inside the window, with the rules of BVDF
56+
% and VMF.
57+
% [~, VMForder] = sort(calculations(2, :));
58+
% [~, BVDForder] = sort(calculations(3, :));
59+
% VMFSortedVects = calculations(3:end, VMForder);
60+
% BVDFSortedVects = calculations(3:end, BVDForder);
61+
% VMF_Vector = VMFSortedVects(:, 1);
62+
% BVDF_Vector = BVDFSortedVects(:, 1);
63+
[~, DDForder] = sort(calculations(1, :));
64+
DDFSortedVects = calculations(4:end, DDForder);
65+
DDF_Vector = DDFSortedVects(:, 1);
66+
67+
filtered_image(x_index, y_index, :) = DDF_Vector;
68+
69+
end
70+
end
71+
72+
filtered_image = cast(filtered_image, 'uint8');
73+
end

0 commit comments

Comments
 (0)