-
Notifications
You must be signed in to change notification settings - Fork 0
/
dark_channel_roi.m
63 lines (49 loc) · 1.49 KB
/
dark_channel_roi.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
win_size = 3;
image = double(imread('img/WILD0.5_input.jpg'))/255;
% image = imresize(image, 0.1);
[m, n, ~] = size(image);
pad_size = floor(win_size/2);
padded_image = padarray(image, [pad_size pad_size], Inf);
dark_channel = zeros(m, n);
for j = 1 : m
for i = 1 : n
patch = padded_image(j : j + (win_size-1), i : i + (win_size-1), :);
dark_channel(j,i) = min(patch(:));
end
end
figure,imshow(dark_channel)
%% 找目标域roi
dark_channel = dark_channel * 255;
roi = zeros(m, n);
min_dark_channel = min(dark_channel(:));
s = 15;
for i = 1 : m
for j = 1 : n
if dark_channel(i, j) >= min_dark_channel && dark_channel(i, j) <= (min_dark_channel + s)
roi(i, j) = 1;
end
end
end
imLabel = bwlabel(roi); %对各连通域进行标记
stats = regionprops(imLabel,'Area'); %求各连通域的大小
area = cat(1,stats.Area);
index = find(area == max(area)); %求最大连通域的索引
roi = ismember(imLabel,index); %获取最大连通域图像
%% 打印roi图片
dark_channel = dark_channel / 255;
dark_channel_new = zeros(m, n, 3);
dark_channel_new(:, :, 1) = dark_channel;
dark_channel_new(:, :, 2) = dark_channel;
dark_channel_new(:, :, 3) = dark_channel;
dark_channel = dark_channel_new;
for i = 1:m
for j = 1 : n
if roi(i,j) == 1
dark_channel(i, j, 1)=255;
dark_channel(i, j, 2)=0;
dark_channel(i, j, 3)=187;
end
end
end
imwrite(dark_channel, 'roi_DCP.jpg')
figure,imshow(dark_channel)