Skip to content

Commit

Permalink
ratio contour v4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
malloc47 committed Dec 6, 2011
1 parent 5f317c2 commit eef06aa
Show file tree
Hide file tree
Showing 9 changed files with 623 additions and 48 deletions.
63 changes: 19 additions & 44 deletions README
Original file line number Diff line number Diff line change
@@ -1,58 +1,33 @@

RRC (VERSION 3.1): A SALIENT BOUNDARY DETECTION TOOL BY
RRC (VERSION 4.0): A SALIENT BOUNDARY DETECTION TOOL BY
COMBINING BOUNDARY AND REGION INFORMATION

This software package is developed for detecting salient closed
boundaries from an image. The main codes were implemented
in C++ using gcc-4.1 in Linux. It also needs the recent Matlab
Software (with Image Processing Toolbox) to perform some image
preprocessing and result display. This work is covered by Copyright
(c) University of South Carolina. It incorporates Blossom4 code
for graph matching that is developed by W. Cook and A. Rohe. The
technical details of this package can be found in the enclosed
file "document.pdf".
boundaries in an image. The main compoent is implemented in C++ using
gcc-4.1 in Linux. It also requires a recent Matlab (with Image
Processing Toolbox) to perform some image preprocessing and result
display. This work is covered by Copyright (c) University of South
Carolina. It incorporates Blossom4 code for graph matching that is
developed by W. Cook and A. Rohe.

Authors: Joachim Stahl and Song Wang
Authors: Joachim Stahl, Jarrell Waggoner, and Song Wang
With contributions from: Kenton Oliver, Andrei Barbu,
Siddharth Narayanaswamy, and Jeffrey Mark Siskind

Update: 08/11/2006
Update: 10/18/2010

BUILD

INSTALL

After unpacking the package, in the RRC folder, run
./install
This will create an executable RRC.

After unpacking the package run
make
This will create an executable.

USAGE

(1) Go to the folder "matlab", in the Matlab environment, run
preprocess('path/foo')
to preprocess the image "foo.pgm" and write the output to "path/foo.line
s". To preprocess all .pgm files in 'path', use the function
batchPreprocess.m instead,
batchPreprocess('path')

(2) From this installation folder, from the shell, run
./RRC path/foo
to extract one salient boundary. We also provide the following choices:

-l # - Set Lambda (default 0.0), a real positive number that weights
the continuity (curvature) term.
-a # - Set Alpha (default 1.0), the exponent for the gap lengths.It
can take any real value. Recommended range between 1.0 and 2.0.
-n # - Set the number of produced boundaries (default 1).
-h - To use intensity homogeneity instead of region area.

(3) Go to the folder "matlab", in the Matlab environment, run
displayResults('path/foo', n)
to display the n detected boundaries (numbered from 0 to n-1), which are
also saved as EPS and PNG images in the folder "path/".

A set of test images used in the enclosed "document.pdf" are included in
the folder "images".
Examine rc.sh, which illustrates the script and executible components
of the RC pipeline.

CONTACT & BUG REPORT
CONTACT & BUG REPORTS
Song Wang
Computer Vision Lab
Department of Computer Science and Engineering
Expand All @@ -61,4 +36,4 @@ Columbia, SC 29208
Email: songwang@cse.sc.edu
TEL: 1-803-777-2487
FAX: 1-803-777-3767
http://www.cse.sc.edu/~songwang
http://www.cse.sc.edu/~songwang
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

BLOSSOMOBJS = $(BLOSSOM:.c=.o)

all : RatioContour3
all : RatioContour4

RatioContour3 : $(BLOSSOMOBJS)
RatioContour4 : $(BLOSSOMOBJS)
$(LD) -o $@ $(BLOSSOMOBJS) -lm

install : all

clean :
rm -f *.o RatioContour3
rm -f *.o RatioContour4

depend :
makedepend $(INCDIRS) $(SEQU)
Expand Down
2 changes: 1 addition & 1 deletion mat_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ char **av;
fprintf (stderr, " (3) Fix a bug in previous release on May 06, 2004, to produce ONLY ONE cycle.\n");
fprintf (stderr, " ---Song Wang, 10/08/2004.\n");
fprintf (stderr, "------------------------------------------------------------------\n");
fprintf (stderr, "Usage: RatioContour3 image [NumIter(1)]\n\n");
fprintf (stderr, "Usage: RatioContour4 image [NumIter(1)]\n\n");
fprintf (stderr, " Note: image is a image.w file with the format:\n");
fprintf (stderr, " Head line: #v(even) #e \n");
fprintf (stderr, " Each line: v1 v2 weight length solid(1)/dashed(0)\n");
Expand Down
166 changes: 166 additions & 0 deletions matlab/convertGraph.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
function convertGraph(filename)
fid = fopen([filename '.graph'],'r');
if (fid == -1)
display(['Could not open file ' filename '.']);
return;
end
n = fscanf(fid, '%d',1);
disp(['Number of vertices: ' int2str(n)]);
vertices = (fscanf(fid,'%d',[2,n]))';
vertices = [vertices -1*ones(size(vertices,1),1)];
edges = (fscanf(fid,'%d %d %f %f %d'));
edges = reshape(edges,[],length(edges)/5)';
fclose(fid);

solid = edges(find(edges(:,5) == 1),:);
dashed = edges(find(edges(:,5) == 0),:);

RCGraph = [];

% Create solid edges first
for i = 1:size(solid,1)
edge_frag = solid(i,:);

n1 = edge_frag(1);
n2 = edge_frag(2);

vertices(edge_frag(1)+1,3) = i;
vertices(edge_frag(2)+1,3) = i;
% RCGraph = [RCGraph; 2*n1 2*n2 abs(edge_frag(4)) abs(edge_frag(3)) 1; 2*n1+1 2*n2+1 -1*abs(edge_frag(4)) abs(edge_frag(3)) 1 ];
RCGraph = [RCGraph; 2*n1 2*n2 0 0 1; 2*n1+1 2*n2+1 0 0 1 ];

end

% Now create dashed edges
for i = 1:size(dashed,1)

edge_frag = dashed(i,:);

w1 = abs(edge_frag(3));
w2 = abs(edge_frag(4));

e1 = (vertices(edge_frag(1)+1,3)-1);
e2 = (vertices(edge_frag(2)+1,3)-1);

ABw1 = abs(solid(e1+1,3));
ABw2 = abs(solid(e1+1,4));
CDw1 = abs(solid(e2+1,3));
CDw2 = abs(solid(e2+1,4));

n1 = edge_frag(1);
n2 = edge_frag(2);

if(n1 == n2)
disp('Nonunique solid edges!');
return;
end

if(e1 == e2)
disp('Nonunique vertices!');
continue;
end

p1 = vertices(n1+1,1:2);
p2 = vertices(n2+1,1:2);

back1 = vertices(setdiff(solid(e1+1,1:2),n1)+1,1:2);
back2 = vertices(setdiff(solid(e2+1,1:2),n2)+1,1:2);

if(isequal(p1,back1) || isequal(p2,back2) || isequal(p1,back2) || isequal(p2,back1))
disp('Endpoint overlap');
continue;
end

flagAB = false;

if(p1(1) > back1(1))
flagAB = true;
elseif(p1(1) == back1(1))
if(p1(2) > back1(2))
flagAB = true;
end
end

flagCD = false;

if(p2(1) > back2(1))
flagCD = true;
elseif(p2(1) == back2(1))
if(p2(2) > back2(2))
flagCD = true;
end
end

if(p1(1) > p2(1))
w2 = -1*w2;
end

if(flagAB)
w2 = w2 + ABw2/2;
else
w2 = w2 - ABw2/2;
end

if(flagCD)
w2 = w2 - CDw2/2;
else
w2 = w2 + CDw2/2;
end

% w1 = w1 + ABw1/2 + CDw1/2;

if(flagAB) % A->B is positive
if(flagCD) % C->D is negative
RCGraph = [RCGraph; 2*n1 2*n2+1 w2 w1 edge_frag(5); ...
2*n1+1 2*n2 -1*w2 w1 edge_frag(5)];
else % C->D is positive
RCGraph = [RCGraph; 2*n1 2*n2 w2 w1 edge_frag(5); ...
2*n1+1 2*n2+1 -1*w2 w1 edge_frag(5)];
end
else % A->B is negative
if(flagCD) % C->D is negative
RCGraph = [RCGraph; 2*n1+1 2*n2+1 w2 w1 edge_frag(5); ...
2*n1 2*n2 -1*w2 w1 edge_frag(5)];
else % C->D is positive
RCGraph = [RCGraph; 2*n1+1 2*n2 w2 w1 edge_frag(5); ...
2*n1 2*n2+1 -1*w2 w1 edge_frag(5)];
end
end

% if(p1(1) > back1(1)) % A->B is positive
% if(p2(1) > back2(1)) % C->D is negative
% RCGraph = [RCGraph; 2*n1 2*n2+1 w2 w1 edge_frag(5); ...
% 2*n1+1 2*n2 -1*w2 w1 edge_frag(5)];
% else % C->D is positive
% RCGraph = [RCGraph; 2*n1 2*n2 w2 w1 edge_frag(5); ...
% 2*n1+1 2*n2+1 -1*w2 w1 edge_frag(5)];
% end
% else % A->B is negative
% if(p2(1) > back2(1)) % C->D is negative
% RCGraph = [RCGraph; 2*n1+1 2*n2+1 w2 w1 edge_frag(5); ...
% 2*n1 2*n2 -1*w2 w1 edge_frag(5)];
% else % C->D is positive
% RCGraph = [RCGraph; 2*n1+1 2*n2 w2 w1 edge_frag(5); ...
% 2*n1 2*n2+1 -1*w2 w1 edge_frag(5)];
% end
% end
end

maxw1 = max(abs(RCGraph(:,4)))
maxw2 = max(abs(RCGraph(:,3)))

for i = 1:size(RCGraph,1)
RCGraph(i,3) = (RCGraph(i,3)*600)/maxw2;
RCGraph(i,4) = (RCGraph(i,4)*600)/maxw1;
end

RCGraph = int16(RCGraph);

largestsolididx = max(max(RCGraph(find(RCGraph(:,5)==1),1:2)))+1;

fid = fopen([filename '.w'],'w');
fprintf(fid,'%d\t%d\n',largestsolididx,size(RCGraph,1));
fprintf(fid, '%d %d %d %d %d\n', RCGraph');
fclose(fid);
end

52 changes: 52 additions & 0 deletions matlab/convertlines.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function convertlines(filename)

lines = dlmread([filename '.lines']);

vertices = [];
solid = [];
dashed = [];
vidx = 0;

for i = 1:size(lines,1)
line = lines(i,:);
vertices = [vertices; line(1) line(2); line(3) line(4)];
% solid = [solid; vidx vidx+1 0 (abs(line(3)-line(1))*(line(2)+line(4)))/2 1];
solid = [solid; vidx vidx+1 0 area(line(1),line(2),line(3),line(4)) 1];
vidx = vidx + 2;
end

for i = 1:size(vertices,1)-1
for j = i+1:size(vertices,1)

p1 = vertices(i,:);
p2 = vertices(j,:);

% dist = abs(p1(1)-p2(1))+abs(p1(2)-p2(2));
dist = sqrt((p2-p1)*(p2-p1)');

if(dist > 50)
continue;
end

% dashed = [dashed; i-1 j-1 dist (abs(p2(1)-p1(1))*(p1(2)+p2(2)))/2 0 ];
dashed = [dashed; i-1 j-1 dist area(p1(1),p1(2),p2(1),p2(2)) 0 ];

end
end

fid = fopen([filename '.graph'],'w');
fprintf(fid,'%d\n',size(vertices,1));
fprintf(fid, '%d %d\n', vertices');
fprintf(fid, '%d %d %f %f %d\n', solid');
fprintf(fid, '%d %d %f %f %d\n', dashed');
fclose(fid);

end

function a = area(P1x,P1y,P2x,P2y)
if(P1y>P2y)
a = abs(P1x-P2x)*(P1y - abs(P1y-P2y)/2);
else
a = abs(P1x-P2x)*(P2y - abs(P1y-P2y)/2);
end
end
Loading

0 comments on commit eef06aa

Please sign in to comment.