-
Notifications
You must be signed in to change notification settings - Fork 9
/
generating_test.m
73 lines (52 loc) · 1.69 KB
/
generating_test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This script is used to generate the testing samples
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
close all;
clc;
addpath('./Utils');
% PatSize ±ØÐëΪÆæÊý
PatSize = 7;
k_n = 3;
fprintf(' ... ... read image file ... ... ... ....\n');
im1 = imread('./pic/bern_1.bmp');
im2 = imread('./pic/bern_2.bmp');
im_gt = imread('./pic/bern_gt.bmp');
fprintf(' ... ... read image file finished !!! !!!\n\n');
im1 = double(im1(:,:,1));
im2 = double(im2(:,:,1));
im_gt = double(im_gt(:,:,1));
[ylen, xlen] = size(im1);
% Caculate neighborhood-based ratio image
fprintf(' ... .. compute the neighborhood ratio ..\n');
nrmap = nr(im1, im2, k_n);
nrmap = max(nrmap(:))-nrmap;
nrmap = nr_enhance( nrmap );
% Select patch for each pixel center
mag = (PatSize-1)/2;
imTmp = zeros(ylen+PatSize-1, xlen+PatSize-1);
imTmp((mag+1):end-mag,(mag+1):end-mag) = nrmap;
nrmap = im2col_general(imTmp, [PatSize, PatSize]);
clear imTmp mag;
nrmap = mat2imgcell(nrmap, PatSize, PatSize, 'gray');
fid = fopen('E:\matlab workplace\DFFN\picture\test\test.txt','wt');
for i = 1:xlen*ylen
if (im_gt(i)==0)
fprintf(fid,'%s','img_');
fprintf(fid,'%g',i);
fprintf(fid,'%s\t','.png');
fprintf(fid,'%g\n',0);
else
fprintf(fid,'%s','img_');
fprintf(fid,'%g',i);
fprintf(fid,'%s\t','.png');
fprintf(fid,'%g\n',1)
end
end
fclose(fid);
% Testing samples generation
for i = 1:xlen*ylen
pic = nrmap{i};
imwrite(uint8(pic),['E:\matlab workplace\DFFN\picture\test\a\','img_',num2str(i),'.png'],'png');
end
fprintf(' ... ... over !!! !!!\n\n');