forked from whitelok/watermark-remover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
waterremover.m
68 lines (55 loc) · 2.16 KB
/
waterremover.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
% clean
% load all images name
imagePath = '../watermark-cvpr17.github.io/supplemental/123RF/image';
imageFiles = dir(imagePath);
% the number of training files
nfiles = length(imageFiles);
% init the array of image
watermarkArray = [];
count = 1;
redGdirPixelList = [];
for ii=1:nfiles
break;
if ~imageFiles(ii).isdir
currentFilename = imageFiles(ii).name;
matchingTargetImg = imread(fullfile(imagePath, currentFilename));
watermark_estimate_pos = [0 0 650 433];
watermark_estimate_img = imcrop(matchingTargetImg, watermark_estimate_pos);
redWMC = edge(watermark_estimate_img(:,:,1),'Canny', 0.1); % Red channel
greenWMC = edge(watermark_estimate_img(:,:,2),'Canny', 0.1); % Green channel
blueWMC = edge(watermark_estimate_img(:,:,3),'Canny', 0.1); % Blue channel
% calc the gradient of the watermark
[gx, gy] = imgradientxy(redWMC,'prewitt');
[redGmag, redGdir] = imgradient(gx, gy);
[gx, gy] = imgradientxy(greenWMC,'prewitt');
[greenGmag, greenGdir] = imgradient(gx, gy);
[gx, gy] = imgradientxy(blueWMC,'prewitt');
[blueGmag, blueGdir] = imgradient(gx, gy);
imwrite(cat(3, redGmag, greenGmag, blueGmag), strcat('tmp/', strcat(int2str(count), '.png')));
count = count + 1;
end
end
% comput median
for i=1:5
tmpImgFiles = dir('tmp');
nTmpFiles = length(tmpImgFiles);
tmpImgList = zeros(nTmpFiles, 433, 650, 3);
count = 1;
for jj=1:nTmpFiles
if ~tmpImgFiles(jj).isdir
img = imread(fullfile('tmp', tmpImgFiles(jj).name));
tmpImgList(count,:,:,:) = img;
count = count + 1;
end
end
redMedian = median(tmpImgList(:,:,:,1));
greenMedian = median(tmpImgList(:,:,:,2));
blueMedian = median(tmpImgList(:,:,:,3));
disp(size(redMedian(1, :, :, :)));
disp(size(cat(4, redMedian(1, :, :), greenMedian(1, :, :), blueMedian(1, :, :))));
figure(1);
W = cat(4, redMedian(1, :, :), greenMedian(1, :, :), blueMedian(1, :, :));
imshow(squeeze(W(1,:,:,:)));
end
%figure(1);
%imshow(cat(3, redMedian(1), greenMedian(1), blueMedian(1)));