📄 gaussian.m
字号:
% This code implements the Gausian Search Algorithm for detect the best
% thershold in image segmentation. v is the size of the window, and p is
% the thershold that the algorithm serchs. COUNTS is the COUNTS variable
% that is returnen by the imhist() funcition. The umbral is the Thershold
% needed for segmenting an image using the Gausian Search Algorithm.
% To use this Function you must gurantee thar there are only tow global maximum
% values in COUNTS, and that those correspond with the maximums of the both
% lobules of the histogram.
%Typical application:
% I=imread('blood1','tiff');
% [COUNTS,x]=imhist(I);
% umbral=suavgausiana(COUNTS,3,5);
%Guasian Search function with a window of size 3, and a throshold of rise of 5.
%To run this function you wont need the Image Processing Toolbox, but
%you'll need it when you want to read the image and try to get its
%histogram.
lc=length(COUNTS); % lc is the length of the COUNTS Vector
COUNTSINT=COUNTS; % Creates a copy of the COUNTS vector
max1=max(COUNTSINT) % Looks for one maximun of the COUNTSINT vector
posmax1=find(COUNTSINT==max1); %Looks for the position of the maximum
% In the next if statement what I try to do is delete all the local
% maximums that are near to max1, and avoid the posibility to considere
% max2 like one of these maximums near to max1
if ((posmax1>40)&(posmax1<=(lc-41)))
COUNTSINT(posmax1-40:posmax1+40)=0; % Erase the maximum from the COUNTSINT vector
elseif (posmax1<40)
COUNTSINT(1:posmax1+40)=0; % Erase the maximum from the COUNTSINT vector
elseif (posmax1>lc-41)
COUNTSINT(posmax1:lc-1)=0; % Erase the maximum from the COUNTSINT vector
end
figure;
stem(COUNTSINT);
title('COUNTSINT');
% Onece deleted one maximum, we procede to search the other maximum
max2=max(COUNTSINT) % Looks for one maximum
posmax2=find(COUNTSINT==max2); % Looks for the position of that maximum
% After findinf the 2 maximums, we procede to establish wich one is grater
% thatn the other one, that is, which one is in the left an which one is
% the righ. This is done because we have to begin this algorith from the
% left side to right side.
if (posmax2>posmax1)
maxini=posmax1;
if (posmax2<=lc-1-v)
maxfinal=posmax2;
else
maxfinal=lc-1-v;
end
else
maxini=posmax2;
if (posmax1<=lc-1-v)
maxfinal=posmax1;
else
maxfinal=lc-1-v;
end
end
% Now we start looking for le thershold using the Gausian Search Algorithm
% with a window V, and a thershold p
for i=maxini:maxfinal;
a(i)=COUNTS(i+v)-COUNTS(i);
if (a(i)>p)
umbral=ceil(i+((v+1)/2));
break;
else
umbral=0;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -