Skip to content

Commit 772184d

Browse files
committed
Initial commit
1 parent ab95f92 commit 772184d

File tree

1,537 files changed

+146801
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,537 files changed

+146801
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<deployment-project plugin="plugin.apptool" plugin-version="1.0">
3+
<configuration target="target.mlapps" target-name="Package App" name="Active Contours implementation &amp; test platform GUI" location="D:\Kolian\Matlab_scripts\FileExchange\Activeontours" file="D:\Kolian\Matlab_scripts\FileExchange\Activeontours\Active Contours implementation &amp; test platform GUI.prj" build-checksum="1484381674">
4+
<param.appname>Active Contours implementation &amp; test platform GUI</param.appname>
5+
<param.authnamewatermark>Nikolay S</param.authnamewatermark>
6+
<param.email />
7+
<param.company />
8+
<param.icon />
9+
<param.summary>Implementation and demonstration of several active contours segmentation methods.</param.summary>
10+
<param.description>This program was written as a part of the “Medical Imaging” course. Together with Alex Blekhman (http://www.mathworks.com/matlabcentral/fileexchange/authors/26540)- my partner we have implemented the paper "Active Contours without Edges" by Tony Chan and Luminita Vese. We wrapped it up with a GUI to allow easy parameters change and segmentation process view and results storage for future analysis.
11+
Later on we have added two existing implementation of additional methods to compare between the methods, and to learn each. The method are:
12+
1)
13+
Implementation of "Level Set Evolution Without Re-initialization: A New Variational Formulation" in Proceedings of CVPR'05, vol. 1, pp. 430-436.
14+
Author: Chunming Li, all rights reserved.
15+
16+
URL: http://www.engr.uconn.edu/~cmli/
17+
2)
18+
Implementation of "Localizing Region Based Active Contours" in “Image Processing, IEEE Transactions on “ im Nov. 2008 by Lankton and Tannenbaum.
19+
Coded by: Shawn Lankton (www.shawnlankton.com)
20+
21+
This is the place to thank both authors for the code contribution.
22+
23+
The users who download this code are welcome to play with it, to try and learn the above segmentation schemes. Moreover, additional methods can be added, and the GUI may serve as a convenient platform for segmentation methods understanding, analysis and comparisons.
24+
Best segmenting you all!</param.description>
25+
<param.screenshot>D:\Kolian\Matlab_scripts\FileExchange\preview.jpg</param.screenshot>
26+
<param.version>1.0</param.version>
27+
<param.products.name>
28+
<item>MATLAB</item>
29+
<item>Signal Processing Toolbox</item>
30+
<item>Image Processing Toolbox</item>
31+
<item>Statistics Toolbox</item>
32+
</param.products.name>
33+
<param.products.id>
34+
<item>1</item>
35+
<item>8</item>
36+
<item>17</item>
37+
<item>19</item>
38+
</param.products.id>
39+
<param.products.version>
40+
<item>8.0</item>
41+
<item>6.18</item>
42+
<item>8.1</item>
43+
<item>8.1</item>
44+
</param.products.version>
45+
<param.platforms />
46+
<param.output>${PROJECT_ROOT}\Active Contours implementation &amp; test platform GUI.mlappinstall</param.output>
47+
<param.guid>e78c8aa2-ba65-436c-805a-b05619730ae5</param.guid>
48+
<unset>
49+
<param.email />
50+
<param.company />
51+
<param.icon />
52+
<param.version />
53+
<param.platforms />
54+
</unset>
55+
<fileset.main>
56+
<file>${PROJECT_ROOT}\ActiveCountorsGUI.m</file>
57+
</fileset.main>
58+
<fileset.depfun>
59+
<file>${PROJECT_ROOT}\ActiveContoursWihoutEdges.m</file>
60+
<file>${PROJECT_ROOT}\ActiveCountorsGUI.fig</file>
61+
<file>${PROJECT_ROOT}\Images\128X128\BallsClusters.jpg</file>
62+
<file>${PROJECT_ROOT}\Images\128X128\BallsClustersLightBalls.jpg</file>
63+
<file>${PROJECT_ROOT}\Images\128X128\BallsOnGray.jpg</file>
64+
<file>${PROJECT_ROOT}\Images\128X128\BlurredBallsOnGray.jpg</file>
65+
<file>${PROJECT_ROOT}\Images\128X128\BlurredLenaText.jpg</file>
66+
<file>${PROJECT_ROOT}\Images\128X128\BlurredShapesOnGray1.jpg</file>
67+
<file>${PROJECT_ROOT}\Images\128X128\BlurredShapesOnGray2.jpg</file>
68+
<file>${PROJECT_ROOT}\Images\128X128\Brodats1.tiff</file>
69+
<file>${PROJECT_ROOT}\Images\128X128\Brodats2.tiff</file>
70+
<file>${PROJECT_ROOT}\Images\128X128\Egypt8.tif</file>
71+
<file>${PROJECT_ROOT}\Images\128X128\Egypt9.tif</file>
72+
<file>${PROJECT_ROOT}\Images\128X128\EuropeNight1.jpg</file>
73+
<file>${PROJECT_ROOT}\Images\128X128\EuropeNight2.jpg</file>
74+
<file>${PROJECT_ROOT}\Images\128X128\GradientBall.jpg</file>
75+
<file>${PROJECT_ROOT}\Images\128X128\HiResSpiral.jpg</file>
76+
<file>${PROJECT_ROOT}\Images\128X128\Lena.jpg</file>
77+
<file>${PROJECT_ROOT}\Images\128X128\LenaText.jpg</file>
78+
<file>${PROJECT_ROOT}\Images\128X128\LinesSketch.jpg</file>
79+
<file>${PROJECT_ROOT}\Images\128X128\monkey.png</file>
80+
<file>${PROJECT_ROOT}\Images\128X128\PaperSpiral.jpg</file>
81+
<file>${PROJECT_ROOT}\Images\128X128\Shapes.JPG</file>
82+
<file>${PROJECT_ROOT}\Images\128X128\ShapesOnGray1.jpg</file>
83+
<file>${PROJECT_ROOT}\Images\128X128\ShapesOnGray2.jpg</file>
84+
<file>${PROJECT_ROOT}\Images\128X128\Thumbs.db</file>
85+
<file>${PROJECT_ROOT}\Images\256X256\BallsClusters.jpg</file>
86+
<file>${PROJECT_ROOT}\Images\256X256\BallsClustersLightBalls.jpg</file>
87+
<file>${PROJECT_ROOT}\Images\256X256\BallsOnGray.jpg</file>
88+
<file>${PROJECT_ROOT}\Images\256X256\BlurredBallsOnGray.jpg</file>
89+
<file>${PROJECT_ROOT}\Images\256X256\BlurredLenaText.jpg</file>
90+
<file>${PROJECT_ROOT}\Images\256X256\BlurredShapesOnGray1.jpg</file>
91+
<file>${PROJECT_ROOT}\Images\256X256\BlurredShapesOnGray2.jpg</file>
92+
<file>${PROJECT_ROOT}\Images\256X256\Brodats1.tiff</file>
93+
<file>${PROJECT_ROOT}\Images\256X256\Brodats2.tiff</file>
94+
<file>${PROJECT_ROOT}\Images\256X256\Egypt8.tif</file>
95+
<file>${PROJECT_ROOT}\Images\256X256\Egypt9.tif</file>
96+
<file>${PROJECT_ROOT}\Images\256X256\EuropeNight1.jpg</file>
97+
<file>${PROJECT_ROOT}\Images\256X256\EuropeNight2.jpg</file>
98+
<file>${PROJECT_ROOT}\Images\256X256\GradientBall.jpg</file>
99+
<file>${PROJECT_ROOT}\Images\256X256\HiResSpiral.jpg</file>
100+
<file>${PROJECT_ROOT}\Images\256X256\Lena.jpg</file>
101+
<file>${PROJECT_ROOT}\Images\256X256\LenaText.jpg</file>
102+
<file>${PROJECT_ROOT}\Images\256X256\LinesSketch.jpg</file>
103+
<file>${PROJECT_ROOT}\Images\256X256\monkey.png</file>
104+
<file>${PROJECT_ROOT}\Images\256X256\PaperSpiral.jpg</file>
105+
<file>${PROJECT_ROOT}\Images\256X256\ShapesOnGray1.jpg</file>
106+
<file>${PROJECT_ROOT}\Images\256X256\ShapesOnGray2.jpg</file>
107+
<file>${PROJECT_ROOT}\Images\256X256\Thumbs.db</file>
108+
<file>${PROJECT_ROOT}\Images\64X64\BallsClusters.jpg</file>
109+
<file>${PROJECT_ROOT}\Images\64X64\BallsClustersLightBalls.jpg</file>
110+
<file>${PROJECT_ROOT}\Images\64X64\BallsOnGray.jpg</file>
111+
<file>${PROJECT_ROOT}\Images\64X64\BlurredBallsOnGray.jpg</file>
112+
<file>${PROJECT_ROOT}\Images\64X64\BlurredLenaText.jpg</file>
113+
<file>${PROJECT_ROOT}\Images\64X64\BlurredShapesOnGray1.jpg</file>
114+
<file>${PROJECT_ROOT}\Images\64X64\BlurredShapesOnGray2.jpg</file>
115+
<file>${PROJECT_ROOT}\Images\64X64\Brodats1.tiff</file>
116+
<file>${PROJECT_ROOT}\Images\64X64\Brodats2.tiff</file>
117+
<file>${PROJECT_ROOT}\Images\64X64\Egypt8.tif</file>
118+
<file>${PROJECT_ROOT}\Images\64X64\Egypt9.tif</file>
119+
<file>${PROJECT_ROOT}\Images\64X64\EuropeNight1.jpg</file>
120+
<file>${PROJECT_ROOT}\Images\64X64\EuropeNight2.jpg</file>
121+
<file>${PROJECT_ROOT}\Images\64X64\GradientBall.jpg</file>
122+
<file>${PROJECT_ROOT}\Images\64X64\HiResSpiral.jpg</file>
123+
<file>${PROJECT_ROOT}\Images\64X64\Lena.jpg</file>
124+
<file>${PROJECT_ROOT}\Images\64X64\LenaText.jpg</file>
125+
<file>${PROJECT_ROOT}\Images\64X64\LinesSketch.jpg</file>
126+
<file>${PROJECT_ROOT}\Images\64X64\monkey.png</file>
127+
<file>${PROJECT_ROOT}\Images\64X64\PaperSpiral.jpg</file>
128+
<file>${PROJECT_ROOT}\Images\64X64\ShapesOnGray1.jpg</file>
129+
<file>${PROJECT_ROOT}\Images\64X64\ShapesOnGray2.jpg</file>
130+
<file>${PROJECT_ROOT}\Images\64X64\twocells.bmp</file>
131+
<file>${PROJECT_ROOT}\Images\64X64\twoObj.bmp</file>
132+
<file>${PROJECT_ROOT}\InfoFiles\ActiveContoursAbout.htm</file>
133+
<file>${PROJECT_ROOT}\InfoFiles\ActiveContoursHelp.htm</file>
134+
<file>${PROJECT_ROOT}\LevelSetEvolutionWithoutReinitialization.m</file>
135+
<file>${PROJECT_ROOT}\localized_seg.m</file>
136+
</fileset.depfun>
137+
<fileset.resources>
138+
<file>${PROJECT_ROOT}\Images</file>
139+
<file>${PROJECT_ROOT}\InfoFiles</file>
140+
</fileset.resources>
141+
<fileset.package />
142+
<build-deliverables>
143+
<file name="Active Contours implementation &amp; test platform GUI.mlappinstall" location="D:\Kolian\Matlab_scripts\FileExchange\Activeontours" optional="false">D:\Kolian\Matlab_scripts\FileExchange\Activeontours\Active Contours implementation &amp; test platform GUI.mlappinstall</file>
144+
</build-deliverables>
145+
<workflow />
146+
<matlab>
147+
<root>C:\Program Files\MATLAB\R2012b</root>
148+
</matlab>
149+
<platform>
150+
<unix>false</unix>
151+
<mac>false</mac>
152+
<windows>true</windows>
153+
<win2k>false</win2k>
154+
<winxp>false</winxp>
155+
<vista>false</vista>
156+
<linux>false</linux>
157+
<solaris>false</solaris>
158+
<osver>6.1</osver>
159+
<os32>false</os32>
160+
<os64>true</os64>
161+
<arch>win64</arch>
162+
<matlab>true</matlab>
163+
</platform>
164+
</configuration>
165+
</deployment-project>
166+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
function ActiveContoursWihoutEdges(hObject,mask)
2+
%This function implements the paper "Active Contours without Edges" by
3+
%Tony Chan and Luminita Vese. It also present results accourding to user
4+
%wish (from ActiveCountorsGUI). Coding- Nikolay S. & Alex B.
5+
%Input argument- a Handle to an object of ActiveCountorsGUI
6+
7+
handles=guidata(hObject);
8+
%% get Alg parametrs from GUI
9+
N=get(handles.NAlgEdit,'Value'); % number of iterations
10+
Lambda_1=get(handles.Lambda1AlgEdit,'Value');
11+
Lambda_2=get(handles.Lambda2AlgEdit,'Value');
12+
miu=get(handles.MiuAlgEdit,'Value'); % varies from 255*1e-1 to 255*1e-4
13+
v=get(handles.NuAlgEdit,'Value');
14+
delta_t=get(handles.DeltaTAlgEdit,'Value');
15+
HTflag=get(handles.HTBasedAlg,'Value');
16+
17+
%% Get visual/plotting parameters
18+
FigRefresRate=get(handles.RefreshRateEdit,'Value');
19+
SaveRefresRate=get(handles.SaveRateEdit,'Value');
20+
SegDispaly=get(handles.SegmentOn,'Value');
21+
EnergyDispaly=get(handles.EnergyOn,'Value');
22+
EnergyImageType=get(handles.EnergyPlotTypeMenu,'Value');
23+
no_of_plots=SegDispaly+EnergyDispaly;
24+
uipael_handle=handles.Axis_uipanel;
25+
26+
if no_of_plots==1
27+
%set(handles.GUIfig,'CurrentAxes',handles.Axes)
28+
subplot(no_of_plots,1,1,'Units','Normalized','Parent',uipael_handle)
29+
end
30+
31+
%% get I/O parameters
32+
out_dir=handles.OutDirPath;
33+
% get file name from path
34+
file_str=handles.ImageFileAddr;
35+
% [pathstr, name, ext, versn] = fileparts(filename)
36+
[~, in_file_name, ~] = fileparts(file_str);
37+
38+
text_line_length=60;
39+
40+
%% divide name too long to cell array to allow compact presentation in text command
41+
length_file_str=length(file_str);
42+
cell_array_length=ceil(length_file_str/text_line_length);
43+
file_str4text=cell(1,cell_array_length);
44+
for ind=1:cell_array_length-1
45+
file_str4text{ind}=[file_str((1+(ind-1)*text_line_length):...
46+
ind*text_line_length),'...'];
47+
end
48+
file_str4text{ind+1}=file_str((1+ind*text_line_length):end);
49+
50+
%% load image
51+
img=handles.ImageData;
52+
[img_x,img_y]=size(img);
53+
54+
%% Init Phi
55+
phi=bwdist(1-mask)-bwdist(mask);
56+
% phi=phi.^3;
57+
phi=phi/(max(max(phi))-min(min(phi))); %normilize to amplitude=1
58+
% K=zeros(img_x,img_y); %init K matrix
59+
if ~strcmpi(class(phi),'double')
60+
phi=double(phi);
61+
end
62+
63+
%define HT
64+
if (HTflag)
65+
% x=-i*sign(linspace(0,1,150)-.5);
66+
N_U=10;N_V=10;
67+
[U,V]=meshgrid(linspace(-fix(N_U/2),fix(N_U/2),N_U),linspace(-fix(N_V/2),fix(N_V/2),N_U));
68+
H_UV_HT=sign(U).*sign(V);
69+
h_ht=fftshift(ifft(H_UV_HT));
70+
end
71+
72+
73+
for n=1:N % main loop
74+
%% Active contours iterations
75+
c_1=sum(img(phi>=0))/max(1,length(img(phi>0))); % prevent division by zero
76+
c_2=sum(img(phi<0))/max(1,length(img(phi<0))); % prevent division by zero
77+
78+
if (HTflag)
79+
dx=filter2(h_ht,phi,'same');
80+
dy=dx.';
81+
else
82+
[dx,dy]=gradient(phi);
83+
end
84+
85+
grad_norm=max(eps,sqrt(dx.^2+dy.^2));%we want to prevent division by zero
86+
% [dxx,dxy]=gradient(dx);
87+
% [dyx,dyy]=gradient(dy);
88+
% K=(dxx.*dy.^2-2*dx.*dy.*dxy+dyy.*dx.^2)./(grad_norm).^3; % another way to define div(grad/|grad|)
89+
K=divergence(dx./grad_norm,dy./grad_norm); %this one is a bit faster
90+
91+
speed = Delta_eps(phi).*(miu*K-v-Lambda_1*(img-c_1).^2+Lambda_2*(img-c_2).^2);
92+
speed =speed/ sqrt(sum(sum(speed.^2)));%norm by square root of sum of square elements
93+
94+
phi=phi+delta_t*speed;
95+
96+
%% Presenting relevant graphs
97+
if (~mod(n,FigRefresRate)) % it's time to draw current image
98+
99+
pause(0.001);
100+
101+
if (SegDispaly)
102+
if (EnergyDispaly) % two axis on display
103+
subplot(no_of_plots,1,1,'Units','Normalized',...
104+
'Parent',uipael_handle);
105+
end
106+
% imshow(uint8(repmat(img,[1,1,3])));hold on;
107+
strechedImg=img-min(img(:)); % now values are between 0:Max
108+
strechedImg=255*strechedImg/max(strechedImg(:)); % now values between 0:255
109+
imshow(repmat(uint8(strechedImg),[1,1,3]),[]); hold on;
110+
contour(sign(phi),[0 0],'g','LineWidth',2);
111+
iterNum=['Segmentation with: Active Contours wihtout Edges, ',num2str(n),' iterations'];
112+
title(iterNum,'FontSize',14);
113+
axis off;axis equal;hold off;
114+
end
115+
116+
if (EnergyDispaly)
117+
if (SegDispaly) % two axis on display
118+
subplot(no_of_plots,1,2,'Units','Normalized',...
119+
'Parent',uipael_handle)
120+
end
121+
122+
switch(EnergyImageType)
123+
case(1) %surf(phi)
124+
surf(phi);
125+
case(2) %mesh(phi)
126+
mesh(phi);
127+
case(3) %imagesc(phi)
128+
imagesc(phi);
129+
axis equal;
130+
axis off;
131+
case(4) %surf(sign|phi|)
132+
surf(sign(phi));
133+
case(5) %mesh(sign|phi|)
134+
mesh(sign(phi));
135+
case(6) %imagesc(sign|phi|);
136+
imagesc(sign(phi));
137+
axis equal;axis off;
138+
end
139+
140+
colormap('Jet');
141+
title(['\phi_{',num2str(n),'}'],'FontSize',18);
142+
end
143+
144+
if (SegDispaly)&&(EnergyDispaly)
145+
text_pos=[0.5,1.35];
146+
else
147+
text_pos=[0.5,-0.02];
148+
end
149+
text(text_pos(1),text_pos(2),{'Applied to file:',file_str4text{:}},...
150+
'HorizontalAlignment','center','Units','Normalized',...
151+
'FontUnits','Normalized');
152+
drawnow;
153+
154+
%% it's time to save current image
155+
if (~mod(n,SaveRefresRate))
156+
tmp=zeros(size(img,1),size(img,2));
157+
tmp(phi>0)=255;
158+
temp_img=repmat(img(:,:,1),[1 1 3]);
159+
temp_img(:,:,2)=temp_img(:,:,2)+tmp;
160+
imwrite(uint8(temp_img),[out_dir,filesep,in_file_name,'Segment_n_',num2str(n),'.jpg'],'jpg');
161+
max_phi=max(max(phi));min_phi=min(min(phi));
162+
tmp=phi; tmp=255*(tmp-min_phi)/(max_phi-min_phi);
163+
imwrite(uint8(tmp),[out_dir,filesep,in_file_name,'Phi_n_',num2str(n),'.jpg'],'jpg');
164+
% saveas(gca,[out_dir,filesep,num2str(n)],'fig') ;%save figure
165+
end % if (~mod(n,SaveRefresRate))
166+
end % if (~mod(n,FigRefresRate))
167+
end % for n=1:N % main loop
168+
169+
170+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171+
% Servise sub function %
172+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173+
function out=Delta_eps(z,epsilon)
174+
if nargin==1
175+
epsilon=1;
176+
end
177+
out=epsilon/pi./(epsilon^2+z.^2);
178+
% out=(1/(2*epsilon))*(1+cos(pi*z/epsilon)).*(abs(z)<=epsilon);
Binary file not shown.

0 commit comments

Comments
 (0)