-
Notifications
You must be signed in to change notification settings - Fork 0
/
testBranch.m
executable file
·61 lines (50 loc) · 1.79 KB
/
testBranch.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
%for testing new features
function [idx, mask] = testBranch(oriImg, segments, num, info)
disp(num);
%process ambiguous region
%for flowers.png: 348 381
[x1, y1] = find(segments ==num);
top = min(x1);
bottom = max(x1);
left = min(y1);
right = max(y1);
idx = [top, bottom, left, right];
cropImg = oriImg(top:bottom, left:right,:);
figure; imshow(cropImg);
cform = makecform('srgb2lab');
labImg = applycform(cropImg,cform);
ab = double(labImg(:,:,2:3));
%ab(:,:,1) = ab(:,:,1).*mask;
%ab(:,:,2) = ab(:,:,2).*mask;
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2)';
% cform = makecform('srgb2lab');
% labImg = applycform(oriImg,cform);
% layer1 = labImg(:,:,2);
% layer2 = labImg(:,:,3);
% ab = zeros(2, size(x1,1));
% ab(1, :) = double(layer1(segments==347));
% ab(2, :) = double(layer2(segments==347));
nColors = 2;
% repeat the clustering 3 times to avoid local minima
%[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
% 'Replicates',3);
% addpath(genpath('vlfeat-0.9.18')) ;
% vl_setup();
[idx_, C_, e] = vl_kmeans(ab, nColors,'distance', 'l1') ;
mask = reshape(C_, nrows, ncols);
%result = double(result) .* double(mask);
figure; imagesc(mask);
mask = mask - 1;
%identify fg bg region
mask_x = info(3) - top + 1;
mask_y = info(4) - left + 1;
if( xor(mask(mask_x, mask_y), info(2)) ==1 ) %flip fg/ bg
tmp = ones(size(mask, 1), size(mask, 2));
mask = xor(mask, tmp);
end
%I=rgb2gray(cropImg);
%L = watershed(I);
%figure; imagesc(L);
end