|
a |
|
b/3D Reconstruction/Denoising/denoising.m |
|
|
1 |
function denoising(inputDir, outputDir, thresh) |
|
|
2 |
%Image denoising by Morphology-based Smoothing |
|
|
3 |
% inputDir: input image directory |
|
|
4 |
% outputDir: output image directory |
|
|
5 |
% thresh: the threshold for binarizing(0~255) |
|
|
6 |
imgDir = dir([inputDir '*.png']); % 遍历目录内所有png格式文件 |
|
|
7 |
for i = 1:length(imgDir) |
|
|
8 |
raw = imread([inputDir imgDir(i).name]); %¶ΑΘ΅ΓΏΥΕΝΌΖ¬ |
|
|
9 |
binary = raw; |
|
|
10 |
binary(binary>thresh) = 255; |
|
|
11 |
binary(binary<=thresh) = 0; |
|
|
12 |
se = strel('disk', 3); |
|
|
13 |
new = imclose(binary, se); |
|
|
14 |
new = imopen(new, se); |
|
|
15 |
new(new>0) = 255; |
|
|
16 |
imwrite(uint8(new), [outputDir imgDir(i).name]); |
|
|
17 |
end |
|
|
18 |
end |
|
|
19 |
|