-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_switch_UI.m
52 lines (50 loc) · 1.67 KB
/
main_switch_UI.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
%%
% change path in the code line number 10
%%
delete('size1.mat')
delete ('imagename.mat')
delete ('inputDir.mat')
delete('outputDir.mat')
%% Remove the directory every time
rmSubDir( 'F:\bm3d\BM3D\images\prepared_data_normal')
%% create patches
inputDir = uigetdir('.', 'Select input images'' directory');
inputDir = strcat(inputDir, '\');
imageFiles = dir(strcat(inputDir, '*.png'));
[size1 ,size2]=size(imageFiles);
save size1.mat size1
imagename=strcat(inputDir,imageFiles(1).name);
save inputDir.mat inputDir
save imagename.mat imagename
%% Extract patch
outputDir = strcat(inputDir, 'prepared_data_normal\');
% if output directory does not exist then create it
save outputDir.mat outputDir
if(exist(outputDir, 'dir') == 0)
mkdir(outputDir);
end
display('Begin preparing training data...');
tic;
%%
patchSize = 64;
% window size used in local contrast normalization
% A window of windowSize x windowSize will be used
windowSize = 8;
% Run through all images
nImages = length(imageFiles);
for i = 1 : nImages
% Read image and convert to a grayscale and double matrix
imageName = imageFiles(i).name;
image = imread(strcat(inputDir, imageName));
image = rgb2gray(image);
image = im2double(image);
% Divide the image into patchSize x patchSize size patches
imagePatches = getImagePatches(image, patchSize);
% Uncomment to visualize the image patches
visImagePatches(imagePatches);
% Apply local contrast normalization to image patches
% normalizedPatches = normalizeLocalContrast(imagePatches, windowSize, patchSize);
saveImagePatches(imagePatches, outputDir, imageName);
end
toc;
display('Finished preparing training data.')