[Proyecto] Segmentación y recuento de células basados en el algoritmo de cuencas hidrográficas de la GUI de matlab [Contiene el código fuente 637 de Matlab]

1. Introducción

El algoritmo de cuenca hidrográfica es un método de segmentación de la región de la imagen. Durante el proceso de segmentación, la imagen se convierte en una imagen en escala de grises. Luego, consideraré el valor de la escala de grises como la altitud y luego inyectaré agua en el punto inferior. Esta interpretación basada en la topografía, Se consideran enfáticamente tres puntos: el
Inserte la descripción de la imagen aquí
punto mínimo, que corresponde al punto más bajo de una cuenca, cuando dejamos caer una gota de agua en la cuenca, el agua eventualmente convergerá a este punto debido a la gravedad. Nota: Puede haber una superficie mínima y todos los puntos de este plano son puntos mínimos.
En otras ubicaciones de la cuenca, las gotas de esa ubicación convergerán al mínimo local.
El punto de borde de la cuenca es la unión de la cuenca y otras cuencas, una gota de agua en este punto fluirá a cualquier cuenca con igual probabilidad.
Inserte la descripción de la imagen aquí
Después de comprender los tres puntos anteriores, comenzamos a inyectar agua en los puntos mínimos de la cuenca, y luego, a medida que la inyección de agua se profundiza, cada punto mínimo se expande lentamente hacia afuera, y luego sabemos que el agua en las dos cuencas converge y el la confluencia es la línea divisoria de aguas que necesitamos.

Se puede entender intuitivamente a partir de la figura a continuación. Primero, estas tres áreas contienen puntos mínimos,
Inserte la descripción de la imagen aquí
y luego rellénelos gradualmente para obtener la cuenca (es decir, la línea divisoria) para
Inserte la descripción de la imagen aquí
obtener la línea divisoria para completar la segmentación de la imagen:
Inserte la descripción de la imagen aquí

En segundo lugar, el código fuente

function varargout = CellCount(varargin)
% CELLCOUNT M-file for CellCount.fig
%      CELLCOUNT, by itself, creates a new CELLCOUNT or raises the existing
%      singleton*.
%
%      H = CELLCOUNT returns the handl e to a new CELLCOUNT or the handle to
%      the existing singleton*.
%
%      CELLCOUNT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CELLCOUNT.M with the given input arguments.
%
%      CELLCOUNT('Property','Value',...) creates a new CELLCOUNT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before CellCount_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to CellCount_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help CellCount

% Last Modified by GUIDE v2.5 01-May-2015 19:43:57

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @CellCount_OpeningFcn, ...
                   'gui_OutputFcn',  @CellCount_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{
    
    1})
    gui_State.gui_Callback = str2func(varargin{
    
    1});
end

if nargout
    [varargout{
    
    1:nargout}] = gui_mainfcn(gui_State, varargin{
    
    :});
else
    gui_mainfcn(gui_State, varargin{
    
    :});
end
% End initialization code - DO NOT EDIT


% --- Executes just before CellCount is made visible.
function CellCount_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to CellCount (see VARARGIN)

% Choose default command line output for CellCount
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes CellCount wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = CellCount_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{
    
    1} = handles.output;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject    handle to file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function open_Callback(hObject, eventdata, handles)
% hObject    handle to open (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global im;
[filename,pathname]=uigetfile({
    
    '*.jpg';'*bmp';'*.gif'},'选择图片');
%合成图片路径+文件名
str=[pathname filename];
%读取图片
im=imread(str);
%使用第一个axes
axes(handles.axes0);
imshow(im);


% --------------------------------------------------------------------
function save_Callback(hObject, eventdata, handles)
% hObject    handle to save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(gcf) %关闭当前figure句柄

% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global im
global I
global C
%%%%%%%%%%%%%%%%%%
I=im;
R=I(:,:,1);
G=I(:,:,2); 
B=I(:,:,3); 
K=rgb2hsv(I);           
H=K(:,:,1); 
S=K(:,:,2); 
V=K(:,:,3); 
[cenwhite,copywhite]=Kmeans(H,3);           
cenwhite;                       
A=copywhite; 
[m,n]=size(A);          
for i=1:m 
    for j=1:n 
        if A(i,j)==cenwhite(2) 
           A(i,j)=1; 
        else A(i,j)=0; 
        end 
    end 

Tres, resultados en ejecución

Inserte la descripción de la imagen aquí

Cuatro, comentarios

Complete el código o escriba en nombre de agregar QQ 1564658423

Supongo que te gusta

Origin blog.csdn.net/TIQCmatlab/article/details/115267339
Recomendado
Clasificación